105 route tests, matrix crawl, spec and README updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
22 lines
1.3 KiB
C++
22 lines
1.3 KiB
C++
// Route: /security/login (HTML login form, session cookie)
|
|
#include "support/Assert.hpp"
|
|
using namespace molo::example::test;
|
|
static const char* kForm = "application/x-www-form-urlencoded";
|
|
int main() {
|
|
Fixture f;
|
|
check(contains(f.client->get("/security/login").body, "type=\"password\""), "form renders");
|
|
check(f.client->get("/security/whoami").status == 401, "anonymous whoami 401");
|
|
auto bad = f.client->post("/security/login", "username=ada&password=nope", kForm);
|
|
check(bad.status == 401 && contains(bad.body, "wrong username or password"), "bad creds inline 401");
|
|
check(!contains(bad.body, "\"error\""), "no raw json");
|
|
auto empty = f.client->post("/security/login", "username=&password=", kForm);
|
|
check(empty.status == 422 && contains(empty.body, "form-errors"), "empty inline 422");
|
|
auto ok = f.client->post("/security/login", "username=ada&password=correct-horse", kForm);
|
|
check(ok.status == 200 && contains(ok.body, "Signed in as ada"), "login ok");
|
|
check(contains(ok.headers.get("Set-Cookie"), "login_sid="), "session cookie set");
|
|
auto who = f.client->get("/security/whoami");
|
|
check(who.status == 200 && contains(who.body, "\"user\":\"ada\""), "whoami via cookie");
|
|
check(f.services.sessions->size() >= 1, "side effect: session stored");
|
|
return finish("security/login");
|
|
}
|