check / check (push) Failing after 3m22s
The first half of the naming audit: names now say what they are. `internal/waf` is `internal/coreruleset`. Log fields, the action `blocked_by_core_rule_set`, the metric and the alert event say Core Rule Set. Timings end `_ms`. Percentages say of what, as `rate_limit_percent` and `bytes_limit_percent`. Setting names follow in #234. Judgement call: `blocked_by_core_rule_set`, not the audit's `core_rule_set_blocked`, to match `blocked_by_block_rule`. Trips a reader: an existing state file holding `waf_blocked` or the anomaly scope `watch` stops the start and must be removed. `SWW_ALERT_EVENTS` listing `waf_block` must list `core_rule_set_match`. Model: opus-5-5
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package discriminator_test
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/discriminator"
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
func TestHealthEndpointCountsTowardNoLimit(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// With a limit of one request a minute, any request counted before
|
|
// the last one would have it refused.
|
|
s, _, _ := startWithClock(t, "", map[string]string{rateLimitPerMinute: "1"})
|
|
|
|
const (
|
|
healthChecks = 3
|
|
contentType = "text/plain; charset=utf-8"
|
|
)
|
|
|
|
for range healthChecks {
|
|
got := s.ownEndpointRequest("", http.MethodGet, discriminator.HealthPath, "",
|
|
http.StatusOK)
|
|
|
|
if string(got.body) != "ok\n" || got.header.Get("Content-Type") != contentType {
|
|
t.Errorf("health endpoint answered %q with Content-Type %q, want ok "+
|
|
"with %q", got.body, got.header.Get("Content-Type"), contentType)
|
|
}
|
|
}
|
|
|
|
s.get(client, http.StatusOK, requestlog.ActionForward)
|
|
|
|
for _, line := range s.out.endedLines(t, healthChecks)[:healthChecks] {
|
|
if line.ResponseContentType != contentType {
|
|
t.Errorf("health check's log line has response_content_type %q, "+
|
|
"want %q", line.ResponseContentType, contentType)
|
|
}
|
|
}
|
|
}
|