From dfff415ab83a083f0db5ea4f772154b8d7b68c45 Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 10 Nov 2026 07:36:36 +0000 Subject: [PATCH] Core Rule Set tests: inspect bodiless recorded requests once (closes #281) wantRecordedRequestsPass inspects a recorded request with no body only at the defaults, as the WordPress test already does. With no body to read, the second inspection ran the same rules on the same request. Requests with a body are still inspected both ways. This cuts the package's CPU time under -race by about a fifth. Model: opus-5-5 --- internal/coreruleset/coreruleset_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/coreruleset/coreruleset_test.go b/internal/coreruleset/coreruleset_test.go index 0d85082..b7f1524 100644 --- a/internal/coreruleset/coreruleset_test.go +++ b/internal/coreruleset/coreruleset_test.go @@ -620,7 +620,9 @@ var hardValues = []string{"python3", "powershell", "ls%20-la", ".htaccess"} // wantRecordedRequestsPass checks that none of the recorded ordinary // requests in the file name in testdata is refused, at the defaults and -// while bodies are read. Each request runs as its own parallel subtest. +// while bodies are read. A request with no body is checked only at the +// defaults: reading bodies changes nothing for it. Each request runs as its +// own parallel subtest. func wantRecordedRequestsPass(t *testing.T, name string) { t.Helper() @@ -639,6 +641,10 @@ func wantRecordedRequestsPass(t *testing.T, name string) { t.Errorf("%s %s refused: %+v", r.method, r.target, got) } + if recorded.Body == "" { + return + } + got, _ = inspectBody(t, bodies, r, recorded.Body) if got.Score >= threshold { t.Errorf("%s %s %.200q refused while bodies are read: %+v",