diff --git a/botfilter_test.go b/botfilter_test.go index c4490c4c..110f78bc 100644 --- a/botfilter_test.go +++ b/botfilter_test.go @@ -122,3 +122,17 @@ func Test404ScoreBansOnSubsequentRequest(t *testing.T) { t.Fatalf("first response status = %d, want 404", firstResponse.Code) } + second := httptest.NewRequest(http.MethodGet, "http://wiki.example/another-miss", nil) + second.RemoteAddr = "198.51.100.23:1234" + second.Header.Set("User-Agent", "Mozilla/5.0 Chrome/120.0 AppleWebKit/537.36 Safari/537.36") + second.Header.Set("Accept", "text/html") + secondResponse := httptest.NewRecorder() + handler.ServeHTTP(secondResponse, second) + if secondResponse.Code != http.StatusForbidden { + t.Fatalf("second response status = %d, want cached ban after two 404s", secondResponse.Code) + } + if nextCalls != 1 { + t.Fatalf("next handler calls = %d, want 1", nextCalls) + } +} +