feat(workflow): example covers security, platform, enterprise and resilience features
105 route tests, matrix crawl, spec and README updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Route: /security/csrf (signed token, inline 403 on bad token)
|
||||
#include "support/Assert.hpp"
|
||||
using namespace molo::example::test;
|
||||
static const char* kForm = "application/x-www-form-urlencoded";
|
||||
int main() {
|
||||
Fixture f;
|
||||
auto page = f.client->get("/security/csrf");
|
||||
check(page.status == 200 && contains(page.body, "<form"), "form renders");
|
||||
std::size_t at = page.body.find("value=\"");
|
||||
at = page.body.find("name=\"csrf_token\" value=\"");
|
||||
check(at != std::string::npos, "token field prefilled");
|
||||
at += std::string("name=\"csrf_token\" value=\"").size();
|
||||
std::string token = page.body.substr(at, page.body.find('"', at) - at);
|
||||
auto ok = f.client->post("/security/csrf", "csrf_token=" + token + "¬e=hi", kForm);
|
||||
check(ok.status == 200 && contains(ok.body, "Saved: hi"), "valid token accepted");
|
||||
auto missing = f.client->post("/security/csrf", "note=hi", kForm);
|
||||
check(missing.status == 403, "missing token is 403");
|
||||
check(contains(missing.body, "form-errors") && contains(missing.body, "invalid CSRF token"), "inline html error");
|
||||
check(!contains(missing.body, "\"error\""), "no raw json");
|
||||
auto bad = f.client->post("/security/csrf", "csrf_token=abc.def¬e=hi", kForm);
|
||||
check(bad.status == 403, "forged token is 403");
|
||||
auto longnote = f.client->post("/security/csrf", "csrf_token=" + token + "¬e=" + std::string(81, 'x'), kForm);
|
||||
check(longnote.status == 422, "note over 80 chars is 422");
|
||||
auto api = f.client->request(molo::example::fw::Method::Post, "/security/csrf", "note=hi",
|
||||
{{"Content-Type", kForm}, {"Accept", "application/json"}});
|
||||
check(api.status == 403 && contains(api.body, "CsrfGuard"), "json client gets json");
|
||||
auto denials = f.client->get("/security/denials");
|
||||
check(contains(denials.body, "CsrfGuard"), "side effect: denial recorded");
|
||||
return finish("security/csrf");
|
||||
}
|
||||
Reference in New Issue
Block a user