Подготовка интеграционного теста

This commit is contained in:
Антон
2025-10-17 08:51:16 +03:00
parent 38a8d5effd
commit d0ad4ae189
3 changed files with 18 additions and 4 deletions
+4 -1
View File
@@ -50,7 +50,8 @@ public:
}
catch (const system::system_error& err)
{
throw session_exception(http::status::bad_request, "cannot deserialize json");
BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Login - Response 500: Cannot deserialize json";
throw session_exception(http::status::internal_server_error, "Cannot deserialize json");
}
@@ -59,6 +60,7 @@ public:
if (login.empty() || password.empty())
{
BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Login - Response 422: Login or password are empty";
throw session_exception(http::status::unprocessable_entity, "Login or password are empty"s);
}
@@ -66,6 +68,7 @@ public:
if (!maybe_user.has_value() && maybe_user.value().hashed_password != HashPassword(password))
{
BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Login - Response 403: Incorrect login or password";
throw session_exception(http::status::forbidden,"Incorrect login or password");
}
const std::string token = GenerateUUID();
+6 -1
View File
@@ -1,4 +1,5 @@
#pragma once
#include <boost/log/trivial.hpp>
#include <regex>
#include <boost/json.hpp>
@@ -35,6 +36,8 @@ public:
using namespace boost::beast;
using namespace std::string_literals;
BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Logout - Request";
const auto body = req.body();
value req_json;
@@ -44,6 +47,7 @@ public:
}
catch (const system::system_error& err)
{
BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Logout - Response 500: Cannot deserialize json";
throw session_exception(http::status::internal_server_error, "cannot deserialize json"s);
}
@@ -51,7 +55,8 @@ public:
if (!auth_dao_->Logout(token))
{
throw session_exception(http::status::bad_request, "token is not authorized"s);
BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Logout - Response 400: Token is not authorized";
throw session_exception(http::status::bad_request, "Token is not authorized"s);
}
http::response<ResponseType> res{http::status::ok, req.version()};
@@ -1,4 +1,5 @@
#pragma once
#include <boost/log/trivial.hpp>
#include <regex>
#include <boost/json.hpp>
@@ -32,6 +33,8 @@ public:
using namespace boost::beast;
using namespace std::string_literals;
BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Registration - Request";
const auto& body = req.body();
value req_json;
@@ -41,7 +44,8 @@ public:
}
catch (const system::system_error& err)
{
throw session_exception(http::status::bad_request, "cannot deserialize json");
BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Registration - Response 500: Cannot deserialize json";
throw session_exception(http::status::internal_server_error, "Cannot deserialize json");
}
const std::string login = req_json.as_object().at("login").as_string().c_str();
@@ -49,6 +53,7 @@ public:
if (!ValidateLogin(login) || !ValidatePassword(password))
{
BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Registration - Response 422: Validations failed. Login should have length from 3 to 50. Password from 5 characters length.";
throw session_exception(
http::status::unprocessable_entity,
"Validations failed. Login should have length from 3 to 50. Password from 5 characters length."s
@@ -57,7 +62,8 @@ public:
if (user_dao_->GetByLogin(login).has_value())
{
throw session_exception(http::status::conflict, "user with login "s + login + " exists"s);
BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Registration - Response 409: "s + "User with login "s + login + " exists"s;
throw session_exception(http::status::conflict, "User with login "s + login + " exists"s);
}
user user;