20 lines
1015 B
C++
20 lines
1015 B
C++
// 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");
|
||
|
|
}
|