1 Commits

Author SHA1 Message Date
Антон e48d3f30cb Подготовка интеграционного теста 2025-10-07 06:35:25 +03:00
6 changed files with 37 additions and 7 deletions
@@ -5,6 +5,8 @@
#include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h>
#include <boost/uuid.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "IExecutor.h"
#include "../DAO/IUserDAO.h"
@@ -38,6 +40,8 @@ public:
using namespace boost::beast;
using namespace std::string_literals;
// BOOST_LOG_TRIVIAL(info) << "Auth/Login - Request";
const auto body = req.body();
value req_json;
@@ -47,6 +51,7 @@ public:
}
catch (const system::system_error& err)
{
// BOOST_LOG_TRIVIAL(error) << "Auth/Login - Error 400";
throw session_exception(http::status::bad_request, "cannot deserialize json");
}
@@ -56,6 +61,7 @@ public:
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);
}
@@ -63,6 +69,7 @@ public:
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");
}
const std::string token = GenerateUUID();
@@ -78,6 +85,8 @@ public:
res.set(http::field::content_type, "application/json");
res.content_length(res.body().size());
// BOOST_LOG_TRIVIAL(info) << "Auth/Login - Success - 200";
return res;
}
};
@@ -5,6 +5,8 @@
#include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h>
#include <boost/uuid.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "IExecutor.h"
#include "../DAO/IUserDAO.h"
@@ -35,6 +37,8 @@ public:
using namespace boost::beast;
using namespace std::string_literals;
// BOOST_LOG_TRIVIAL(info) << "Auth/Logout - Request";
const auto body = req.body();
value req_json;
@@ -44,6 +48,7 @@ public:
}
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);
}
@@ -51,6 +56,7 @@ public:
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);
}
@@ -60,6 +66,8 @@ public:
res.set(http::field::content_type, "application/json");
res.content_length(res.body().size());
// BOOST_LOG_TRIVIAL(info) << "Auth/Login - Success 200";
return res;
}
};
@@ -3,6 +3,8 @@
#include <regex>
#include <boost/json.hpp>
#include <mysqlx/xdevapi.h>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "IExecutor.h"
#include "../DAO/IUserDAO.h"
@@ -32,6 +34,8 @@ public:
using namespace boost::beast;
using namespace std::string_literals;
// BOOST_LOG_TRIVIAL(info) << "Auth/Registration - Request";
const auto& body = req.body();
value req_json;
@@ -41,6 +45,7 @@ public:
}
catch (const system::system_error& err)
{
// BOOST_LOG_TRIVIAL(error) << "Auth/Logout - Error 400";
throw session_exception(http::status::bad_request, "cannot deserialize json");
}
@@ -49,6 +54,7 @@ public:
if (!ValidateLogin(login) || !ValidatePassword(password))
{
// BOOST_LOG_TRIVIAL(error) << "Auth/Logout - Error 422";
throw session_exception(
http::status::unprocessable_entity,
"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())
{
// BOOST_LOG_TRIVIAL(error) << "Auth/Logout - Error 409";
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.content_length(res.body().size());
// BOOST_LOG_TRIVIAL(info) << "Auth/Logout - Created 201";
return res;
}
+4 -4
View File
@@ -11,11 +11,11 @@ namespace uad
void InitLogs()
{
logging::add_file_log(
logging::keywords::file_name = "app_%Y-%m-%d_%H-%M-%S.log",
logging::keywords::rotation_size = 10 * 1024 * 1024,
logging::keywords::file_name = "app_%Y-%m-%d_%H-%M-%S.log", // Имя файла с timestamp
logging::keywords::rotation_size = 10 * 1024 * 1024, // Ротация при достижении 10 МБ
logging::keywords::time_based_rotation =
logging::sinks::file::rotation_at_time_point(0, 0, 0),
logging::keywords::format = "[%TimeStamp%] [%Severity%]: %Message%"
logging::sinks::file::rotation_at_time_point(0, 0, 0), // Ротация каждый день в полночь
logging::keywords::format = "[%TimeStamp%] [%Severity%]: %Message%" // Формат записи
);
}
}
+4 -3
View File
@@ -1,10 +1,8 @@
#ifdef WIN32
#define _WIN32_WINNT 0x0602
#include <sdkddkver.h>
#endif
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <algorithm>
#include <boost/asio/signal_set.hpp>
#include <boost/beast/core.hpp>
@@ -17,6 +15,9 @@
#include <string>
#include <thread>
#include <vector>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "./session/WebsocketSession.h"
#include "./listener/Listener.h"
+3
View File
@@ -3,6 +3,9 @@
#include <memory>
#include <boost/beast.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
{