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,24 @@
|
||||
// Route: GET /csp/page (per-request nonce in header and script tag)
|
||||
#include "support/Assert.hpp"
|
||||
using namespace molo::example::test;
|
||||
static std::string nonce_of(const std::string& h) {
|
||||
std::size_t a = h.find("'nonce-");
|
||||
if (a == std::string::npos) return "";
|
||||
a += 7;
|
||||
return h.substr(a, h.find('\'', a) - a);
|
||||
}
|
||||
int main() {
|
||||
Fixture f;
|
||||
auto a = f.client->get("/csp/page");
|
||||
auto b = f.client->get("/csp/page");
|
||||
check(a.status == 200 && contains(a.content_type(), "text/html"), "html 200");
|
||||
std::string h = a.headers.get("Content-Security-Policy-Report-Only");
|
||||
check(contains(h, "default-src 'none'"), "deny-first default");
|
||||
check(contains(h, "report-uri /csp/report"), "report uri set");
|
||||
std::string n = nonce_of(h);
|
||||
check(n.size() == 32, "nonce is 16 random bytes in hex");
|
||||
check(contains(a.body, "<script nonce=\"" + n + "\">"), "script carries same nonce");
|
||||
check(n != nonce_of(b.headers.get("Content-Security-Policy-Report-Only")), "nonce differs per request");
|
||||
check(f.client->post("/csp/page", "x").status == 405, "POST is 405");
|
||||
return finish("csp/page");
|
||||
}
|
||||
Reference in New Issue
Block a user