script/fmt now runs golines -m 77 after gofmt, repeating golines until it changes nothing, since one pass can leave a line the next splits. script/fmt-check fails when either would change a file. script/bootstrap installs golines v0.13.0 with go install, pinned to its commit, and checks the installed version with go version -m. The tree is reformatted. The longer lines this makes are fixed by hand: nolint directives moved onto their own line above the statement, one string split, and 20 functions over funlen's 80 lines shortened or split, RunWAF and limitPercentages among them. Model: opus-5-5
This commit is contained in:
1 parent
63e58e326b
commit
7f8a59de04
118 files changed
+9447
-2670
No files matched your search
@@ -32,8 +32,13 @@ func TestMetricsAreOffWhileTheTokenIsUnset(t *testing.T) {
|
||||
|
||||
// An empty token does not match the unset one either.
|
||||
for _, authorization := range []string{bearer, "Bearer ", ""} {
|
||||
s.ownEndpointRequest(authorization, http.MethodGet, waf.MetricsPath, "",
|
||||
http.StatusNotFound)
|
||||
s.ownEndpointRequest(
|
||||
authorization,
|
||||
http.MethodGet,
|
||||
waf.MetricsPath,
|
||||
"",
|
||||
http.StatusNotFound,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +65,13 @@ func TestMetricsNeedTheTokenAndOtherPathsAreNotFound(t *testing.T) {
|
||||
{http.MethodGet, "/_sww/bans", bearer, http.StatusNotFound},
|
||||
{http.MethodPost, waf.HealthPath, "", http.StatusNotFound},
|
||||
} {
|
||||
got := s.ownEndpointRequest(tc.authorization, tc.method, tc.path, "", tc.status)
|
||||
got := s.ownEndpointRequest(
|
||||
tc.authorization,
|
||||
tc.method,
|
||||
tc.path,
|
||||
"",
|
||||
tc.status,
|
||||
)
|
||||
|
||||
if tc.status == http.StatusUnauthorized &&
|
||||
got.header.Get("WWW-Authenticate") != "Bearer" {
|
||||
@@ -69,7 +80,10 @@ func TestMetricsNeedTheTokenAndOtherPathsAreNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.status == http.StatusOK &&
|
||||
!strings.Contains(string(got.body), "# TYPE sww_requests_total counter") {
|
||||
!strings.Contains(
|
||||
string(got.body),
|
||||
"# TYPE sww_requests_total counter",
|
||||
) {
|
||||
t.Errorf("the metrics are\n%s", got.body)
|
||||
}
|
||||
}
|
||||
@@ -85,7 +99,10 @@ func TestMetricsCountTheTraffic(t *testing.T) {
|
||||
addr, out, server := startProxyWithClock(t, app.URL, "", time.Now,
|
||||
map[string]string{metricsToken: token})
|
||||
|
||||
got := do(t, newRequest(t, http.MethodPost, addr, "/", strings.NewReader("abc")))
|
||||
got := do(
|
||||
t,
|
||||
newRequest(t, http.MethodPost, addr, "/", strings.NewReader("abc")),
|
||||
)
|
||||
wantStatus(t, got, http.StatusOK)
|
||||
wantStatus(t, get(t, addr, "/_sww/nothing"), http.StatusNotFound)
|
||||
out.endedLines(t, 2)
|
||||
@@ -132,12 +149,26 @@ func TestMetricsCountLimitsAndBans(t *testing.T) {
|
||||
s.get(client, 0, requestlog.ActionClientIsRateLimited)
|
||||
|
||||
metrics := s.scrape()
|
||||
wantMetric(t, metrics,
|
||||
`sww_requests_total{action="client_denied",instance="app",status_class="none"}`, 1)
|
||||
wantMetric(
|
||||
t,
|
||||
metrics,
|
||||
`sww_requests_total{action="client_denied",instance="app",status_class="none"}`,
|
||||
1,
|
||||
)
|
||||
wantMetric(t, metrics, `sww_rate_limit_hits_total{instance="app",`+
|
||||
`kind="requests",window="minute"}`, 1)
|
||||
wantMetric(t, metrics, `sww_offences_total{instance="app",kind="limit"}`, 1)
|
||||
wantMetric(t, metrics, `sww_bans_made_total{cause="limit",instance="app"}`, 1)
|
||||
wantMetric(
|
||||
t,
|
||||
metrics,
|
||||
`sww_offences_total{instance="app",kind="limit"}`,
|
||||
1,
|
||||
)
|
||||
wantMetric(
|
||||
t,
|
||||
metrics,
|
||||
`sww_bans_made_total{cause="limit",instance="app"}`,
|
||||
1,
|
||||
)
|
||||
wantMetric(t, metrics, `sww_active_bans{instance="app"}`, 1)
|
||||
wantMetric(t, metrics, `sww_permanent_bans{instance="app"}`, 0)
|
||||
|
||||
@@ -152,8 +183,18 @@ func TestMetricsCountLimitsAndBans(t *testing.T) {
|
||||
metrics = s.scrape()
|
||||
wantMetric(t, metrics, `sww_rate_limit_hits_total{instance="app",`+
|
||||
`kind="requests",window="minute"}`, 2)
|
||||
wantMetric(t, metrics, `sww_offences_total{instance="app",kind="limit"}`, 2)
|
||||
wantMetric(t, metrics, `sww_bans_made_total{cause="limit",instance="app"}`, 2)
|
||||
wantMetric(
|
||||
t,
|
||||
metrics,
|
||||
`sww_offences_total{instance="app",kind="limit"}`,
|
||||
2,
|
||||
)
|
||||
wantMetric(
|
||||
t,
|
||||
metrics,
|
||||
`sww_bans_made_total{cause="limit",instance="app"}`,
|
||||
2,
|
||||
)
|
||||
wantMetric(t, metrics, `sww_active_bans{instance="app"}`, 1)
|
||||
wantMetric(t, metrics, `sww_permanent_bans{instance="app"}`, 1)
|
||||
// denied and client.
|
||||
@@ -201,12 +242,14 @@ func TestMetricsByCountryKeepTheBusiestAndCountTheRestAsOther(t *testing.T) {
|
||||
allowedCountries: "de,fr",
|
||||
}
|
||||
geojsURL, _ := startGeoJS(t)
|
||||
addr, out, server := startProxyWithClock(t, app.URL, geojsURL, time.Now, env)
|
||||
addr, out, server := startProxyWithClock(t, app.URL, geojsURL,
|
||||
time.Now, env)
|
||||
|
||||
// The answers are kept before the requests, so that none waits for
|
||||
// GeoJS.
|
||||
server.GeoJS.Load([]lookup.Answer{
|
||||
keptAnswer(fromKP, "KP"), keptAnswer(fromDE, "DE"), keptAnswer(fromFR, "FR"),
|
||||
keptAnswer(fromKP, "KP"), keptAnswer(fromDE, "DE"),
|
||||
keptAnswer(fromFR, "FR"),
|
||||
})
|
||||
|
||||
lines := 0
|
||||
@@ -214,7 +257,8 @@ func TestMetricsByCountryKeepTheBusiestAndCountTheRestAsOther(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
for range times {
|
||||
req := newRequest(t, http.MethodPost, addr, "/", strings.NewReader("abc"))
|
||||
body := strings.NewReader("abc")
|
||||
req := newRequest(t, http.MethodPost, addr, "/", body)
|
||||
req.Header.Set(forwardedFor, from)
|
||||
wantStatus(t, do(t, req), status)
|
||||
|
||||
@@ -271,7 +315,9 @@ func TestMetricsByCountryKeepTheBusiestAndCountTheRestAsOther(t *testing.T) {
|
||||
`sww_country_request_bytes_total{country="DE",instance="app"}`)
|
||||
}
|
||||
|
||||
func TestMetricsByASNumberKeepTheBusiestAndCountTheRestAsOther(t *testing.T) {
|
||||
func TestMetricsByASNumberKeepTheBusiestAndCountTheRestAsOther(
|
||||
t *testing.T,
|
||||
) {
|
||||
t.Parallel()
|
||||
|
||||
geojsURL, _ := startGeoJS(t)
|
||||
@@ -347,7 +393,12 @@ func TestMetricsCountGeoJSRequestsAndFailures(t *testing.T) {
|
||||
|
||||
wantMetric(t, metrics, `sww_geojs_requests_total{instance="app"}`, 1)
|
||||
wantMetric(t, metrics, `sww_geojs_failures_total{instance="app"}`, 1)
|
||||
wantMetric(t, metrics, `sww_requests_without_geojs_answer_total{instance="app"}`, 1)
|
||||
wantMetric(
|
||||
t,
|
||||
metrics,
|
||||
`sww_requests_without_geojs_answer_total{instance="app"}`,
|
||||
1,
|
||||
)
|
||||
}
|
||||
|
||||
// keptAnswer returns GeoJS's answer that the client at addr is in
|
||||
@@ -381,8 +432,10 @@ func scrape(t *testing.T, addr string) string {
|
||||
func (s *sender) scrape() string {
|
||||
s.t.Helper()
|
||||
|
||||
return string(s.ownEndpointRequest(bearer, http.MethodGet, waf.MetricsPath,
|
||||
"", http.StatusOK).body)
|
||||
return string(
|
||||
s.ownEndpointRequest(bearer, http.MethodGet, waf.MetricsPath,
|
||||
"", http.StatusOK).body,
|
||||
)
|
||||
}
|
||||
|
||||
// metric returns the value of series in metrics, which are in the
|
||||
@@ -394,7 +447,10 @@ func metric(t *testing.T, metrics, series string) float64 {
|
||||
t.Helper()
|
||||
|
||||
for line := range strings.Lines(metrics) {
|
||||
value, found := strings.CutPrefix(strings.TrimSuffix(line, "\n"), series+" ")
|
||||
value, found := strings.CutPrefix(
|
||||
strings.TrimSuffix(line, "\n"),
|
||||
series+" ",
|
||||
)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user