feat(auth): add session-based auth service with tests
这个提交包含在:
@@ -0,0 +1,23 @@
|
||||
#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);
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户