diff --git a/internal/rproxy/rproxy_test.go b/internal/rproxy/rproxy_test.go index d45e5f6..74e8eae 100644 --- a/internal/rproxy/rproxy_test.go +++ b/internal/rproxy/rproxy_test.go @@ -324,7 +324,8 @@ func greet(w http.ResponseWriter, r *http.Request) { // startRProxy starts rproxy with waf at backend and the app at appURL, and // the settings in env on top of the defaults. It returns where rproxy listens -// and what it writes. +// and what it writes. SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS is a minute unless env +// sets it, so that a busy host cannot make rproxy drop a question or a report. func startRProxy( t *testing.T, backend, appURL string, env map[string]string, ) (string, *output) { @@ -357,6 +358,7 @@ func startServerLogging( settings := map[string]string{ "SWW_RPROXY_WAF_BACKEND": backend, "SWW_RPROXY_UPSTREAM_URL": appURL, + wafBackendTimeout: "60000", } maps.Copy(settings, env) diff --git a/internal/sww/rproxy_test.go b/internal/sww/rproxy_test.go index 267704e..49b8de1 100644 --- a/internal/sww/rproxy_test.go +++ b/internal/sww/rproxy_test.go @@ -52,6 +52,8 @@ func runRProxy(ctx context.Context, env map[string]string, out *output) int { // startRProxy runs rproxy with waf at backend and the app at appURL, and // returns its URL and what it writes. It believes X-Forwarded-For from the // tests. It stops as the test ends, and that it stopped in order is checked. +// It waits a minute for waf's answers, so that a busy host cannot make it drop +// a question or a report. func startRProxy(t *testing.T, backend, appURL string) (string, *output) { t.Helper() @@ -65,6 +67,7 @@ func startRProxy(t *testing.T, backend, appURL string) (string, *output) { "SWW_RPROXY_UPSTREAM_URL": appURL, "SWW_RPROXY_TRUSTED_PROXIES": localhost + "/32", wafBackend: backend, + wafBackendTimeout: "60000", }, out) }() diff --git a/internal/sww/sww_test.go b/internal/sww/sww_test.go index 4cfa9a7..ee70ac0 100644 --- a/internal/sww/sww_test.go +++ b/internal/sww/sww_test.go @@ -157,12 +157,21 @@ func (o *output) text() string { // run runs `sww waf` with the settings in env until ctx is done, // and returns its exit status. SWW_WAF_LOOKUP_SOURCE is off unless env sets it, // so that no test sends GeoJS its clients' addresses. +// +// SWW_WAF_CORE_RULE_SET_MODE is off unless env sets it too. The race detector +// and a busy host can slow the Core Rule Set's inspections past waf's time +// limit for its checks, and waf then refuses the request with 503. The waf +// package's tests cover the Core Rule Set. func run(ctx context.Context, env map[string]string, out *output) int { v := configtest.Viper(env) if _, set := env["SWW_WAF_LOOKUP_SOURCE"]; !set { v.Set("SWW_WAF_LOOKUP_SOURCE", "off") } + if _, set := env["SWW_WAF_CORE_RULE_SET_MODE"]; !set { + v.Set("SWW_WAF_CORE_RULE_SET_MODE", config.CoreRuleSetModeOff) + } + // The cache files go beside the state files unless the test says // otherwise. if _, set := env[cacheDir]; !set && env[stateDir] != "" { @@ -625,6 +634,7 @@ func TestCoreRuleSetExclusionsFileThatCannotBeReadStopsTheStart( status := run(t.Context(), map[string]string{ listenAddr: localhost + ":0", stateDir: t.TempDir(), ruleFilesDir: t.TempDir(), + "SWW_WAF_CORE_RULE_SET_MODE": config.CoreRuleSetModeBlock, "SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE": path, }, out) if status != 1 {