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()