check / check (push) Failing after 3m37s
routes.go lists every own endpoint. One middleware checks a token and another writes the log line. answerOwnEndpoint, answerAdmin and endpoint() are gone; the handlers return http.HandlerFunc. The router matches the decoded path, as the old code did. A test checks the request_bytes of an own endpoint's log line. Model: opus-5-5
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package waf_test
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
"sneak.berlin/go/smallwebwaf/internal/wafprotocol"
|
|
)
|
|
|
|
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,
|
|
wafprotocol.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,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHealthEndpointIsFoundAtItsPathPercentEncoded(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// %68 is h. An endpoint is found by the decoded path.
|
|
s, _, _ := startWithClock(t, "", nil)
|
|
|
|
got := s.ownEndpointRequest("", http.MethodGet, "/_sww/%68ealthz", "",
|
|
http.StatusOK)
|
|
wantBody(t, got, "ok\n")
|
|
}
|