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:
2026-10-24 02:19:52 +02:00
co-authored by Claude Sonnet 5.5
parent 00af65613d
commit 62fdd08da8
90 changed files with 8038 additions and 11 deletions
+21
View File
@@ -0,0 +1,21 @@
// Route: GET/POST /audit/log (hash-chained log page and append form)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto page = f.client->get("/audit/log");
check(page.status == 200 && contains(page.headers.get("Content-Type"), "text/html"), "html page");
check(contains(page.body, "Chain intact"), "intact");
auto js = f.client->request(Method::Get, "/audit/log", "", {{"Accept", "application/json"}});
check(contains(js.body, "\"records\""), "json variant");
auto bad = f.client->post("/audit/log", "actor=&action=x&subject=y", "application/x-www-form-urlencoded");
check(bad.status == 422 && contains(bad.body, "field-error"), "inline validation");
auto ok = f.client->post("/audit/log", "actor=ada&action=edit&subject=doc&detail=mail+me%40example.com", "application/x-www-form-urlencoded");
check(ok.status == 201 && contains(ok.body, "appended"), "appended");
auto after = f.client->request(Method::Get, "/audit/log", "", {{"Accept", "application/json"}});
check(contains(after.body, "[EMAIL]") && !contains(after.body, "me@example.com"), "side effect: PII redacted in record");
return finish("audit/log");
}
+18
View File
@@ -0,0 +1,18 @@
// Route: GET /audit/mask (masking and redaction patterns)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto d = f.client->get("/audit/mask");
check(d.status == 200 && contains(d.body, "a***********@example.com"), "email masked");
check(contains(d.body, "************1111"), "card keeps last 4");
check(contains(d.body, "[EMAIL]") && contains(d.body, "[SSN]") && contains(d.body, "[IP]"), "redactions");
check(contains(d.body, "\"redactions\":4"), "counted 4 hits");
auto c = f.client->get("/audit/mask?text=nothing+here");
check(contains(c.body, "\"redactions\":0"), "clean text unchanged");
check(f.client->post("/audit/mask").status == 405, "405");
return finish("audit/mask");
}
+23
View File
@@ -0,0 +1,23 @@
// Route: GET /audit/retention + hold + purge (policy, legal hold, dry run)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto page = f.client->get("/audit/retention");
check(page.status == 200 && contains(page.body, "expired"), "html page");
auto js = f.client->request(Method::Get, "/audit/retention", "", {{"Accept", "application/json"}});
check(contains(js.body, "\"r1\"") && contains(js.body, "\"r5\""), "expired listed");
auto dry = f.client->post("/audit/retention/purge", "");
check(contains(dry.body, "\"dry_run\":true") && contains(dry.body, "\"purged\":0"), "dry run by default");
check(f.client->post("/audit/retention/hold", "id=r1&hold=true").status == 200, "hold");
auto real = f.client->post("/audit/retention/purge", "confirm=yes");
check(contains(real.body, "\"purged\":2"), "held entry skipped, two purged");
auto after = f.client->request(Method::Get, "/audit/retention", "", {{"Accept", "application/json"}});
check(contains(after.body, "\"r1\"") && !contains(after.body, "\"id\":\"r5\""), "side effect: r1 kept, r5 gone");
check(f.client->post("/audit/retention/hold", "id=r1&hold=x").status == 422, "bad hold");
check(f.client->post("/audit/retention/hold", "id=zz&hold=true").status == 404, "unknown id");
return finish("audit/retention");
}
+21
View File
@@ -0,0 +1,21 @@
// Route: GET /audit/subject, export, POST erase (data subject rights)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto page = f.client->get("/audit/subject");
check(page.status == 200 && contains(page.headers.get("Content-Type"), "text/html"), "form page");
auto ex = f.client->get("/audit/subject/export?subject=ada@example.com");
check(ex.status == 200 && contains(ex.body, "order=1001") && contains(ex.body, "profiles"), "export across tables");
check(f.client->get("/audit/subject/export").status == 400, "missing subject");
auto bad = f.client->post("/audit/subject/erase", "subject=nope&confirm=no", "application/x-www-form-urlencoded");
check(bad.status == 422 && contains(bad.body, "field-error"), "inline errors");
auto ok = f.client->post("/audit/subject/erase", "subject=ada%40example.com&confirm=yes", "application/x-www-form-urlencoded");
check(ok.status == 200 && contains(ok.body, "4 rows erased"), "cascade erased 4 rows");
check(!contains(f.client->get("/audit/subject/export?subject=ada@example.com").body, "order="), "side effect: data gone");
check(contains(f.client->get("/audit/verify").body, "\"intact\":true"), "erasure audited, chain intact");
return finish("audit/subject");
}
+18
View File
@@ -0,0 +1,18 @@
// Route: GET /audit/verify + POST /audit/tamper (tamper detection)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto v = f.client->get("/audit/verify");
check(v.status == 200 && contains(v.body, "\"intact\":true") && contains(v.body, "\"first_broken\":null"), "intact");
check(f.client->post("/audit/tamper", "index=abc").status == 422, "bad index");
check(f.client->post("/audit/tamper", "index=99").status == 404, "missing record");
check(f.client->post("/audit/tamper", "index=1").status == 200, "tamper");
auto b = f.client->get("/audit/verify");
check(contains(b.body, "\"intact\":false") && contains(b.body, "\"first_broken\":1"), "first broken index reported");
check(contains(f.client->get("/audit/log").body, "Chain broken at index 1"), "side effect: page shows break");
return finish("audit/verify");
}
+20
View File
@@ -0,0 +1,20 @@
// Route: GET /cli/commands (real molo command reference)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto res = f.client->get("/cli/commands");
check(res.status == 200 && contains(res.headers.get("Content-Type"), "text/html"), "html page");
for (const char* c : {"new", "serve", "build", "embed", "migrate", "health", "supervisor", "task",
"ai", "expose", "verify", "supply-check", "release", "rollout", "rollback",
"experiment", "debug"})
check(contains(res.body, std::string("<code>molo ") + c + "</code>"), std::string("lists ") + c);
auto js = f.client->request(Method::Get, "/cli/commands", "", {{"Accept", "application/json"}});
check(contains(js.body, "\"commands\""), "json for json clients");
check(f.services.features.size() > 0, "side effect: feature rows registered");
check(f.client->request(Method::Post, "/cli/commands").status == 405, "post is 405");
return finish("clicmd/commands");
}
+24
View File
@@ -0,0 +1,24 @@
// Route: /clients/retry (capped backoff, 4xx never retried)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/clients/retry").status == 200, "status 200");
auto ok = f.client->post("/clients/retry/run", "failures=2&max_attempts=3&status=503", kForm);
check(contains(ok.body, "final status 200 after 3 attempt(s)"), "succeeds on third attempt");
check(contains(ok.body, "backoff 100ms") && contains(ok.body, "backoff 200ms"), "doubling backoff");
auto cap = f.client->post("/clients/retry/run", "failures=10&max_attempts=5&status=503", kForm);
check(contains(cap.body, "final status 503 after 5 attempt(s)"), "gives up at the attempt cap");
check(contains(cap.body, "backoff 800ms"), "backoff capped at 800ms");
auto c4 = f.client->post("/clients/retry/run", "failures=3&max_attempts=5&status=404", kForm);
check(contains(c4.body, "after 1 attempt(s)"), "404 is not retried");
auto bad = f.client->post("/clients/retry/run", "failures=1&max_attempts=9&status=200", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 1 and 5"), "422 attempts above hard cap");
check(contains(f.client->get("/clients/retry").body, "runs"), "side effect: runs counted");
return finish("clients/retry");
}
+27
View File
@@ -0,0 +1,27 @@
// Route: /clients/session (cookie jar, pool, proxy, auth)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/clients/session").status == 200, "status 200");
auto r1 = f.client->post("/clients/session/request", "auth=basic", kForm);
check(contains(r1.body, "Authorization=Basic ZGVtbzpkZW1v"), "basic auth header");
check(!contains(r1.body, "Cookie="), "first request has no cookie");
auto r2 = f.client->post("/clients/session/request", "auth=bearer", kForm);
check(contains(r2.body, "Cookie=sid=s-1; visits=1"), "cookie jar replays server cookies");
check(contains(r2.body, "Bearer demo-token"), "bearer header");
check(contains(r2.body, "connection reused"), "pooled connection reused");
auto r3 = f.client->post("/clients/session/request", "proxy=http://proxy.local:3128", kForm);
check(contains(r3.body, "connection created via http://proxy.local:3128"), "proxy change opens new connection");
auto bad = f.client->post("/clients/session/request", "proxy=ftp://x", kForm);
check(bad.status == 422 && contains(bad.body, "socks5://host:port"), "422 bad proxy");
auto badauth = f.client->post("/clients/session/request", "auth=digest", kForm);
check(badauth.status == 422, "422 unknown auth");
check(contains(f.client->get("/clients/session").body, "pool_created"), "side effect: pool stats shown");
return finish("clients/session");
}
+25
View File
@@ -0,0 +1,25 @@
// Route: GET /compress/demo (gzip negotiated by Accept-Encoding)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto plain = f.client->get("/compress/demo?size=1000");
check(plain.status == 200 && plain.body.size() == 1000, "identity body");
check(!plain.headers.has("Content-Encoding"), "no encoding without header");
auto gz = f.client->request(Method::Get, "/compress/demo?size=1000", "", {{"Accept-Encoding", "br, gzip;q=0.8"}});
check(gz.headers.get("Content-Encoding") == "gzip", "content-encoding gzip");
check(gz.body.size() > 2 && (unsigned char)gz.body[0] == 0x1f && (unsigned char)gz.body[1] == 0x8b, "gzip magic");
check(gz.headers.get("Vary") == "Accept-Encoding", "vary");
check(gz.headers.get("X-Original-Length") == "1000", "original length header");
auto refused = f.client->request(Method::Get, "/compress/demo?size=1000", "", {{"Accept-Encoding", "gzip;q=0"}});
check(!refused.headers.has("Content-Encoding"), "q=0 refuses gzip");
auto tiny = f.client->request(Method::Get, "/compress/demo?size=10", "", {{"Accept-Encoding", "gzip"}});
check(!tiny.headers.has("Content-Encoding"), "tiny bodies stay identity");
check(f.client->get("/compress/demo?size=x").status == 422, "bad size 422");
check(f.client->get("/compress/demo?size=9999999").status == 422, "size cap 422");
check(f.client->request(Method::Post, "/compress/demo").status == 405, "post is 405");
return finish("compress/demo");
}
+34
View File
@@ -0,0 +1,34 @@
// Route: GET/POST /conditional/doc (ETag, 304, Range, If-Match)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto full = f.client->get("/conditional/doc");
std::string etag = full.headers.get("ETag");
check(full.status == 200 && !etag.empty(), "200 with etag");
check(full.headers.get("Accept-Ranges") == "bytes", "accept-ranges");
auto nm = f.client->request(Method::Get, "/conditional/doc", "", {{"If-None-Match", etag}});
check(nm.status == 304 && nm.body.empty(), "304 on matching etag");
auto weak = f.client->request(Method::Get, "/conditional/doc", "", {{"If-None-Match", "W/" + etag}});
check(weak.status == 304, "weak tag matches");
auto part = f.client->request(Method::Get, "/conditional/doc", "", {{"Range", "bytes=0-9"}});
check(part.status == 206 && part.body == full.body.substr(0, 10), "206 partial body");
check(part.headers.get("Content-Range") == "bytes 0-9/" + std::to_string(full.body.size()), "content-range");
auto suffix = f.client->request(Method::Get, "/conditional/doc", "", {{"Range", "bytes=-4"}});
check(suffix.body == full.body.substr(full.body.size() - 4), "suffix range");
auto bad = f.client->request(Method::Get, "/conditional/doc", "", {{"Range", "bytes=99999-"}});
check(bad.status == 416, "416 unsatisfiable");
auto stale = f.client->request(Method::Post, "/conditional/doc", "new text", {{"If-Match", "\"nope\""}});
check(stale.status == 412, "412 on stale If-Match");
auto ok = f.client->request(Method::Post, "/conditional/doc", "new text", {{"If-Match", etag}});
check(ok.status == 200, "update with matching If-Match");
auto after = f.client->get("/conditional/doc");
check(after.body == "new text" && after.headers.get("ETag") != etag, "side effect: new body and etag");
check(f.client->request(Method::Post, "/conditional/doc", "").status == 422, "empty body 422");
check(f.client->request(Method::Post, "/conditional/doc", std::string(5000, 'x')).status == 413, "over cap 413");
check(f.client->request(Method::Delete, "/conditional/doc").status == 405, "delete is 405");
return finish("conditional/doc");
}
+25
View File
@@ -0,0 +1,25 @@
// Route: GET /context/trace (traceparent continuation, correlation id)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
std::string tid = "4bf92f3577b34da6a3ce929d0e0e4736";
auto cont = f.client->request(Method::Get, "/context/trace", "",
{{"traceparent", "00-" + tid + "-00f067aa0ba902b7-01"}, {"X-Correlation-ID", "corr-9"}});
check(cont.status == 200, "status 200");
check(contains(cont.body, "\"trace_id\":\"" + tid), "trace id continued");
check(contains(cont.body, "\"parent_span_id\":\"00f067aa0ba902b7\""), "parent span reported");
check(cont.headers.get("traceparent").rfind("00-" + tid + "-", 0) == 0, "response traceparent same trace");
check(!contains(cont.headers.get("traceparent"), "00f067aa0ba902b7"), "new span id");
check(cont.headers.get("X-Correlation-ID") == "corr-9", "correlation propagated");
auto fresh = f.client->get("/context/trace");
check(contains(fresh.body, "\"continued\":false") && contains(fresh.body, "\"parent_valid\":true"), "new trace");
check(fresh.headers.get("X-Correlation-ID").rfind("req-", 0) == 0, "falls back to request id");
auto bad = f.client->request(Method::Get, "/context/trace", "", {{"traceparent", "garbage"}});
check(contains(bad.body, "\"parent_valid\":false") && contains(bad.body, "\"continued\":false"), "invalid parent restarts trace");
check(f.client->request(Method::Post, "/context/trace").status == 405, "post is 405");
return finish("context/trace");
}
+19
View File
@@ -0,0 +1,19 @@
// Route: /crypto/hash (real SHA-256 and HMAC-SHA256)
#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("/crypto/hash").body, "<form"), "form renders");
auto r = f.client->post("/crypto/hash", "text=abc", kForm);
check(r.status == 200, "status 200");
check(contains(r.body, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"), "sha256(abc) vector");
auto m = f.client->post("/crypto/hash", "text=what+do+ya+want+for+nothing%3F&key=Jefe", kForm);
check(contains(m.body, "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"), "RFC 4231 hmac vector");
auto bad = f.client->post("/crypto/hash", "text=", kForm);
check(bad.status == 422 && contains(bad.body, "form-errors"), "empty text inline 422");
auto big = f.client->post("/crypto/hash", "text=" + std::string(5000, 'a'), kForm);
check(big.status == 422, "over cap 422");
check(f.client->request(molo::example::fw::Method::Put, "/crypto/hash").status == 405, "PUT is 405");
return finish("crypto/hash");
}
+18
View File
@@ -0,0 +1,18 @@
// Route: /crypto/password (salted PBKDF2, demo rounds)
#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("/crypto/password").body, "DEMO"), "labelled demo");
auto a = f.client->post("/crypto/password", "password=correct-horse", kForm);
auto b = f.client->post("/crypto/password", "password=correct-horse", kForm);
check(a.status == 200 && contains(a.body, "pbkdf2-demo$2000$"), "hash format");
check(contains(a.body, "verify ok: yes") && contains(a.body, "wrong password: rejected"), "verify works");
auto salt = [](const std::string& s) { std::size_t p = s.find("pbkdf2-demo$2000$"); return s.substr(p + 17, 32); };
check(salt(a.body) != salt(b.body), "salt differs per hash");
auto bad = f.client->post("/crypto/password", "password=short", kForm);
check(bad.status == 422 && contains(bad.body, "must be 8 to 128"), "short password inline 422");
check(f.client->post("/crypto/password", "password=" + std::string(129, 'a'), kForm).status == 422, "over cap 422");
return finish("crypto/password");
}
+15
View File
@@ -0,0 +1,15 @@
// Route: GET /crypto/random (urandom token, 1 to 64 bytes)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto a = f.client->get("/crypto/random?bytes=8");
auto b = f.client->get("/crypto/random?bytes=8");
check(a.status == 200 && contains(a.body, "\"bytes\":8"), "8 bytes ok");
check(a.body != b.body, "tokens differ");
check(f.client->get("/crypto/random").status == 200, "default ok");
check(f.client->get("/crypto/random?bytes=65").status == 400, "over cap 400");
check(f.client->get("/crypto/random?bytes=abc").status == 400, "non numeric 400");
check(f.client->post("/crypto/random", "x").status == 405, "POST 405");
return finish("crypto/random");
}
+24
View File
@@ -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");
}
+19
View File
@@ -0,0 +1,19 @@
// Route: /csp/report (violation report intake, capped store)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto ok = f.client->post("/csp/report", "{\"csp-report\":{\"blocked-uri\":\"inline\"}}", "application/csp-report");
check(ok.status == 204, "report accepted 204");
auto empty = f.client->post("/csp/report", "", "application/csp-report");
check(empty.status == 400, "empty report is 400");
auto big = f.client->post("/csp/report", std::string(5000, 'x'), "application/csp-report");
check(big.status == 400, "oversized report is 400");
for (int i = 0; i < 60; ++i) f.client->post("/csp/report", "r", "application/csp-report");
auto list = f.client->get("/csp/report");
check(list.status == 200 && contains(list.body, "\"total\":61"), "total counted");
std::size_t n = 0, p = 0;
while ((p = list.body.find("\"r\"", p)) != std::string::npos) { ++n; p += 3; }
check(n <= 50, "stored reports capped at 50");
return finish("csp/report");
}
+28
View File
@@ -0,0 +1,28 @@
// Route: /data/migrations (check preview, apply, drift, heal)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
auto page = f.client->get("/data/migrations");
check(page.status == 200, "status 200");
check(contains(page.body, "CREATE TABLE users") && contains(page.body, "CREATE TABLE posts"), "preview lists pending sql");
check(contains(page.body, "none"), "nothing applied by viewing");
auto one = f.client->post("/data/migrations/apply", "limit=1", kForm);
check(contains(one.body, "1 migration(s) applied"), "apply one step");
check(!contains(one.body, "CREATE TABLE users"), "applied step leaves the preview");
check(contains(one.body, "CREATE TABLE posts"), "later steps still pending");
auto rest = f.client->post("/data/migrations/apply", "limit=3", kForm);
check(contains(rest.body, "2 migration(s) applied"), "rest applied");
check(contains(rest.body, "table posts"), "side effect: table exists");
f.client->post("/data/migrations/drift", "", kForm);
check(contains(f.client->get("/data/migrations").body, "003 posts"), "drift detected");
check(contains(f.client->post("/data/migrations/heal", "", kForm).body, "1 table(s) healed"), "healer repairs drift");
auto bad = f.client->post("/data/migrations/apply", "limit=9", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 1 and 3"), "422 step limit");
return finish("data/migrations");
}
+24
View File
@@ -0,0 +1,24 @@
// Route: /data/query (query builder and has-many relation)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/query").status == 200, "status 200");
auto all = f.client->post("/data/query/run", "limit=10&order=title", kForm);
check(contains(all.body, "ORDER BY posts.title LIMIT 10"), "sql built");
check(contains(all.body, "5 row(s)"), "five posts");
check(contains(all.body, "Alpha by ada") && contains(all.body, "Beta by grace"), "relation joins author");
auto ada = f.client->post("/data/query/run", "user_id=1", kForm);
check(contains(ada.body, "WHERE posts.user_id = 1") && contains(ada.body, "3 row(s)"), "where filter");
auto lim = f.client->post("/data/query/run", "limit=2", kForm);
check(contains(lim.body, "2 row(s)"), "limit applied");
auto bad = f.client->post("/data/query/run", "order=name", kForm);
check(bad.status == 422 && contains(bad.body, "must be one of: id, title"), "422 order whitelist");
check(f.client->post("/data/query/run", "limit=99", kForm).status == 422, "422 limit above cap");
return finish("data/query");
}
+22
View File
@@ -0,0 +1,22 @@
// Route: /data/singleflight (concurrent loads collapse into one)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/singleflight").status == 200, "status 200");
auto res = f.client->post("/data/singleflight/run", "callers=8", kForm);
check(contains(res.body, "8 callers, 1 load(s)"), "eight callers share one load");
auto one = f.client->post("/data/singleflight/run", "callers=1", kForm);
check(contains(one.body, "1 callers, 1 load(s)"), "single caller loads once");
auto max = f.client->post("/data/singleflight/run", "callers=16", kForm);
check(contains(max.body, "16 callers, 1 load(s)"), "cap of 16 threads still collapses");
auto bad = f.client->post("/data/singleflight/run", "callers=17", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 1 and 16"), "422 above thread cap");
check(contains(f.client->get("/data/singleflight").body, ">3<"), "side effect: three runs counted");
return finish("data/singleflight");
}
+26
View File
@@ -0,0 +1,26 @@
// Route: /data/transaction (commit and rollback)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/transaction").status == 200, "status 200");
auto ok = f.client->post("/data/transaction/transfer", "amount=30", kForm);
check(contains(ok.body, "committed"), "commit");
check(f.services.sqlite != nullptr, "fixture alive");
auto fail = f.client->post("/data/transaction/transfer", "amount=10&fail_after_debit=1", kForm);
check(contains(fail.body, "rolled back: failure after debit"), "failure rolls back");
auto over = f.client->post("/data/transaction/transfer", "amount=500", kForm);
check(contains(over.body, "rolled back: insufficient funds"), "overdraft rolls back");
auto json = f.client->request(Method::Post, "/data/transaction/transfer", "{\"amount\":\"1\"}", {{"Content-Type", "application/json"}});
check(json.status == 200 && contains(json.body, "\"alice\":\"69\""), "alice 100-30-1; rollbacks changed nothing");
check(contains(json.body, "\"rollbacks\":\"2\"") && contains(json.body, "\"commits\":\"2\""), "side effect: counters");
auto same = f.client->post("/data/transaction/transfer", "from=bob&to=bob&amount=5", kForm);
check(same.status == 422 && contains(same.body, "must differ"), "422 same account");
check(f.client->post("/data/transaction/transfer", "amount=0", kForm).status == 422, "422 amount limit");
return finish("data/transaction");
}
+26
View File
@@ -0,0 +1,26 @@
// Route: /data/ttl (TTL expiry, LRU eviction, pubsub events)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/ttl").status == 200, "status 200");
f.client->post("/data/ttl/set", "key=a&value=1&ttl_s=5", kForm);
check(contains(f.client->post("/data/ttl/get", "key=a", kForm).body, "hit: 1"), "hit");
f.client->post("/data/ttl/tick", "", kForm);
auto gone = f.client->post("/data/ttl/get", "key=a", kForm);
check(contains(gone.body, "miss") && contains(gone.body, "expired a"), "expired after ttl, event published");
for (int i = 0; i < 6; ++i)
f.client->post("/data/ttl/set", "key=k" + std::to_string(i) + "&value=v&ttl_s=60", kForm);
auto page = f.client->get("/data/ttl");
check(contains(page.body, "5/5"), "capacity capped at 5");
check(contains(page.body, "evicted k0 (lru)"), "oldest key evicted");
auto bad = f.client->post("/data/ttl/set", "key=&value=x&ttl_s=0", kForm);
check(bad.status == 422 && contains(bad.body, "is required"), "422 missing key");
check(f.client->post("/data/ttl/set", "key=a&value=b&ttl_s=999", kForm).status == 422, "422 ttl above cap");
return finish("data/ttl");
}
+26
View File
@@ -0,0 +1,26 @@
// Route: GET /di/services, /di/resolve/{name} (lifetimes)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto list = f.client->get("/di/services");
check(list.status == 200 && contains(list.body, "singleton") && contains(list.body, "transient") &&
contains(list.body, "scoped"), "lists lifetimes");
auto a = f.client->get("/di/resolve/config");
auto b = f.client->get("/di/resolve/config");
check(a.body == b.body, "singleton is stable");
auto m1 = f.client->get("/di/resolve/mailer");
auto m2 = f.client->get("/di/resolve/mailer");
check(m1.body != m2.body, "transient differs");
auto s1 = f.client->get("/di/resolve/request-context?scope=r1");
auto s2 = f.client->get("/di/resolve/request-context?scope=r1");
auto s3 = f.client->get("/di/resolve/request-context?scope=r2");
check(s1.body == s2.body && s1.body != s3.body, "scoped per scope key");
check(f.client->get("/di/resolve/ghost").status == 404, "unknown 404");
check(contains(f.client->get("/di/services").body, "<td>2</td>"), "side effect: resolve counts");
check(f.client->request(Method::Post, "/di/services").status == 405, "post is 405");
return finish("di/services");
}
+29
View File
@@ -0,0 +1,29 @@
// Route: GET /expose/stats, POST /expose/record (per-method table, windowed kB/s)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto empty = f.client->get("/expose/stats");
check(empty.status == 200 && contains(empty.body, "_total"), "page with total row");
auto form = f.client->get("/expose/record");
check(form.status == 200 && contains(form.body, "<form"), "record form");
const std::map<std::string, std::string> h = {{"Content-Type", "application/x-www-form-urlencoded"}};
auto ok = f.client->request(Method::Post, "/expose/record", "method=GET&bytes_up=2048&bytes_down=10240&micros=4000", h);
check(ok.status == 303 && ok.headers.get("Location") == "/expose/stats", "redirect");
f.client->request(Method::Post, "/expose/record", "method=GET&bytes_up=0&bytes_down=0&micros=2000", h);
auto js = f.client->request(Method::Get, "/expose/stats", "", {{"Accept", "application/json"}});
check(contains(js.body, "\"GET\":{\"count\":2"), "count per method");
check(contains(js.body, "\"kb_up\":2.0") && contains(js.body, "\"kb_down\":10.0"), "kB up and down");
check(contains(js.body, "\"avg_ms\":3.00"), "average latency");
check(contains(js.body, "\"kb_s_down\":0.17"), "windowed kB/s (10 kB over 60 s)");
auto bad = f.client->request(Method::Post, "/expose/record", "method=FETCH&bytes_up=-1&bytes_down=x&micros=", h);
check(bad.status == 422 && contains(bad.body, "field-error"), "inline errors in page");
auto badjson = f.client->request(Method::Post, "/expose/record", "method=FETCH&bytes_up=1&bytes_down=1&micros=1",
{{"Content-Type", "application/x-www-form-urlencoded"}, {"Accept", "application/json"}});
check(badjson.status == 422 && contains(badjson.body, "method"), "json client gets json");
check(f.client->request(Method::Delete, "/expose/stats").status == 405, "delete is 405");
return finish("expose/stats");
}
+23
View File
@@ -0,0 +1,23 @@
// Route: GET /flash, POST /flash/set (cookie flash shown once)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(contains(f.client->get("/flash").body, "No flash message"), "empty at start");
auto bad = f.client->request(Method::Post, "/flash/set", "message=", {{"Content-Type", "application/x-www-form-urlencoded"}});
check(bad.status == 422 && contains(bad.body, "field-error"), "inline validation error");
auto set = f.client->request(Method::Post, "/flash/set", "message=Saved+%3Cb%3E", {{"Content-Type", "application/x-www-form-urlencoded"}});
check(set.status == 303 && set.headers.get("Location") == "/flash", "redirect");
check(contains(set.headers.get("Set-Cookie"), "flash="), "flash cookie set");
auto once = f.client->get("/flash");
check(contains(once.body, "Saved &lt;b&gt;"), "shown escaped");
check(contains(once.headers.get("Set-Cookie"), "Max-Age=0"), "cookie cleared");
check(contains(f.client->get("/flash").body, "No flash message"), "gone on next view");
auto too_long = f.client->request(Method::Post, "/flash/set", "message=" + std::string(300, 'a'), {{"Content-Type", "application/x-www-form-urlencoded"}});
check(too_long.status == 422, "length limit");
check(f.client->request(Method::Delete, "/flash").status == 405, "delete is 405");
return finish("flash/flash");
}
+21
View File
@@ -0,0 +1,21 @@
// Route: GET/POST /governance/diff (breaking change detection)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(f.client->get("/governance/diff").status == 200, "form");
auto bad = f.client->post("/governance/diff", "before=GET+%2Fa", "application/x-www-form-urlencoded");
check(bad.status == 422 && contains(bad.body, "field-error"), "after required");
std::string before = "GET /items required=id\nDELETE /items required=id\n";
std::string after = "GET /items required=id,page\nPOST /items required=name\n";
auto r = f.client->request(Method::Post, "/governance/diff", "before=" + before + "&after=" + after, {{"Accept", "application/json"}});
check(r.status == 200 && contains(r.body, "\"breaking\":2"), "two breaking changes");
check(contains(r.body, "operation removed") && contains(r.body, "new required parameter page"), "details");
check(contains(r.body, "operation added"), "compatible addition");
auto same = f.client->request(Method::Post, "/governance/diff", "before=GET /a&after=GET /a", {{"Accept", "application/json"}});
check(contains(same.body, "\"breaking\":0"), "side effect: identical specs clean");
return finish("governance/diff");
}
+27
View File
@@ -0,0 +1,27 @@
// Route: GET/POST /governance/keys (+ revoke, whoami): API keys with scopes
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(f.client->get("/governance/keys").status == 200, "form page");
auto bad = f.client->post("/governance/keys", "owner=&tier=gold", "application/x-www-form-urlencoded");
check(bad.status == 422 && contains(bad.body, "field-error"), "inline errors");
auto js = f.client->request(Method::Post, "/governance/keys", "owner=ada&tier=free&scopes=read", {{"Accept", "application/json"}});
check(js.status == 201 && contains(js.body, "mk_"), "issued");
std::string key = js.body.substr(js.body.find("mk_"), 35);
auto who = f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
check(who.status == 200 && contains(who.body, "ada"), "authenticates");
check(f.client->get("/governance/whoami").status == 401, "missing key 401");
check(f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", "mk_bogus"}}).status == 401, "unknown 401");
auto nos = f.client->request(Method::Post, "/governance/keys", "owner=bob&scopes=write", {{"Accept", "application/json"}});
std::string k2 = nos.body.substr(nos.body.find("mk_"), 35);
check(f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", k2}}).status == 403, "missing scope 403");
check(f.client->post("/governance/keys/key1/revoke").status == 200, "revoke");
auto rev = f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
check(rev.status == 401 && contains(rev.body, "Revoked"), "side effect: revoked key rejected");
check(f.client->post("/governance/keys/nope/revoke").status == 404, "unknown revoke 404");
return finish("governance/keys");
}
+20
View File
@@ -0,0 +1,20 @@
// Route: GET/POST /governance/lint (route linter, HTML form)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(f.client->get("/governance/lint").status == 200, "form");
auto bad = f.client->post("/governance/lint", "paths=", "application/x-www-form-urlencoded");
check(bad.status == 422 && contains(bad.body, "field-error") && !contains(bad.body, "\"failures\""), "inline error");
auto ok = f.client->post("/governance/lint", "paths=%2Fusers%2F%0A%2FgetUser%0A%2Fuser_list%0A%2Fusers", "application/x-www-form-urlencoded");
check(ok.status == 200 && contains(ok.body, "no-trailing-slash"), "trailing slash found");
check(contains(ok.body, "lowercase-only") && contains(ok.body, "kebab-case"), "other rules");
auto clean = f.client->request(Method::Post, "/governance/lint", "paths=/users\n/orders", {{"Accept", "application/json"}});
check(contains(clean.body, "\"findings\":[]"), "clean paths: no findings (json)");
auto verbs = f.client->request(Method::Post, "/governance/lint", "paths=/api/get/users", {{"Accept", "application/json"}});
check(contains(verbs.body, "no-verbs-in-path"), "side effect: verb rule");
return finish("governance/lint");
}
+18
View File
@@ -0,0 +1,18 @@
// Route: GET /governance/problem[/:status] (RFC 7807)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(f.client->get("/governance/problem").status == 200, "overview");
auto p = f.client->get("/governance/problem/404");
check(p.status == 404 && contains(p.headers.get("Content-Type"), "application/problem+json"), "problem content type");
check(contains(p.body, "\"status\":404") && contains(p.body, "\"title\"") && contains(p.body, "\"instance\""), "rfc7807 members");
auto bad = f.client->get("/governance/problem/200");
check(bad.status == 400 && contains(bad.headers.get("Content-Type"), "problem+json"), "out of range is 400");
check(f.client->get("/governance/problem/abc").status == 400, "non numeric");
check(f.client->post("/governance/problem/404").status == 405, "405");
return finish("governance/problem");
}
+23
View File
@@ -0,0 +1,23 @@
// Route: GET /governance/tiers (+ whoami rate-limit headers)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto t = f.client->get("/governance/tiers");
check(t.status == 200 && contains(t.body, "\"per_min\":3") && contains(t.body, "\"per_min\":10"), "tiers");
auto js = f.client->request(Method::Post, "/governance/keys", "owner=ada&tier=free&scopes=read", {{"Accept", "application/json"}});
std::string key = js.body.substr(js.body.find("mk_"), 35);
auto r1 = f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
check(r1.headers.get("X-RateLimit-Limit") == "3" && r1.headers.get("X-RateLimit-Remaining") == "2", "headers");
check(r1.headers.get("X-Tier") == "free", "tier header");
f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
auto r4 = f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
check(r4.status == 429 && r4.headers.get("Retry-After") == "60", "limit 429 with Retry-After");
check(contains(r4.headers.get("Content-Type"), "problem+json"), "problem body");
check(r4.headers.get("X-RateLimit-Remaining") == "0", "side effect: ledger exhausted");
return finish("governance/tiers");
}
@@ -0,0 +1,15 @@
// Route: GET /governance/versions (version table)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto r = f.client->get("/governance/versions");
check(r.status == 200 && contains(r.body, "\"deprecated\":true") && contains(r.body, "\"deprecated\":false"), "table");
check(contains(r.body, "GMT"), "sunset date listed");
check(f.client->post("/governance/versions").status == 405, "405");
check(contains(r.headers.get("Content-Type"), "application/json"), "json");
return finish("governance/versions");
}
+26
View File
@@ -0,0 +1,26 @@
// Route: GET /healthz /readyz /startupz (probes, startup gate, 503)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto live = f.client->get("/healthz");
check(live.status == 200 && contains(live.body, "alive"), "liveness 200");
check(contains(live.headers.get("Content-Type"), "application/json"), "json");
check(f.client->get("/readyz").status == 200, "ready at start");
check(f.client->get("/startupz").status == 200, "started");
auto gate = f.client->request(Method::Post, "/startupz/tasks/seed-data?state=pending");
check(gate.status == 503 && contains(gate.body, "pending"), "gate closed is 503");
check(f.client->get("/readyz").status == 503, "not ready while starting");
check(f.client->get("/healthz").status == 200, "liveness unaffected");
f.client->request(Method::Post, "/startupz/tasks/seed-data?state=done");
auto down = f.client->request(Method::Post, "/readyz/checks/database?state=down");
check(down.status == 503 && contains(down.body, "\"database\":\"down\""), "failed check 503");
check(f.client->request(Method::Post, "/readyz/checks/database?state=up").status == 200, "recovers");
check(f.client->request(Method::Post, "/readyz/checks/database?state=meh").status == 422, "bad state 422");
check(f.client->request(Method::Post, "/readyz/checks/nothing?state=up").status == 404, "unknown check 404");
check(f.client->request(Method::Post, "/healthz").status == 405, "post is 405");
return finish("healthz/probes");
}
+34
View File
@@ -0,0 +1,34 @@
// Route: GET /i18n (locale negotiation, plurals, .po dump)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto en = f.client->get("/i18n?n=1");
check(en.status == 200, "status 200");
check(contains(en.headers.get("Content-Type"), "text/html"), "html");
check(contains(en.body, "1 item<"), "english singular");
check(en.headers.get("Content-Language") == "en", "content-language en");
auto ru = f.client->get("/i18n?lang=ru&n=22");
check(contains(ru.body, "22 предмета"), "russian few form");
auto ru5 = f.client->get("/i18n?lang=ru&n=5");
check(contains(ru5.body, "5 предметов"), "russian many form");
auto fr = f.client->get("/i18n?lang=fr&n=0");
check(contains(fr.body, "0 article<"), "french zero is singular");
auto hdr = f.client->request(Method::Get, "/i18n?n=2", "", {{"Accept-Language", "de;q=0.5, nl;q=0.9"}});
check(hdr.headers.get("Content-Language") == "nl", "accept-language q weights");
auto prm = f.client->request(Method::Get, "/i18n?lang=ja", "", {{"Accept-Language", "nl"}});
check(prm.headers.get("Content-Language") == "ja", "?lang beats header");
auto bad = f.client->get("/i18n?n=abc");
check(bad.status == 422 && contains(bad.body, "field-error"), "inline validation error");
check(!contains(bad.body, "{\""), "no raw json in page");
auto huge = f.client->get("/i18n?n=99999999");
check(huge.status == 422, "limit: count capped");
auto po = f.client->get("/i18n/po?lang=ru");
check(contains(po.body, "msgstr[2]") && contains(po.body, "nplurals=3"), "po catalog");
check(f.client->get("/i18n/po?lang=xx").status == 404, "unknown locale 404");
check(f.client->request(Method::Post, "/i18n").status == 405, "post is 405");
return finish("i18n/page");
}
+35
View File
@@ -0,0 +1,35 @@
// Route: GET /logging/records, POST /logging/emit (levels, redaction, ring cap)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto form = f.client->get("/logging/emit");
check(form.status == 200 && contains(form.body, "<form"), "form page");
auto ok = f.client->request(Method::Post, "/logging/emit", "level=warn&message=login+password%3Dhunter2+failed",
{{"Content-Type", "application/x-www-form-urlencoded"}, {"X-Correlation-ID", "abc-1"}});
check(ok.status == 303 && ok.headers.get("Location") == "/logging/records", "redirect after emit");
auto page = f.client->get("/logging/records");
check(page.status == 200 && contains(page.body, "password=***"), "secret redacted");
check(!contains(page.body, "hunter2"), "secret not shown");
check(contains(page.body, "abc-1"), "correlation id kept");
auto lines = f.client->get("/logging/records?format=json&level=warn");
check(contains(lines.body, "\"level\":\"warn\"") && !contains(lines.body, "platform demo ready"), "json lines, level filter");
auto bad = f.client->request(Method::Post, "/logging/emit", "level=loud&message=",
{{"Content-Type", "application/x-www-form-urlencoded"}});
check(bad.status == 422 && contains(bad.body, "field-error") && !contains(bad.body, "\"error\""), "html inline errors");
auto js = f.client->request(Method::Post, "/logging/emit", "{\"level\":\"loud\"}",
{{"Content-Type", "application/json"}});
check(js.status == 422 && contains(js.body, "level"), "json client gets json");
check(f.client->get("/logging/records?n=101").status == 422, "n capped at 100");
for (int i = 0; i < 230; ++i)
f.client->request(Method::Post, "/logging/emit", "level=info&message=m" + std::to_string(i),
{{"Content-Type", "application/x-www-form-urlencoded"}});
auto all = f.client->get("/logging/records?n=100&format=json");
check(contains(all.body, "m229") && !contains(all.body, "m100\""), "newest first, capped to n");
check(contains(f.client->get("/logging/records").body, "now 200"), "ring capped at 200");
check(f.client->request(Method::Delete, "/logging/records").status == 405, "delete is 405");
return finish("logging/records");
}
+26
View File
@@ -0,0 +1,26 @@
// Route: GET / (every matrix link resolves; no dead rows)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto index = f.client->get("/");
check(index.status == 200, "index renders");
std::size_t pos = 0, rows = 0;
const std::string marker = "<td><a href=\"";
while ((pos = index.body.find(marker, pos)) != std::string::npos) {
pos += marker.size();
std::string href = index.body.substr(pos, index.body.find('"', pos) - pos);
// The template escapes '&' in hrefs.
for (std::size_t a; (a = href.find("&amp;")) != std::string::npos;)
href.replace(a, 5, "&");
auto res = f.client->get(href);
// /auth/me demands credentials by design; every other row must be 2xx/3xx.
bool ok = res.status < 400 || (href == "/auth/me" && res.status == 401);
check(ok, "matrix link " + href + " -> " + std::to_string(res.status));
++rows;
}
check(rows >= 37, "matrix lists at least the original 37 rows");
return finish("matrix");
}
+21
View File
@@ -0,0 +1,21 @@
// Route: GET/POST /middleware/demo (builtin chain: headers, body limit, timing)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto res = f.client->get("/middleware/demo");
check(res.status == 200, "status 200");
check(res.headers.get("X-Content-Type-Options") == "nosniff", "secure headers");
check(res.headers.get("X-Frame-Options") == "DENY", "frame options");
check(res.headers.has("X-Response-Time-Us"), "timing header");
auto small = f.client->request(Method::Post, "/middleware/demo", "tiny");
check(small.status == 200 && contains(small.body, "Received 4 body bytes"), "small body passes");
auto big = f.client->request(Method::Post, "/middleware/demo", std::string(65, 'x'));
check(big.status == 413, "body limit 413");
check(big.headers.get("X-Frame-Options") == "DENY", "outer middleware still runs on short circuit");
check(f.client->request(Method::Delete, "/middleware/demo").status == 405, "delete is 405");
return finish("middleware/demo");
}
@@ -0,0 +1,28 @@
// Route: /operability/breaker (closed -> open -> half-open -> closed)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
auto page = f.client->get("/operability/breaker");
check(page.status == 200, "status 200");
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
check(contains(page.body, "closed"), "starts closed");
for (int i = 0; i < 3; ++i) f.client->post("/operability/breaker/failure", "", kForm);
check(contains(f.client->get("/operability/breaker").body, ">open<"), "three failures open it");
auto rej = f.client->post("/operability/breaker/success", "", kForm);
check(contains(rej.body, "rejected: breaker open"), "call rejected while open");
for (int i = 0; i < 3; ++i) f.client->post("/operability/breaker/tick", "", kForm);
check(contains(f.client->get("/operability/breaker").body, ">half-open<"), "30 s later half-open");
f.client->post("/operability/breaker/success", "", kForm);
check(contains(f.client->get("/operability/breaker").body, ">closed<"), "good probe closes");
auto json = f.client->request(Method::Post, "/operability/breaker/failure", "", {{"Accept", "application/json"}});
check(json.status == 200 && contains(json.body, "\"name\":\"breaker\""), "json client gets state");
check(f.client->request(Method::Delete, "/operability/breaker").status == 405, "405 on delete");
check(contains(f.client->get("/operability/debug").body, "\"breaker\""), "side effect: debug snapshot lists it");
return finish("operability/breaker");
}
@@ -0,0 +1,24 @@
// Route: /operability/bulkhead (2 slots, queue of 1, then reject)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/operability/bulkhead").status == 200, "status 200");
auto a = f.client->post("/operability/bulkhead/acquire", "", kForm);
check(contains(a.body, ">admitted<") || contains(a.body, "admitted"), "first admitted");
f.client->post("/operability/bulkhead/acquire", "", kForm);
auto q = f.client->post("/operability/bulkhead/acquire", "", kForm);
check(contains(q.body, "queued"), "third queued");
auto r = f.client->post("/operability/bulkhead/acquire", "", kForm);
check(contains(r.body, "rejected: compartment full"), "fourth rejected (limit)");
check(contains(r.body, "2/2"), "side effect: active slots full");
check(f.client->post("/operability/bulkhead/nope", "", kForm).status == 404, "404 unknown action");
for (int i = 0; i < 3; ++i) f.client->post("/operability/bulkhead/release", "", kForm);
check(contains(f.client->post("/operability/bulkhead/release", "", kForm).body, "nothing to release"), "empty release is reported");
return finish("operability/bulkhead");
}
+22
View File
@@ -0,0 +1,22 @@
// Route: /operability/chaos (dry run default, hard blast radius)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/operability/chaos").status == 200, "status 200");
auto dry = f.client->post("/operability/chaos/run", "percent=40&max_faults=3", kForm);
check(contains(dry.body, "dry run: 0 injected, 3 planned"), "default is a dry run");
auto armed = f.client->post("/operability/chaos/run", "percent=40&max_faults=2&armed=1", kForm);
check(contains(armed.body, "armed: 2 injected, 2 planned"), "armed run capped at max_faults");
auto big = f.client->post("/operability/chaos/run", "percent=90&max_faults=9", kForm);
check(big.status == 422 && contains(big.body, "must be between 0 and 50"), "percent above cap rejected");
check(contains(big.body, "must be between 1 and 5"), "faults above cap rejected");
check(contains(f.client->get("/operability/chaos").body, "total_injected"), "side effect: totals tracked");
check(contains(f.client->get("/operability/chaos").body, ">2<"), "only the armed run injected");
return finish("operability/chaos");
}
+28
View File
@@ -0,0 +1,28 @@
// Route: /operability/coord (lease, election, lock with fencing tokens)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/operability/coord").status == 200, "status 200");
auto a = f.client->post("/operability/coord/acquire", "key=lock&owner=a", kForm);
check(contains(a.body, "granted token 1"), "a gets token 1");
auto b = f.client->post("/operability/coord/acquire", "key=lock&owner=b", kForm);
check(contains(b.body, "denied, held by a"), "b denied while lease live");
f.client->post("/operability/coord/tick", "", kForm);
f.client->post("/operability/coord/tick", "", kForm);
auto b2 = f.client->post("/operability/coord/acquire", "key=lock&owner=b", kForm);
check(contains(b2.body, "granted token 2"), "b gets token 2 after expiry");
check(contains(f.client->post("/operability/coord/write", "key=lock&token=2", kForm).body, "write accepted"), "fresh token writes");
auto stale = f.client->post("/operability/coord/write", "key=lock&token=1", kForm);
check(contains(stale.body, "stale fencing token"), "stale token fenced off");
auto bad = f.client->post("/operability/coord/acquire", "key=db&owner=a", kForm);
check(bad.status == 422, "422 unknown key");
check(contains(f.client->post("/operability/coord/acquire", "key=leader&owner=n1", kForm).body, "granted"), "election via leader key");
check(contains(f.client->get("/operability/coord").body, "held by b"), "side effect: holder shown");
return finish("operability/coord");
}
@@ -0,0 +1,22 @@
// Route: /operability/deadline (budget shared across hops)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/operability/deadline").status == 200, "status 200");
auto ok = f.client->post("/operability/deadline/run", "budget_ms=100&hops=3", kForm);
check(contains(ok.body, "all hops finished in budget"), "fits in budget");
auto late = f.client->post("/operability/deadline/run", "budget_ms=70&hops=5", kForm);
check(contains(late.body, "deadline exceeded at hop 3"), "expires at hop 3");
check(contains(late.body, "call skipped"), "side effect: log shows skipped hop");
auto bad = f.client->post("/operability/deadline/run", "budget_ms=99999&hops=0", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 0 and 5000"), "422 limit on budget");
auto json = f.client->request(Method::Post, "/operability/deadline/run", "{\"budget_ms\":\"abc\"}", {{"Content-Type", "application/json"}});
check(json.status == 422 && contains(json.headers.get("Content-Type"), "json"), "json client gets json error");
return finish("operability/deadline");
}
+21
View File
@@ -0,0 +1,21 @@
// Route: /operability/debug (snapshot of every lab)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
f.client->post("/operability/slo/bad", "", kForm);
auto res = f.client->get("/operability/debug");
check(res.status == 200, "status 200");
check(contains(res.headers.get("Content-Type"), "application/json"), "json");
check(contains(res.body, "\"labs\""), "labs object");
for (const char* n : {"breaker", "bulkhead", "shedder", "deadline", "slo", "chaos", "deploy", "coord", "supplychain", "client-retry", "client-session", "migrations", "transaction", "query", "singleflight", "ttl"})
check(contains(res.body, std::string("\"") + n + "\":{"), std::string("lab present: ") + n);
check(contains(res.body, "bad event"), "side effect: earlier action visible in log");
check(f.client->post("/operability/debug", "", kForm).status == 405, "405 on post");
return finish("operability/debug");
}
+28
View File
@@ -0,0 +1,28 @@
// Route: /operability/deploy (rolling, blue-green, rollback)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/operability/deploy").status == 200, "status 200");
f.client->post("/operability/deploy/start", "strategy=rolling&version=v2", kForm);
f.client->post("/operability/deploy/step", "", kForm);
check(contains(f.client->get("/operability/deploy").body, "v2,v1,v1,v1"), "one instance replaced");
auto again = f.client->post("/operability/deploy/start", "strategy=rolling", kForm);
check(contains(again.body, "already in progress"), "second rollout refused");
auto rb = f.client->post("/operability/deploy/rollback", "", kForm);
check(contains(rb.body, "v1,v1,v1,v1") && contains(rb.body, "rolled back"), "rollback restores fleet");
f.client->post("/operability/deploy/start", "strategy=bluegreen&version=v3", kForm);
f.client->post("/operability/deploy/step", "", kForm);
check(contains(f.client->get("/operability/deploy").body, "v1,v1,v1,v1"), "green prepared, blue serves");
f.client->post("/operability/deploy/step", "", kForm);
auto done = f.client->get("/operability/deploy");
check(contains(done.body, "v3,v3,v3,v3") && contains(done.body, "done"), "switched");
auto bad = f.client->post("/operability/deploy/start", "strategy=canary", kForm);
check(bad.status == 422 && contains(bad.body, "must be one of: rolling, bluegreen"), "422 unknown strategy");
return finish("operability/deploy");
}
@@ -0,0 +1,23 @@
// Route: /operability/shedder (low priority shed first)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/operability/shedder").status == 200, "status 200");
f.client->post("/operability/shedder/enter", "priority=low", kForm);
f.client->post("/operability/shedder/enter", "priority=low", kForm);
auto low = f.client->post("/operability/shedder/enter", "priority=low", kForm);
check(contains(low.body, "shed"), "third low request shed");
auto high = f.client->post("/operability/shedder/enter", "priority=high", kForm);
check(contains(high.body, "accepted"), "high priority still accepted");
auto bad = f.client->post("/operability/shedder/enter", "priority=urgent", kForm);
check(bad.status == 422 && contains(bad.body, "must be one of: low, high"), "422 inline error");
check(!contains(bad.body, "{\"errors\""), "no raw json in page");
check(contains(f.client->get("/operability/shedder").body, "3/3"), "side effect: inflight 3/3");
return finish("operability/shedder");
}
+25
View File
@@ -0,0 +1,25 @@
// Route: /operability/slo (error budget burn)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/operability/slo").status == 200, "status 200");
for (int i = 0; i < 20; ++i) f.client->post("/operability/slo/good", "", kForm);
check(contains(f.client->get("/operability/slo").body, "healthy"), "healthy without bad events");
f.client->post("/operability/slo/bad", "", kForm);
check(contains(f.client->get("/operability/slo").body, "burning"), "one bad of 21 is within budget");
f.client->post("/operability/slo/bad", "", kForm);
f.client->post("/operability/slo/bad", "", kForm);
check(contains(f.client->get("/operability/slo").body, "exhausted"), "budget exhausted");
f.client->post("/operability/slo/reset", "", kForm);
check(contains(f.client->get("/operability/slo").body, "0/100"), "side effect: window emptied");
for (int i = 0; i < 105; ++i) f.client->request(Method::Post, "/operability/slo/good", "", {{"Accept", "application/json"}});
check(contains(f.client->get("/operability/slo").body, "100/100"), "limit: window capped at 100");
check(f.client->request(Method::Put, "/operability/slo").status == 405, "405 on put");
return finish("operability/slo");
}
+20
View File
@@ -0,0 +1,20 @@
// Route: GET /metrics (Prometheus text: stats plus example metrics)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
f.services.metrics->inc("demo.hits", 3);
f.client->get("/health");
auto res = f.client->get("/metrics");
check(res.status == 200, "status 200");
check(contains(res.headers.get("Content-Type"), "text/plain; version=0.0.4"), "prometheus content type");
check(contains(res.body, "# TYPE molo_http_requests_total counter"), "type line");
check(contains(res.body, "molo_http_requests_total "), "request counter");
check(contains(res.body, "molo_example_demo_hits 3"), "example metric sanitized");
check(f.services.stats->total_requests() >= 2, "side effect: stats counted");
check(f.client->request(Method::Post, "/metrics").status == 405, "post is 405");
return finish("prom/metrics");
}
+19
View File
@@ -0,0 +1,19 @@
// Route: GET /security/admin (Bearer token, role permission check)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(contains(f.client->get("/security/roles").body, "admin:manage"), "roles page lists permissions");
auto none = f.client->get("/security/admin");
check(none.status == 401 && none.headers.get("WWW-Authenticate") == "Bearer", "no token 401");
auto junk = f.client->request(Method::Get, "/security/admin", "", {{"Authorization", "Bearer nope"}});
check(junk.status == 401, "unknown token 401");
auto viewer = f.client->request(Method::Get, "/security/admin", "", {{"Authorization", "Bearer viewer-token"}});
check(viewer.status == 403 && contains(viewer.body, "viewer"), "viewer 403");
auto admin = f.client->request(Method::Get, "/security/admin", "", {{"Authorization", "Bearer admin-token"}});
check(admin.status == 200 && contains(admin.body, "\"role\":\"admin\""), "admin 200");
check(f.client->post("/security/admin", "x").status == 405, "POST 405");
check(contains(f.client->get("/security/denials").body, "lacks admin:manage"), "side effect: denial recorded");
return finish("security/admin");
}
+22
View File
@@ -0,0 +1,22 @@
// Route: OPTIONS /security/cors (origin allowlist preflight)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(f.client->get("/security/cors").status == 200, "info page 200");
auto ok = f.client->request(Method::Options, "/security/cors", "",
{{"Origin", "https://app.example.com"}});
check(ok.status == 204, "allowed origin is 204");
check(ok.headers.get("Access-Control-Allow-Origin") == "https://app.example.com", "origin echoed");
check(ok.headers.has("Access-Control-Allow-Methods"), "methods header");
auto bad = f.client->request(Method::Options, "/security/cors", "", {{"Origin", "https://evil.example"}});
check(bad.status == 403, "unknown origin is 403");
check(!bad.headers.has("Access-Control-Allow-Origin"), "no allow header on denial");
auto none = f.client->request(Method::Options, "/security/cors");
check(none.status == 403, "missing origin is 403");
auto post = f.client->post("/security/cors", "x");
check(post.status == 405, "POST is 405");
check(contains(f.client->get("/security/denials").body, "CorsPolicy"), "side effect: denial recorded");
return finish("security/cors");
}
+30
View File
@@ -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 + "&note=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&note=hi", kForm);
check(bad.status == 403, "forged token is 403");
auto longnote = f.client->post("/security/csrf", "csrf_token=" + token + "&note=" + 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");
}
+16
View File
@@ -0,0 +1,16 @@
// Route: GET /security/denials (capped ring of refusals)
#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/denials").body, "\"total\":0"), "starts empty");
for (int i = 0; i < 120; ++i) f.client->post("/security/guard", "kind=x&value=a", kForm);
auto r = f.client->get("/security/denials");
check(r.status == 200 && contains(r.body, "\"total\":120"), "total counts all");
std::size_t n = 0, p = 0;
while ((p = r.body.find("\"guard\"", p)) != std::string::npos) { ++n; p += 7; }
check(n == 100, "ring capped at 100");
check(f.client->post("/security/denials", "x").status == 405, "POST 405");
return finish("security/denials");
}
+20
View File
@@ -0,0 +1,20 @@
// Route: /security/guard (SqlSafety and PathGuard rejection)
#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/guard").body, "<form"), "form renders");
auto ok = f.client->post("/security/guard", "kind=sql&value=ada", kForm);
check(ok.status == 200 && contains(ok.body, "safe for sql"), "safe sql value");
auto sql = f.client->post("/security/guard", "kind=sql&value=x%27+OR+1%3D1+--", kForm);
check(sql.status == 422 && contains(sql.body, "form-errors"), "sql injection inline 422");
auto path = f.client->post("/security/guard", "kind=path&value=..%2F..%2Fetc%2Fpasswd", kForm);
check(path.status == 422 && contains(path.body, "traversal"), "traversal rejected");
auto abs = f.client->post("/security/guard", "kind=path&value=%2Fetc%2Fpasswd", kForm);
check(abs.status == 422 && contains(abs.body, "absolute"), "absolute rejected");
check(f.client->post("/security/guard", "kind=x&value=a", kForm).status == 422, "bad kind 422");
check(f.client->post("/security/guard", "kind=sql&value=" + std::string(513, 'a'), kForm).status == 422, "over cap 422");
check(contains(f.client->get("/security/denials").body, "PathGuard"), "side effect: denial recorded");
return finish("security/guard");
}
+14
View File
@@ -0,0 +1,14 @@
// Route: GET /security/headers (hardening headers applied)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto r = f.client->get("/security/headers");
check(r.status == 200, "status 200");
check(r.headers.get("X-Content-Type-Options") == "nosniff", "nosniff");
check(r.headers.get("X-Frame-Options") == "DENY", "frame deny");
check(r.headers.has("Strict-Transport-Security"), "hsts");
check(contains(r.body, "Referrer-Policy"), "body lists headers");
check(f.client->post("/security/headers", "x").status == 405, "POST is 405");
return finish("security/headers");
}
+21
View File
@@ -0,0 +1,21 @@
// 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");
}
+21
View File
@@ -0,0 +1,21 @@
// Route: GET /security/rate (5 hits per 60 s per client, then 429)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
for (int i = 0; i < 5; ++i) {
auto r = f.client->request(Method::Get, "/security/rate", "", {{"X-Client-Id", "a"}});
check(r.status == 200, "hit " + std::to_string(i + 1) + " allowed");
if (i == 4) check(contains(r.body, "\"remaining\":0"), "remaining reaches 0");
}
auto limited = f.client->request(Method::Get, "/security/rate", "", {{"X-Client-Id", "a"}});
check(limited.status == 429, "6th hit is 429");
int retry = std::atoi(limited.headers.get("Retry-After").c_str());
check(retry >= 1 && retry <= 61, "Retry-After within window");
auto other = f.client->request(Method::Get, "/security/rate", "", {{"X-Client-Id", "b"}});
check(other.status == 200, "other client unaffected");
check(f.client->post("/security/rate", "x").status == 405, "POST is 405");
check(contains(f.client->get("/security/denials").body, "RateLimiter"), "side effect: denial recorded");
return finish("security/rate");
}
+15
View File
@@ -0,0 +1,15 @@
// Route: GET /security/secrets (values are always masked)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto list = f.client->get("/security/secrets");
check(list.status == 200 && contains(list.body, "DB_PASSWORD"), "names listed");
check(!contains(list.body, "demo-db-password"), "no values in list");
auto one = f.client->get("/security/secrets?name=API_KEY");
check(one.status == 200 && contains(one.body, "de*"), "masked value");
check(!contains(one.body, "demo-api-key-abcdef"), "full value never returned");
check(f.client->get("/security/secrets?name=NOPE").status == 404, "unknown 404");
check(f.client->post("/security/secrets", "x").status == 405, "POST 405");
return finish("security/secrets");
}
+24
View File
@@ -0,0 +1,24 @@
// Route: /security/upload (extension allowlist, size cap, magic bytes)
#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/upload").body, "<form"), "form renders");
auto ok = f.client->post("/security/upload", "filename=a.pdf&content_hex=255044462d31", kForm);
check(ok.status == 200 && contains(ok.body, "Accepted a.pdf"), "valid pdf accepted");
auto fake = f.client->post("/security/upload", "filename=a.png&content_hex=255044462d31", kForm);
check(fake.status == 422 && contains(fake.body, "magic bytes"), "magic mismatch inline 422");
auto ext = f.client->post("/security/upload", "filename=a.exe&content_hex=4d5a", kForm);
check(ext.status == 422 && contains(ext.body, "extension not allowed"), "bad extension");
auto path = f.client->post("/security/upload", "filename=..%2Fa.txt&content_hex=6869", kForm);
check(path.status == 422, "path in name rejected");
auto hex = f.client->post("/security/upload", "filename=a.txt&content_hex=zz", kForm);
check(hex.status == 422 && contains(hex.body, "hex digits"), "bad hex");
auto big = f.client->post("/security/upload", "filename=a.txt&content_hex=" + std::string(2050, '4') + std::string(2050, '1'), kForm);
check(big.status == 422 || big.status == 413, "oversize rejected");
auto bigok = f.client->post("/security/upload", "filename=a.txt&content_hex=" + std::string(2050, '6'), kForm);
check(bigok.status == 413, "over 1024 bytes is 413");
check(contains(f.client->get("/security/denials").body, "UploadValidator"), "side effect: denial recorded");
return finish("security/upload");
}
+31
View File
@@ -0,0 +1,31 @@
// Route: /supplychain (SBOM, pins, advisories, attestation gate)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
auto page = f.client->get("/supplychain");
check(page.status == 200 && contains(page.body, "chartjs"), "sbom listed");
check(contains(page.body, ">PASS<"), "gate passes initially");
auto sbom = f.client->get("/supplychain/sbom.json");
check(sbom.status == 200 && contains(sbom.body, "CycloneDX"), "cyclonedx json");
auto adv = f.client->post("/supplychain/advisory", "", kForm);
check(contains(adv.body, ">FAIL<"), "advisory on a used version fails the gate");
f.client->post("/supplychain/reset", "", kForm);
check(contains(f.client->get("/supplychain").body, ">PASS<"), "reset restores the gate");
f.client->post("/supplychain/tamper", "", kForm);
check(contains(f.client->get("/supplychain").body, ">FAIL<"), "tampered component fails pins and attestation");
auto bad = f.client->post("/supplychain/verify", "digest=abc", kForm);
check(bad.status == 422 && contains(bad.body, "at least 16"), "422 short digest");
auto wrong = f.client->post("/supplychain/verify", "digest=0000000000000000", kForm);
check(contains(wrong.body, "attestation FAILED"), "wrong digest fails verification");
check(contains(wrong.body, "failed"), "side effect: last_verify recorded");
f.client->post("/supplychain/reset", "", kForm);
auto defaults = f.client->get("/supplychain");
check(contains(defaults.body, "value=\""), "verify form prefilled with the attested digest");
return finish("supplychain/index");
}
+17
View File
@@ -0,0 +1,17 @@
// Route: GET/POST /tenancy/config (config overlay)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
Method P = Method::Post;
check(contains(f.client->get("/tenancy/config").body, "\"theme\":\"light\""), "base value");
check(f.client->request(P, "/tenancy/config", "key=theme&value=dark", {{"X-Tenant-ID", "acme"}}).status == 200, "set overlay");
check(contains(f.client->request(Method::Get, "/tenancy/config", "", {{"X-Tenant-ID", "acme"}}).body, "\"theme\":\"dark\""), "overlay wins");
check(contains(f.client->request(Method::Get, "/tenancy/config", "", {{"X-Tenant-ID", "globex"}}).body, "\"theme\":\"light\""), "side effect: other tenant keeps base");
check(f.client->request(P, "/tenancy/config", "key=bogus&value=x", {{"X-Tenant-ID", "acme"}}).status == 422, "unknown key");
check(f.client->request(P, "/tenancy/config", "key=theme&value=", {{"X-Tenant-ID", "acme"}}).status == 422, "empty value");
return finish("tenancy/config");
}
+22
View File
@@ -0,0 +1,22 @@
// Route: GET/POST /tenancy/data (tenant-scoped data isolation, cap)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto add = f.client->request(Method::Post, "/tenancy/data", "item=alpha", {{"X-Tenant-ID", "acme"}});
check(add.status == 201, "add");
auto acme = f.client->request(Method::Get, "/tenancy/data", "", {{"X-Tenant-ID", "acme"}});
check(contains(acme.body, "alpha"), "visible to owner");
auto globex = f.client->request(Method::Get, "/tenancy/data", "", {{"X-Tenant-ID", "globex"}});
check(!contains(globex.body, "alpha"), "side effect: isolated from other tenant");
check(f.client->request(Method::Post, "/tenancy/data", "item=", {{"X-Tenant-ID", "acme"}}).status == 422, "empty item 422");
int last = 0;
for (int i = 0; i < 55; ++i)
last = f.client->request(Method::Post, "/tenancy/data", "item=x", {{"X-Tenant-ID", "acme"}}).status;
check(last == 429, "per-tenant cap 429");
check(f.client->get("/tenancy/data").status == 200, "default tenant GET");
return finish("tenancy/data");
}
+18
View File
@@ -0,0 +1,18 @@
// Route: GET/POST /tenancy/flags (per-tenant overrides)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
Method P = Method::Post;
auto def = f.client->request(Method::Get, "/tenancy/flags", "", {{"X-Tenant-ID", "acme"}});
check(def.status == 200 && contains(def.body, "\"beta-ui\":false"), "default off");
check(f.client->request(P, "/tenancy/flags", "flag=beta-ui&enabled=true", {{"X-Tenant-ID", "acme"}}).status == 200, "set");
check(contains(f.client->request(Method::Get, "/tenancy/flags", "", {{"X-Tenant-ID", "acme"}}).body, "\"beta-ui\":true"), "override applied");
check(contains(f.client->request(Method::Get, "/tenancy/flags", "", {{"X-Tenant-ID", "globex"}}).body, "\"beta-ui\":false"), "side effect: other tenant unchanged");
check(f.client->request(P, "/tenancy/flags", "flag=nope&enabled=true", {{"X-Tenant-ID", "acme"}}).status == 422, "unknown flag");
check(f.client->request(P, "/tenancy/flags", "flag=beta-ui&enabled=maybe", {{"X-Tenant-ID", "acme"}}).status == 422, "bad value");
return finish("tenancy/flags");
}
+18
View File
@@ -0,0 +1,18 @@
// Route: GET /tenancy/metrics (per-tenant counters)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
check(f.client->get("/tenancy/metrics").status == 200, "empty ok");
f.client->request(Method::Get, "/tenancy/data", "", {{"X-Tenant-ID", "acme"}});
f.client->request(Method::Get, "/tenancy/data", "", {{"X-Tenant-ID", "acme"}});
f.client->request(Method::Get, "/tenancy/data", "", {{"X-Tenant-ID", "globex"}});
auto m = f.client->get("/tenancy/metrics");
check(contains(m.body, "\"acme\":{\"data.list\":2}"), "acme counted twice");
check(contains(m.body, "\"globex\":{\"data.list\":1}"), "globex counted once");
check(f.client->post("/tenancy/metrics").status == 405, "405 on post");
return finish("tenancy/metrics");
}
+22
View File
@@ -0,0 +1,22 @@
// Route: GET/POST /tenancy/provision (HTML form, inline errors)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto page = f.client->get("/tenancy/provision");
check(page.status == 200 && contains(page.headers.get("Content-Type"), "text/html"), "form page");
auto bad = f.client->post("/tenancy/provision", "id=Bad&name=&plan=gold", "application/x-www-form-urlencoded");
check(bad.status == 422 && contains(bad.headers.get("Content-Type"), "text/html"), "html 422");
check(contains(bad.body, "field-error") && !contains(bad.body, "\"failures\""), "inline errors, no raw json");
auto ok = f.client->post("/tenancy/provision", "id=initech&name=Initech&plan=pro", "application/x-www-form-urlencoded");
check(ok.status == 201 && contains(ok.body, "provisioned"), "created");
check(f.client->get("/tenancy/t/initech/whoami").status == 200, "side effect: tenant resolves");
auto dup = f.client->post("/tenancy/provision", "id=initech&name=X&plan=free", "application/x-www-form-urlencoded");
check(dup.status == 422 && contains(dup.body, "exists"), "duplicate rejected");
auto js = f.client->request(Method::Post, "/tenancy/provision", "{\"id\":\"b\"}", {{"Content-Type", "application/json"}});
check(js.status == 422 && contains(js.headers.get("Content-Type"), "application/json"), "json client gets json");
return finish("tenancy/provision");
}
+21
View File
@@ -0,0 +1,21 @@
// Route: GET/POST /tenancy/quota (plan quotas)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
Method P = Method::Post;
check(f.client->get("/tenancy/quota").status == 200, "get");
int s = 0;
for (int i = 0; i < 3; ++i) s = f.client->request(P, "/tenancy/quota", "", {{"X-Tenant-ID", "globex"}}).status;
check(s == 200, "free plan allows 3");
auto over = f.client->request(P, "/tenancy/quota", "", {{"X-Tenant-ID", "globex"}});
check(over.status == 429 && over.headers.get("Retry-After") == "60", "4th is 429 with Retry-After");
auto pro = f.client->request(P, "/tenancy/quota", "", {{"X-Tenant-ID", "acme"}});
check(pro.status == 200 && contains(pro.body, "\"limit\":10"), "pro has bigger limit");
check(contains(f.client->get("/tenancy/metrics").body, "quota.denied"), "side effect: denied metric");
check(f.client->request(P, "/tenancy/quota", "", {{"X-Tenant-ID", "ghost"}}).status == 404, "unknown tenant");
return finish("tenancy/quota");
}
+24
View File
@@ -0,0 +1,24 @@
// Route: GET /tenancy/resolve (tenant from header, subdomain, default)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto def = f.client->get("/tenancy/resolve");
check(def.status == 200 && contains(def.body, "\"source\":\"default\""), "default tenant");
check(contains(def.headers.get("Content-Type"), "application/json"), "json type");
auto hdr = f.client->request(Method::Get, "/tenancy/resolve", "", {{"X-Tenant-ID", "acme"}});
check(contains(hdr.body, "\"tenant\":\"acme\"") && contains(hdr.body, "header"), "header wins");
auto sub = f.client->request(Method::Get, "/tenancy/resolve", "", {{"Host", "globex.example.com"}});
check(contains(sub.body, "subdomain") && contains(sub.body, "globex"), "subdomain");
auto bad = f.client->request(Method::Get, "/tenancy/resolve", "", {{"X-Tenant-ID", "Bad_ID"}});
check(bad.status == 400 && contains(bad.headers.get("Content-Type"), "problem+json"), "malformed id is 400 problem");
auto none = f.client->request(Method::Get, "/tenancy/resolve", "", {{"X-Tenant-ID", "nobody"}});
check(none.status == 404, "unknown tenant 404");
check(f.client->post("/tenancy/resolve").status == 405, "405 on post");
auto m = f.client->get("/tenancy/metrics");
check(contains(m.body, "\"resolve\""), "side effect: metric counted");
return finish("tenancy/resolve");
}
@@ -0,0 +1,16 @@
// Route: GET /tenancy/t/{tenant}/whoami (path resolution)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto ok = f.client->get("/tenancy/t/acme/whoami");
check(ok.status == 200 && contains(ok.body, "\"source\":\"path\"") && contains(ok.body, "pro"), "path tenant");
check(f.client->get("/tenancy/t/x/whoami").status == 400, "too short id");
check(f.client->get("/tenancy/t/ghost/whoami").status == 404, "unknown 404");
auto h = f.client->request(Method::Get, "/tenancy/t/acme/whoami", "", {{"X-Tenant-ID", "globex"}});
check(contains(h.body, "globex"), "header beats path");
return finish("tenancy/t/tenant/whoami");
}
+17
View File
@@ -0,0 +1,17 @@
// Route: GET /v1/items (deprecated version: Deprecation, Sunset, Link)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto r = f.client->get("/v1/items");
check(r.status == 200 && contains(r.body, "\"v1\""), "ok");
check(r.headers.get("Deprecation") == "true", "Deprecation header");
check(contains(r.headers.get("Sunset"), "GMT"), "Sunset header");
check(contains(r.headers.get("Link"), "successor-version") && contains(r.headers.get("Link"), "/v2/items"), "Link successor");
check(f.client->post("/v1/items").status == 405, "405 on post");
check(f.client->get("/v1/nothing").status == 404, "404");
return finish("v1/items");
}
+16
View File
@@ -0,0 +1,16 @@
// Route: GET /v2/items (current version: no deprecation headers)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto r = f.client->get("/v2/items");
check(r.status == 200 && contains(r.body, "\"v2\""), "ok");
check(r.headers.get("X-API-Version") == "v2", "version header");
check(!r.headers.has("Deprecation") && !r.headers.has("Sunset"), "no deprecation");
check(f.client->post("/v2/items").status == 405, "405 on post");
check(f.client->get("/v3/items").status == 404, "404 unknown version");
return finish("v2/items");
}