24 lines
492 B
Go
24 lines
492 B
Go
package botfilter
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestRequiredHeaderCreatesTemporaryBan(t *testing.T) {
|
|
cfg := CreateConfig()
|
|
cfg.RequireUserAgent = true
|
|
cfg.RequireAccept = true
|
|
cfg.RequireHost = true
|
|
nextCalls := 0
|
|
handler, err := New(context.Background(), http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
|
|
nextCalls++
|
|
rw.WriteHeader(http.StatusOK)
|
|
}), cfg, "test")
|
|
if err != nil {
|
|
t.Fatalf("New() error = %v", err)
|
|
}
|
|
|