1 Commits

Author SHA1 Message Date
Антон e48d3f30cb Подготовка интеграционного теста 2025-10-07 06:35:25 +03:00
5 changed files with 31 additions and 1 deletions
@@ -5,6 +5,8 @@
#include <mysqlx/xdevapi.h> #include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h> #include <mysqlx/common/api.h>
#include <boost/uuid.hpp> #include <boost/uuid.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "IExecutor.h" #include "IExecutor.h"
#include "../DAO/IUserDAO.h" #include "../DAO/IUserDAO.h"
@@ -38,6 +40,8 @@ public:
using namespace boost::beast; using namespace boost::beast;
using namespace std::string_literals; using namespace std::string_literals;
// BOOST_LOG_TRIVIAL(info) << "Auth/Login - Request";
const auto body = req.body(); const auto body = req.body();
value req_json; value req_json;
@@ -47,6 +51,7 @@ public:
} }
catch (const system::system_error& err) catch (const system::system_error& err)
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Login - Error 400";
throw session_exception(http::status::bad_request, "cannot deserialize json"); throw session_exception(http::status::bad_request, "cannot deserialize json");
} }
@@ -56,6 +61,7 @@ public:
if (login.empty() || password.empty()) if (login.empty() || password.empty())
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Login - Error 422";
throw session_exception(http::status::unprocessable_entity, "Login or password are empty"s); throw session_exception(http::status::unprocessable_entity, "Login or password are empty"s);
} }
@@ -63,6 +69,7 @@ public:
if (!maybe_user.has_value() && maybe_user.value().hashed_password != HashPassword(password)) if (!maybe_user.has_value() && maybe_user.value().hashed_password != HashPassword(password))
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Login - Error 403";
throw session_exception(http::status::forbidden,"Incorrect login or password"); throw session_exception(http::status::forbidden,"Incorrect login or password");
} }
const std::string token = GenerateUUID(); const std::string token = GenerateUUID();
@@ -78,6 +85,8 @@ public:
res.set(http::field::content_type, "application/json"); res.set(http::field::content_type, "application/json");
res.content_length(res.body().size()); res.content_length(res.body().size());
// BOOST_LOG_TRIVIAL(info) << "Auth/Login - Success - 200";
return res; return res;
} }
}; };
@@ -5,6 +5,8 @@
#include <mysqlx/xdevapi.h> #include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h> #include <mysqlx/common/api.h>
#include <boost/uuid.hpp> #include <boost/uuid.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "IExecutor.h" #include "IExecutor.h"
#include "../DAO/IUserDAO.h" #include "../DAO/IUserDAO.h"
@@ -35,6 +37,8 @@ public:
using namespace boost::beast; using namespace boost::beast;
using namespace std::string_literals; using namespace std::string_literals;
// BOOST_LOG_TRIVIAL(info) << "Auth/Logout - Request";
const auto body = req.body(); const auto body = req.body();
value req_json; value req_json;
@@ -44,6 +48,7 @@ public:
} }
catch (const system::system_error& err) catch (const system::system_error& err)
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Login - Error 500";
throw session_exception(http::status::internal_server_error, "cannot deserialize json"s); throw session_exception(http::status::internal_server_error, "cannot deserialize json"s);
} }
@@ -51,6 +56,7 @@ public:
if (!auth_dao_->Logout(token)) if (!auth_dao_->Logout(token))
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Login - Error 400";
throw session_exception(http::status::bad_request, "token is not authorized"s); throw session_exception(http::status::bad_request, "token is not authorized"s);
} }
@@ -60,6 +66,8 @@ public:
res.set(http::field::content_type, "application/json"); res.set(http::field::content_type, "application/json");
res.content_length(res.body().size()); res.content_length(res.body().size());
// BOOST_LOG_TRIVIAL(info) << "Auth/Login - Success 200";
return res; return res;
} }
}; };
@@ -3,6 +3,8 @@
#include <regex> #include <regex>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <mysqlx/xdevapi.h> #include <mysqlx/xdevapi.h>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "IExecutor.h" #include "IExecutor.h"
#include "../DAO/IUserDAO.h" #include "../DAO/IUserDAO.h"
@@ -32,6 +34,8 @@ public:
using namespace boost::beast; using namespace boost::beast;
using namespace std::string_literals; using namespace std::string_literals;
// BOOST_LOG_TRIVIAL(info) << "Auth/Registration - Request";
const auto& body = req.body(); const auto& body = req.body();
value req_json; value req_json;
@@ -41,6 +45,7 @@ public:
} }
catch (const system::system_error& err) catch (const system::system_error& err)
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Logout - Error 400";
throw session_exception(http::status::bad_request, "cannot deserialize json"); throw session_exception(http::status::bad_request, "cannot deserialize json");
} }
@@ -49,6 +54,7 @@ public:
if (!ValidateLogin(login) || !ValidatePassword(password)) if (!ValidateLogin(login) || !ValidatePassword(password))
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Logout - Error 422";
throw session_exception( throw session_exception(
http::status::unprocessable_entity, http::status::unprocessable_entity,
"Validations failed. Login should have length from 3 to 50. Password from 5 characters length."s "Validations failed. Login should have length from 3 to 50. Password from 5 characters length."s
@@ -57,6 +63,7 @@ public:
if (user_dao_->GetByLogin(login).has_value()) if (user_dao_->GetByLogin(login).has_value())
{ {
// BOOST_LOG_TRIVIAL(error) << "Auth/Logout - Error 409";
throw session_exception(http::status::conflict, "user with login "s + login + " exists"s); throw session_exception(http::status::conflict, "user with login "s + login + " exists"s);
} }
@@ -87,6 +94,8 @@ public:
res.set(http::field::content_type, "application/json"); res.set(http::field::content_type, "application/json");
res.content_length(res.body().size()); res.content_length(res.body().size());
// BOOST_LOG_TRIVIAL(info) << "Auth/Logout - Created 201";
return res; return res;
} }
+2 -1
View File
@@ -1,4 +1,5 @@
#ifdef WIN32 #ifdef WIN32
#define _WIN32_WINNT 0x0602
#include <sdkddkver.h> #include <sdkddkver.h>
#endif #endif
@@ -63,7 +64,7 @@ int main(int argc, char* argv[])
net::signal_set signals(ioc, SIGINT, SIGTERM); net::signal_set signals(ioc, SIGINT, SIGTERM);
signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); }); signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); });
BOOST_LOG_TRIVIAL(error) << "Приложение запущено"; BOOST_LOG_TRIVIAL(info) << "Приложение запущено";
std::vector<std::thread> v; std::vector<std::thread> v;
v.reserve(threads - 1); v.reserve(threads - 1);
+3
View File
@@ -3,6 +3,9 @@
#include <memory> #include <memory>
#include <boost/beast.hpp> #include <boost/beast.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
namespace uad namespace uad
{ {