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