feat: implement MoloApp plans 01-15 with integration

Full C++23 framework tree: runtime, observability, security,
data, app, realtime, supervisor, clients, CLI, example plus
enterprise tenancy, audit, operability, governance,
supplychain. Postgres via docker compose for tests.
This commit is contained in:
2026-10-23 18:20:04 +02:00
parent 54068f1953
commit 3c4334cec9
1068 changed files with 100899 additions and 2 deletions
+47
View File
@@ -0,0 +1,47 @@
// V5: mapped exceptions render exact JSON and HTML shapes; 500 hides
// internals; request_id is present in both.
#include "../_testlib.h"
using namespace molo::app;
int main() {
app::Application app;
app.router().get("/bad", views::adapt([](http_msg::Request&) -> http_msg::Response {
throw errors::BadRequest("custom bad");
}));
app.router().get("/deny", views::adapt([](http_msg::Request&) -> http_msg::Response {
throw errors::Forbidden();
}));
app.router().get("/leak", views::adapt([](http_msg::Request&) -> http_msg::Response {
throw std::runtime_error("secret db password hunter2");
}));
app.startup();
http_msg::Response j = get(app, "/bad");
CHECK_EQ_INT(j.status(), 400, "BadRequest maps to 400");
CHECK_EQ_STR(j.content_type(), "application/json", "API error is JSON");
validate::Value parsed = validate::parse_json(j.body());
const auto* root = std::get_if<validate::Object>(&parsed.storage());
const auto* err = std::get_if<validate::Object>(&root->at("error").storage());
CHECK_EQ_STR(err->at("code").as_text(), "bad_request", "error code field");
CHECK_EQ_STR(err->at("message").as_text(), "custom bad", "error message field");
CHECK(!err->at("request_id").as_text().empty(), "JSON error carries request_id");
http_msg::Response page = get(app, "/deny", {{"accept", "text/html"}});
CHECK_EQ_INT(page.status(), 403, "Forbidden maps to 403");
CHECK(page.content_type().find("text/html") != std::string::npos, "browser error is HTML");
CHECK(page.body().find("viewport") != std::string::npos, "error page is responsive");
CHECK(page.body().find("forbidden") != std::string::npos, "error page shows code");
CHECK(page.body().find("req-") != std::string::npos, "HTML error carries request_id");
http_msg::Response leak = get(app, "/leak");
CHECK_EQ_INT(leak.status(), 500, "unknown exception maps to 500");
CHECK(leak.body().find("hunter2") == std::string::npos, "500 hides internals");
CHECK(leak.body().find("internal server error") != std::string::npos,
"500 shows fixed message");
http_msg::Response leak_html = get(app, "/leak", {{"accept", "text/html"}});
CHECK_EQ_INT(leak_html.status(), 500, "HTML unknown exception maps to 500");
CHECK(leak_html.body().find("hunter2") == std::string::npos, "HTML 500 hides internals");
return test_report("errors/render");
}