generated from Sithas/conan_template
89 lines
2.6 KiB
C++
89 lines
2.6 KiB
C++
#ifdef WIN32
|
|
#include <sdkddkver.h>
|
|
#include <WinSock2.h>
|
|
#endif
|
|
|
|
#define BOOST_TEST_MODULE AuthLoginExecutors
|
|
|
|
#include <boost/test/included/unit_test.hpp>
|
|
|
|
#include <string>
|
|
|
|
#include "./../../src/endpoints_handlers/AuthLogoutExecutor.h"
|
|
|
|
#include "../../src/DAO/MemoryAuthDAO.h"
|
|
#include "./../../src/DAO/MySQLUserDAO.h"
|
|
#include "./../../src/db/mysql_connector.h"
|
|
#include "./../../src/exceptions/session_exception.h"
|
|
#include "./../../src/helpers/helpers.h"
|
|
#include "../fixtures/AuthFixture.h"
|
|
|
|
using namespace std;
|
|
using namespace uad;
|
|
using namespace boost;
|
|
using namespace beast;
|
|
using namespace json;
|
|
|
|
using RouteAuthLogoutExecutor = AuthLogoutExecutor<beast::http::string_body,
|
|
std::allocator<char>,
|
|
beast::http::string_body>;
|
|
using Request = boost::beast::http::request<beast::http::string_body,
|
|
beast::http::basic_fields<std::allocator<char>>>;
|
|
|
|
BOOST_FIXTURE_TEST_CASE(AuthRegistrationExecutor_Cant_Find_User_Token, AuthFixture)
|
|
{
|
|
RouteAuthLogoutExecutor executor(GetMySqlSession(), auth_dao);
|
|
|
|
value req_body;
|
|
|
|
req_body.emplace_object();
|
|
req_body.as_object().emplace("token", "1234567890");
|
|
|
|
req.body() = "{ \"token\": abcde }";
|
|
req.content_length(req.body().size());
|
|
|
|
BOOST_CHECK_EXCEPTION(executor(std::move(req)), session_exception,
|
|
[](const session_exception& e) -> bool
|
|
{
|
|
return e.code == beast::http::status::bad_request;
|
|
});
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(AuthRegistrationExecutor_Cant_Revoke_Token, AuthFixture)
|
|
{
|
|
RouteAuthLogoutExecutor executor(GetMySqlSession(), auth_dao);
|
|
|
|
value req_body;
|
|
|
|
req_body.emplace_object();
|
|
req_body.as_object().emplace("token", "1234567890");
|
|
|
|
req.body() = "{ \"token\": \"1234567890\" }";
|
|
req.content_length(req.body().size());
|
|
|
|
BOOST_CHECK_EXCEPTION(executor(std::move(req)), session_exception,
|
|
[](const session_exception& e) -> bool
|
|
{
|
|
return e.code == beast::http::status::bad_request;
|
|
});
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(AuthRegistrationExecutor_Succesful_Auth, AuthFixture)
|
|
{
|
|
RouteAuthLogoutExecutor executor(GetMySqlSession(), auth_dao);
|
|
|
|
value req_body;
|
|
|
|
auth_dao->Login("SomethingUser", "1234567890");
|
|
|
|
req_body.emplace_object();
|
|
req_body.as_object().emplace("token", "1234567890");
|
|
|
|
req.body() = "{ \"token\": \"1234567890\" }";
|
|
req.content_length(req.body().size());
|
|
|
|
auto response = executor(std::move(req));
|
|
|
|
BOOST_CHECK(response.result() == http::status::ok);
|
|
}
|