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
+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");
}