24 行
622 B
C++
24 行
622 B
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "csp/db/sqlite_db.h"
|
|
#include "csp/services/auth_service.h"
|
|
|
|
TEST_CASE("auth register/login/verify") {
|
|
auto db = csp::db::SqliteDb::OpenMemory();
|
|
csp::db::ApplyMigrations(db);
|
|
|
|
csp::services::AuthService auth(db);
|
|
|
|
const auto r = auth.Register("alice", "password123");
|
|
REQUIRE(r.user_id > 0);
|
|
REQUIRE(r.token.size() > 10);
|
|
|
|
const auto uid = auth.VerifyToken(r.token);
|
|
REQUIRE(uid.has_value());
|
|
REQUIRE(uid.value() == r.user_id);
|
|
|
|
const auto r2 = auth.Login("alice", "password123");
|
|
REQUIRE(r2.user_id == r.user_id);
|
|
REQUIRE(r2.token != r.token);
|
|
}
|