From b7e7557047efb01cd37da7c6ab8d053686d2ea68 Mon Sep 17 00:00:00 2001 From: clawbot Date: Thu, 19 Nov 2026 17:07:16 +0000 Subject: [PATCH] waf: test the request_bytes of a ban added through the endpoint No test read the request_bytes of an own endpoint's log line, so removing the counting in logOwnEndpoint went unnoticed. The test checks that a ban to add is logged with its body's bytes, and that the health endpoint, which reads no body, logs 0. Model: opus-5-5 --- internal/waf/admin_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/internal/waf/admin_test.go b/internal/waf/admin_test.go index be342b1..24386f1 100644 --- a/internal/waf/admin_test.go +++ b/internal/waf/admin_test.go @@ -333,6 +333,39 @@ func TestBanToAddThatCannotBeReadIsRefused(t *testing.T) { } } +func TestBanToAddIsLoggedWithTheBytesOfItsBody(t *testing.T) { + t.Parallel() + + s, _, _ := startWithClock( + t, + "", + map[string]string{adminToken: adminSecret}, + ) + + s.admin(http.MethodPost, waf.BansPath, banOtherClient, http.StatusOK) + + line := s.out.endedLines(t, s.sent)[s.sent-1] + if line.RequestBytes != int64(len(banOtherClient)) { + t.Errorf( + "the ban to add was logged with request_bytes %d, want %d", + line.RequestBytes, + len(banOtherClient), + ) + } + + // The health endpoint reads none of a body sent to it. + s.ownEndpointRequest("", http.MethodGet, waf.HealthPath, "ok", + http.StatusOK) + + line = s.out.endedLines(t, s.sent)[s.sent-1] + if line.RequestBytes != 0 { + t.Errorf( + "the health request was logged with request_bytes %d, want 0", + line.RequestBytes, + ) + } +} + func TestClientEndpointShowsTheClientAndItsBans(t *testing.T) { t.Parallel()