Compare commits

..
Author SHA1 Message Date
sneak ac46289c62 waf: Server exports no parts (closes #436)
check / check (push) Waiting to run
waf.Server held its parts as public fields only for the tests to read.
The tests now keep the Params the server was built from in a test-only
wafAndParts, which embeds both, so every assertion reads as before.
newWAFWith takes a change to the Params instead of a build function, so
the Params kept are the ones the server was built from.

Model: opus-5-5
2026-11-19 16:40:01 +00:00
18 changed files with 91 additions and 122 deletions

No files matched your search

+7 -16
View File
@@ -2,7 +2,6 @@ package rproxy
import (
"bufio"
"context"
"errors"
"io"
"net"
@@ -23,9 +22,7 @@ type requestBody struct {
// body is the visitor's body, ending in an *http.MaxBytesError past
// SWW_RPROXY_MAX_REQUEST_SIZE.
body io.ReadCloser
// refuse refuses the request with a status, as the request's own refuse
// does.
refuse func(status int)
rq *request
// held is the part read before the request goes to the app, which Read gives
// first.
held []byte
@@ -71,7 +68,7 @@ func (b *requestBody) Read(p []byte) (int, error) {
case errors.Is(err, io.EOF):
b.received.Store(true)
case errors.As(err, &tooLarge):
b.refuse(http.StatusRequestEntityTooLarge)
b.rq.refuse(http.StatusRequestEntityTooLarge)
}
return n, err
@@ -89,13 +86,7 @@ type responseBody struct {
// body is the app's body, ending in an *http.MaxBytesError past
// SWW_RPROXY_MAX_RESPONSE_SIZE.
body io.ReadCloser
// refuse refuses the request with a status, as the request's own refuse
// does.
refuse func(status int)
// responseReceived is called once the app's whole answer has arrived.
responseReceived func()
// ctx is the visitor's request's context.
ctx context.Context //nolint:containedctx // the body ends with the request
rq *request
}
// Read reads from the app's body.
@@ -109,15 +100,15 @@ func (b *responseBody) Read(p []byte) (int, error) {
switch {
case errors.Is(err, io.EOF):
b.responseReceived()
b.rq.responseReceived()
case errors.As(err, &tooLarge):
b.refuse(http.StatusBadGateway)
b.rq.refuse(http.StatusBadGateway)
return n, errResponseTooLarge
case b.ctx.Err() == nil:
case b.rq.in.Context().Err() == nil:
// The answer broke off, not because the visitor went away. If a time
// limit cut it, that refusal came first and is the one kept.
b.refuse(http.StatusBadGateway)
b.rq.refuse(http.StatusBadGateway)
}
return n, err
+3 -8
View File
@@ -126,8 +126,8 @@ func (h *handler) newRequest(
if r.Body != http.NoBody {
rq.body = &requestBody{
body: limitBody(r.Body, h.config.MaxRequestSize),
refuse: rq.refuse,
body: limitBody(r.Body, h.config.MaxRequestSize),
rq: rq,
}
}
@@ -294,12 +294,7 @@ func (rq *request) modifyResponse(res *http.Response) error {
// the request, and SWW_RPROXY_MAX_RESPONSE_TIME_MS starts.
rq.startResponseTimer(requestEnd)
res.Body = &responseBody{
body: limitBody(res.Body, maxBytes),
refuse: rq.refuse,
responseReceived: rq.responseReceived,
ctx: rq.in.Context(),
}
res.Body = &responseBody{body: limitBody(res.Body, maxBytes), rq: rq}
rq.out.afterStatus = rq.setResponseDeadline
return nil
+2 -2
View File
@@ -54,7 +54,7 @@ func TestClientsOnTheAbuseIPDBBlacklistAreBannedForTheBanDays(t *testing.T) {
})
// Two clients in one netblock make one ban, with the higher score.
server.BanAbuseIPDBBlacklist([]reputation.BlacklistEntry{
server.banAbuseIPDBBlacklist([]reputation.BlacklistEntry{
{Addr: netip.MustParseAddr(client), Score: 95},
{Addr: netip.MustParseAddr(otherClient), Score: 100},
{Addr: netip.MustParseAddr("2001:db8:5::1"), Score: 90},
@@ -88,7 +88,7 @@ func TestAbuseIPDBBlacklistMakesNoBanInObserveMode(t *testing.T) {
map[string]string{mode: "observe"},
)
server.BanAbuseIPDBBlacklist([]reputation.BlacklistEntry{
server.banAbuseIPDBBlacklist([]reputation.BlacklistEntry{
{Addr: netip.MustParseAddr(client), Score: 100},
})
+2 -3
View File
@@ -11,7 +11,6 @@ import (
"sneak.berlin/go/smallwebwaf/internal/alerts"
"sneak.berlin/go/smallwebwaf/internal/bans"
"sneak.berlin/go/smallwebwaf/internal/requestlog"
"sneak.berlin/go/smallwebwaf/internal/waf"
)
const (
@@ -252,7 +251,7 @@ func TestObserveModeWorksOutABanOnlyWhenItsAlertWouldBeSent(t *testing.T) {
// never sent them, and returns the queue they wait in as well.
func startWithAlerts(
t *testing.T, env map[string]string,
) (*sender, *clock, *waf.Server, *alerts.Queue) {
) (*sender, *clock, *wafAndParts, *alerts.Queue) {
t.Helper()
return startAppWithAlerts(
@@ -265,7 +264,7 @@ func startWithAlerts(
// startAppWithAlerts is startWithAlerts in front of the app handler.
func startAppWithAlerts(
t *testing.T, handler http.HandlerFunc, env map[string]string,
) (*sender, *clock, *waf.Server, *alerts.Queue) {
) (*sender, *clock, *wafAndParts, *alerts.Queue) {
t.Helper()
app := startApp(t, handler)
+1 -2
View File
@@ -15,7 +15,6 @@ import (
"sneak.berlin/go/smallwebwaf/internal/anomaly"
"sneak.berlin/go/smallwebwaf/internal/ratelimit"
"sneak.berlin/go/smallwebwaf/internal/requestlog"
"sneak.berlin/go/smallwebwaf/internal/waf"
)
// The anomaly thresholds: the prefix of a scope followed by the end of a
@@ -332,7 +331,7 @@ func TestRequestCountsForTheASNumberGeoJSGivesBeforeItEnds(t *testing.T) {
// kept.
geojsURL, _, release := startHeldGeoJS(t)
var server atomic.Pointer[waf.Server]
var server atomic.Pointer[wafAndParts]
app := startApp(t, func(http.ResponseWriter, *http.Request) {
release()
+13 -13
View File
@@ -411,7 +411,7 @@ func TestTheHeaderLimitsComeBeforeEveryCheckThatRefuses(t *testing.T) {
env map[string]string
path string
// prepare gets the server ready, at now, before the question.
prepare func(t *testing.T, server *waf.Server, now time.Time)
prepare func(t *testing.T, server *wafAndParts, now time.Time)
}{
{"SWW_WAF_DENY_NETS", map[string]string{denyNets: client}, "/", leaveAsItIs},
{"a ban", nil, "/", banClient},
@@ -426,21 +426,21 @@ func TestTheHeaderLimitsComeBeforeEveryCheckThatRefuses(t *testing.T) {
"a DNS blocklist", map[string]string{
dnsblZones: dnsblZone, dnsblResolver: noResolver, dnsblAbuseIPDBAction: actionDeny,
},
"/", func(_ *testing.T, server *waf.Server, _ time.Time) {
"/", func(_ *testing.T, server *wafAndParts, _ time.Time) {
loadVerdicts(server, map[string][]string{client: {dnsblZone}})
},
},
{
"AbuseIPDB",
map[string]string{abuseIPDBKey: accountKey, dnsblAbuseIPDBAction: actionDeny},
"/", func(_ *testing.T, server *waf.Server, _ time.Time) {
"/", func(_ *testing.T, server *wafAndParts, _ time.Time) {
// Over SWW_WAF_ABUSEIPDB_MIN_SCORE, 75 by default.
loadScores(server, map[string]int64{client: 80})
},
},
{
"SWW_WAF_TAG_DENY", map[string]string{tagLists: "vpn=" + vpnList, tagDeny: "vpn"},
"/", func(t *testing.T, server *waf.Server, _ time.Time) {
"/", func(t *testing.T, server *wafAndParts, _ time.Time) {
t.Helper()
loadLists(t, server, map[string][]string{vpnList: {client}})
},
@@ -647,7 +647,7 @@ func TestObserveModeAsksGeoJSNothingForARequestOverTheHeaderLimits(
// for env. No request to it may use the network.
func newWAFInBubble(
t *testing.T, env map[string]string,
) (*waf.Server, *output) {
) (*wafAndParts, *output) {
t.Helper()
settings := map[string]string{tagDeny: "country=KP"}
@@ -661,7 +661,7 @@ func newWAFInBubble(
// askDirectly hands a question about a request from client straight to server,
// as change leaves it, and returns the answer's status and how long it took.
func askDirectly(
t *testing.T, server *waf.Server, change func(*http.Request),
t *testing.T, server *wafAndParts, change func(*http.Request),
) (int, time.Duration) {
t.Helper()
@@ -685,7 +685,7 @@ func askDirectly(
}
// banClient bans client at now.
func banClient(_ *testing.T, server *waf.Server, now time.Time) {
func banClient(_ *testing.T, server *wafAndParts, now time.Time) {
server.Ledger.BanForLimit(
netip.MustParsePrefix(client+"/32"),
now,
@@ -694,7 +694,7 @@ func banClient(_ *testing.T, server *waf.Server, now time.Time) {
}
// countClient counts one request from client at now for the rate limits.
func countClient(_ *testing.T, server *waf.Server, now time.Time) {
func countClient(_ *testing.T, server *wafAndParts, now time.Time) {
server.Limiter.Count(
netip.MustParsePrefix(client+"/32"),
now,
@@ -703,7 +703,7 @@ func countClient(_ *testing.T, server *waf.Server, now time.Time) {
}
// listClient puts client on the blocklist at dropURL.
func listClient(t *testing.T, server *waf.Server, now time.Time) {
func listClient(t *testing.T, server *wafAndParts, now time.Time) {
t.Helper()
err := server.Lists.Load([]reputation.List{{
@@ -715,7 +715,7 @@ func listClient(t *testing.T, server *waf.Server, now time.Time) {
}
// leaveAsItIs prepares nothing.
func leaveAsItIs(*testing.T, *waf.Server, time.Time) {}
func leaveAsItIs(*testing.T, *wafAndParts, time.Time) {}
func TestARefusedRequestDoesNotWaitForASlowGeoJS(t *testing.T) {
t.Parallel()
@@ -726,7 +726,7 @@ func TestARefusedRequestDoesNotWaitForASlowGeoJS(t *testing.T) {
name string
env map[string]string
// prepare gets the server ready, at now, before the question.
prepare func(t *testing.T, server *waf.Server, now time.Time)
prepare func(t *testing.T, server *wafAndParts, now time.Time)
// cookie is the request's Cookie header.
cookie string
status int
@@ -811,7 +811,7 @@ func TestAQuestionWaitsForASlowGeoJSOnlyAsLongAsTheDefaultSays(
name string
env map[string]string
// prepare gets the server ready, at now, before the question.
prepare func(t *testing.T, server *waf.Server, now time.Time)
prepare func(t *testing.T, server *wafAndParts, now time.Time)
status int
action string
}{
@@ -877,7 +877,7 @@ func TestWAFAnswersWithinTheTimeLimitWhileEveryOutsideSourceHangs(
held, _, _ := startHeldGeoJS(t)
resolver, releaseResolver := startHeldResolver(t)
server, out, _ := newWAFWith(t, waf.New,
server, out, _ := newWAFWith(t, func(*waf.Params) {},
silentGeoJSURL, silentAbuseIPDBURL, time.Now, map[string]string{
tagDeny: "country=KP", coreRuleSetMode: block,
dnsblZones: dnsblZone, dnsblResolver: resolver,
+1 -2
View File
@@ -16,7 +16,6 @@ import (
"sneak.berlin/go/smallwebwaf/internal/bans"
"sneak.berlin/go/smallwebwaf/internal/requestlog"
"sneak.berlin/go/smallwebwaf/internal/waf"
)
const (
@@ -466,7 +465,7 @@ func (c *clock) advance(d time.Duration) {
// window.
func startWithClock(
t *testing.T, geojsURL string, env map[string]string,
) (*sender, *clock, *waf.Server) {
) (*sender, *clock, *wafAndParts) {
t.Helper()
app := startApp(t, func(http.ResponseWriter, *http.Request) {})
+3 -5
View File
@@ -62,7 +62,7 @@ func coreRuleSetMatch() coreruleset.Result {
// at its default but for env. No request to it may use the network.
func newWAFHoldingTheCoreRuleSet(
t *testing.T, crs *heldCoreRuleSet, env map[string]string,
) (*waf.Server, *output, *alerts.Queue) {
) (*wafAndParts, *output, *alerts.Queue) {
t.Helper()
settings := map[string]string{
@@ -71,11 +71,9 @@ func newWAFHoldingTheCoreRuleSet(
}
maps.Copy(settings, env)
server, out, queue := newWAFWith(t, func(params waf.Params) *waf.Server {
server, out, queue := newWAFWith(t, func(params *waf.Params) {
params.CoreRuleSet = crs
params.BesideLookupTimeLimit = waf.BesideLookupTimeLimit
return waf.New(params)
}, silentGeoJSURL, abuseIPDBURL, time.Now, settings)
return server, out, queue
@@ -105,7 +103,7 @@ func wantAnswer(
// left no trace: line has none of its fields, and server has counted no match
// of it and raised no alert for one.
func wantNoCoreRuleSetTrace(
t *testing.T, server *waf.Server, queue *alerts.Queue, line logLine,
t *testing.T, server *wafAndParts, queue *alerts.Queue, line logLine,
) {
t.Helper()
+3 -3
View File
@@ -529,7 +529,7 @@ func TestBanForALoweredLimitGivesThePercentageInItsNotesAndItsAlert(
// clock.
func startWithLookups(
t *testing.T, env map[string]string,
) (*sender, *waf.Server, *alerts.Queue) {
) (*sender, *wafAndParts, *alerts.Queue) {
t.Helper()
s, _, server, queue := startWithLookupsAndClock(t, env)
@@ -544,7 +544,7 @@ func startWithLookups(
// country, and no other address.
func startWithLookupsAndClock(
t *testing.T, env map[string]string,
) (*sender, *clock, *waf.Server, *alerts.Queue) {
) (*sender, *clock, *wafAndParts, *alerts.Queue) {
t.Helper()
path := filepath.Join(t.TempDir(), "ipinfo_lite.mmdb")
@@ -584,7 +584,7 @@ func (s *sender) uploadFrom(from string) logLine {
// straight to server's handler, without the network, and returns once it is
// answered.
func serveFromDE(
t *testing.T, server *waf.Server, method string, body io.Reader,
t *testing.T, server *wafAndParts, method string, body io.Reader,
) {
t.Helper()
-9
View File
@@ -1,13 +1,4 @@
package waf
import "sneak.berlin/go/smallwebwaf/internal/reputation"
// BesideLookupTimeLimit is besideLookupTimeLimit.
const BesideLookupTimeLimit = besideLookupTimeLimit
// BanAbuseIPDBBlacklist does on s what a fetch of AbuseIPDB's blacklist with
// the clients on listed does.
func (s *Server) BanAbuseIPDBBlacklist(listed []reputation.BlacklistEntry) {
h := s.Handler.(*handler) //nolint:forcetypeassert // New makes it one
BanAbuseIPDBBlacklist(h.config, h.ledger, h.processLog, h.now(), listed)
}
+1 -1
View File
@@ -150,7 +150,7 @@ func TestPathUnderTheOwnPrefixIsNeitherForwardedNorRefused(t *testing.T) {
// historyOf returns the history of the client at addr.
func historyOf(
t *testing.T, server *waf.Server, addr string,
t *testing.T, server *wafAndParts, addr string,
) ratelimit.History {
t.Helper()
+1 -13
View File
@@ -116,21 +116,9 @@ type CoreRuleSetInspector interface {
) (coreruleset.Result, []byte, error)
}
// Server is the server waf runs, with the parts of its Params. The tests
// read them.
// Server is the server waf runs.
type Server struct {
*http.Server
Ledger *bans.Ledger
Limiter *ratelimit.Limiter
GeoJS *geojs.GeoJS
Anomalies *anomaly.Counters
LookupFile *lookup.File
Lists *reputation.Lists
DNSBL *reputation.DNSBL
AbuseIPDB *reputation.AbuseIPDB
RouteWatch *routewatch.Client
Metrics *metrics.Metrics
}
// newHandler returns the handler with what every request shares, the parts
+36 -12
View File
@@ -318,7 +318,7 @@ func startProxyWithGeoJS(
func startProxyWithClock(
t *testing.T, appURL, geojsURL string, now func() time.Time,
env map[string]string,
) (string, *output, *waf.Server) {
) (string, *output, *wafAndParts) {
t.Helper()
addr, out, server, _ := startProxyWithAlerts(
@@ -337,7 +337,7 @@ func startProxyWithClock(
func startProxyWithAlerts(
t *testing.T, appURL, geojsURL string, now func() time.Time,
env map[string]string,
) (string, *output, *waf.Server, *alerts.Queue) {
) (string, *output, *wafAndParts, *alerts.Queue) {
t.Helper()
server, out, alertQueue := newWAF(t, geojsURL, now, env)
@@ -348,7 +348,7 @@ func startProxyWithAlerts(
// serve serves server on a port of its own until the test ends, and sets its
// Addr to where it listens.
func serve(t *testing.T, server *waf.Server) {
func serve(t *testing.T, server *wafAndParts) {
t.Helper()
listener, err := (&net.ListenConfig{}).Listen(
@@ -424,8 +424,29 @@ func startRProxy(
return listener.Addr().String()
}
// newWAF makes waf's server, without starting it, and
// returns it, what it writes, and the queue of the alerts it raises, as the
// wafAndParts is waf's server with the Params it was built from, so that a
// test can read the parts the server uses.
type wafAndParts struct {
*waf.Server
waf.Params
}
// banAbuseIPDBBlacklist does on w what a fetch of AbuseIPDB's blacklist with
// the clients on listed does.
func (w *wafAndParts) banAbuseIPDBBlacklist(
listed []reputation.BlacklistEntry,
) {
waf.BanAbuseIPDBBlacklist(
w.Config,
w.Ledger,
w.ProcessLog,
w.Now(),
listed,
)
}
// newWAF makes waf's server, without starting it, and returns it with its
// parts, what it writes, and the queue of the alerts it raises, as the
// settings in env make it. No alert is sent from the queue: they wait in it,
// for the test to look at.
// With no geojsURL, there is no stand-in for GeoJS to look clients up at, and
@@ -440,19 +461,21 @@ func newWAF(
geojsURL string,
now func() time.Time,
env map[string]string,
) (*waf.Server, *output, *alerts.Queue) {
) (*wafAndParts, *output, *alerts.Queue) {
t.Helper()
return newWAFWith(t, waf.New, geojsURL, abuseIPDBURL, now, env)
return newWAFWith(
t, func(*waf.Params) {}, geojsURL, abuseIPDBURL, now, env,
)
}
// newWAFWith is newWAF for the server build makes, with clients checked with
// AbuseIPDB at abuseIPDBCheckURL.
// newWAFWith is newWAF with change applied to the Params before the server is
// built from them, and clients checked with AbuseIPDB at abuseIPDBCheckURL.
func newWAFWith(
t *testing.T, build func(waf.Params) *waf.Server,
t *testing.T, change func(*waf.Params),
geojsURL, abuseIPDBCheckURL string, now func() time.Time,
env map[string]string,
) (*waf.Server, *output, *alerts.Queue) {
) (*wafAndParts, *output, *alerts.Queue) {
t.Helper()
settings := map[string]string{
@@ -524,8 +547,9 @@ func newWAFWith(
}
addCounters(&params)
addOutsideSources(&params, geojsURL, abuseIPDBCheckURL)
change(&params)
server := build(params)
server := &wafAndParts{Server: waf.New(params), Params: params}
return server, out, alertQueue
}
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"sneak.berlin/go/smallwebwaf/internal/bans"
"sneak.berlin/go/smallwebwaf/internal/ratelimit"
"sneak.berlin/go/smallwebwaf/internal/requestlog"
"sneak.berlin/go/smallwebwaf/internal/waf"
)
const refusalsLimitPerMinute = "SWW_WAF_REFUSALS_LIMIT_PER_MINUTE"
@@ -52,7 +51,7 @@ func (r refused) send(s *sender, from string) logLine {
// SWW_WAF_REFUSALS_LIMIT_PER_MINUTE at limit, and the settings in env.
func startForRefusalLimit(
t *testing.T, limit string, env map[string]string,
) (*sender, *clock, *waf.Server) {
) (*sender, *clock, *wafAndParts) {
t.Helper()
settings := map[string]string{
+11 -12
View File
@@ -18,7 +18,6 @@ import (
"sneak.berlin/go/smallwebwaf/internal/ratelimit"
"sneak.berlin/go/smallwebwaf/internal/reputation"
"sneak.berlin/go/smallwebwaf/internal/requestlog"
"sneak.berlin/go/smallwebwaf/internal/waf"
)
// The reputation settings.
@@ -139,13 +138,13 @@ func TestReputationRefusalNamesItsHeuristicAndWhatListedTheClient(
for _, tc := range []struct {
heuristic string
env map[string]string
load func(*testing.T, *waf.Server)
load func(*testing.T, *wafAndParts)
figures string
}{
{
"blocklists",
map[string]string{blocklistURLs: dropURL, blocklistAction: actionDeny},
func(t *testing.T, server *waf.Server) {
func(t *testing.T, server *wafAndParts) {
t.Helper()
loadLists(t, server, map[string][]string{dropURL: {client}})
},
@@ -157,7 +156,7 @@ func TestReputationRefusalNamesItsHeuristicAndWhatListedTheClient(
dnsblZones: dnsblZone, dnsblResolver: noResolver,
dnsblAbuseIPDBAction: actionDeny,
},
func(_ *testing.T, server *waf.Server) {
func(_ *testing.T, server *wafAndParts) {
loadVerdicts(server, map[string][]string{client: {dnsblZone}})
},
`{"zones": ["` + dnsblZone + `"]}`,
@@ -165,7 +164,7 @@ func TestReputationRefusalNamesItsHeuristicAndWhatListedTheClient(
{
"abuseipdb",
map[string]string{abuseIPDBKey: accountKey, dnsblAbuseIPDBAction: actionDeny},
func(_ *testing.T, server *waf.Server) {
func(_ *testing.T, server *wafAndParts) {
loadScores(server, map[string]int64{client: 80})
},
`{"score": 80, "min_score": 75}`,
@@ -560,7 +559,7 @@ func TestReputationSourcesTagTheRequestWhateverTheirAction(t *testing.T) {
for _, tc := range []struct {
name string
env map[string]string
load func(*waf.Server)
load func(*wafAndParts)
want []string
}{
{
@@ -568,7 +567,7 @@ func TestReputationSourcesTagTheRequestWhateverTheirAction(t *testing.T) {
map[string]string{
dnsblZones: dnsblZone, dnsblResolver: noResolver, dnsblAbuseIPDBAction: actionLog,
},
func(server *waf.Server) {
func(server *wafAndParts) {
loadVerdicts(server, map[string][]string{fromDE: {dnsblZone}})
},
[]string{"asn=64496", "country=DE", "dnsbl=" + dnsblZone},
@@ -576,7 +575,7 @@ func TestReputationSourcesTagTheRequestWhateverTheirAction(t *testing.T) {
{
abuseipdb,
map[string]string{abuseIPDBKey: accountKey, dnsblAbuseIPDBAction: actionLog},
func(server *waf.Server) {
func(server *wafAndParts) {
loadScores(server, map[string]int64{fromDE: 80})
},
[]string{abuseipdb, "asn=64496", "country=DE"},
@@ -1256,7 +1255,7 @@ func verdictsFetched() time.Time {
// verdictsFetched, as dnsbl.json would at start: one that lists the
// client from each zone listedBy gives for it, and one that does not from
// each other zone.
func loadVerdicts(server *waf.Server, listedBy map[string][]string) {
func loadVerdicts(server *wafAndParts, listedBy map[string][]string) {
verdicts := make(
[]reputation.Verdict,
0,
@@ -1281,7 +1280,7 @@ func loadVerdicts(server *waf.Server, listedBy map[string][]string) {
// loadScores puts into server's AbuseIPDB the score scores gives each
// client, an IPv4 address, fetched at verdictsFetched, as
// abuseipdb-scores.json would at start.
func loadScores(server *waf.Server, scores map[string]int64) {
func loadScores(server *wafAndParts, scores map[string]int64) {
kept := make([]reputation.Score, 0, len(scores))
for client, score := range scores {
kept = append(kept, reputation.Score{
@@ -1295,7 +1294,7 @@ func loadScores(server *waf.Server, scores map[string]int64) {
// wantAbuseIPDBChecks checks how many clients server has checked with
// AbuseIPDB.
func wantAbuseIPDBChecks(t *testing.T, server *waf.Server, want int) {
func wantAbuseIPDBChecks(t *testing.T, server *wafAndParts, want int) {
t.Helper()
if got := server.AbuseIPDB.Checked(); got != want {
@@ -1307,7 +1306,7 @@ func wantAbuseIPDBChecks(t *testing.T, server *waf.Server, want int) {
// its lines, fetched at listsFetched, as lists.json would at start.
func loadLists(
t *testing.T,
server *waf.Server,
server *wafAndParts,
copies map[string][]string,
) {
t.Helper()
+1 -2
View File
@@ -11,7 +11,6 @@ import (
"time"
"sneak.berlin/go/smallwebwaf/internal/requestlog"
"sneak.berlin/go/smallwebwaf/internal/waf"
)
// routeWatchURL is SWW_WAF_ROUTEWATCH_URL, and tagsMissing the log line's field
@@ -58,7 +57,7 @@ func startRouteWatch(t *testing.T, routes map[string]standInRoute) string {
// waitForRouteWatch waits until routewatch's answer about from, in the client
// group of the given length, is kept, so that the next request gets its tags.
func waitForRouteWatch(
t *testing.T, server *waf.Server, from string, bits int,
t *testing.T, server *wafAndParts, from string, bits int,
) {
t.Helper()
+1 -13
View File
@@ -104,12 +104,10 @@ type Report struct {
// is far above rproxy's, and a question refused for its size would have rproxy
// let the request through.
func New(params Params) *Server {
h := newHandler(params)
return &Server{
Server: &http.Server{
Addr: params.Config.ListenAddr,
Handler: h,
Handler: newHandler(params),
ErrorLog: slog.NewLogLogger(
params.ProcessLog.Handler(),
slog.LevelWarn,
@@ -118,16 +116,6 @@ func New(params Params) *Server {
WriteTimeout: wafTimeout,
IdleTimeout: wafIdleTimeout,
},
Ledger: h.ledger,
Limiter: h.limiter,
GeoJS: h.geojs,
Anomalies: h.anomalies,
LookupFile: h.lookupFile,
Lists: h.lists,
DNSBL: h.dnsbl,
AbuseIPDB: h.abuseIPDB,
RouteWatch: h.routeWatch,
Metrics: h.metrics,
}
}
+4 -4
View File
@@ -57,7 +57,7 @@ type WAF struct {
t *testing.T
addr string
out *output
server *waf.Server
server *wafAndParts
clock *clock
queue *alerts.Queue
}
@@ -69,14 +69,14 @@ func startWAF(
) *WAF {
t.Helper()
return startWAFWith(t, geojsURL, env, func(*waf.Server) {})
return startWAFWith(t, geojsURL, env, func(*wafAndParts) {})
}
// startWAFWith is startWAF with change applied to the server before
// it starts.
func startWAFWith(
t *testing.T, geojsURL string, env map[string]string,
change func(*waf.Server),
change func(*wafAndParts),
) *WAF {
t.Helper()
@@ -663,7 +663,7 @@ func TestQuestionWhoseBodyStopsArrivingGetsNoAnswer(t *testing.T) {
t,
"",
map[string]string{metricsToken: token},
func(server *waf.Server) { server.ReadTimeout = readTimeout },
func(server *wafAndParts) { server.ReadTimeout = readTimeout },
)
conn := dial(t, s.addr)