Import Anubis v1.28.2
Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3). Masyunis customizations are re-applied in the following commits.
This commit is contained in:
1 parent
eb3e46d8d0
commit
e07de898cd
573 files changed
+35846
-6807
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package naive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/TecharoHQ/anubis/lib/config"
|
||||
"github.com/TecharoHQ/anubis/lib/store/memory"
|
||||
)
|
||||
|
||||
func TestInvalidClientIP(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
i, err := New(&config.Honeypot{}, memory.New(ctx), slog.Default())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, ip := range []string{"", "invalid", "1.2.3.999"} {
|
||||
t.Run(ip, func(t *testing.T) {
|
||||
r := httptest.NewRequest("GET", "http://example.com/", nil)
|
||||
r.Header.Set("X-Real-IP", ip)
|
||||
w := httptest.NewRecorder()
|
||||
i.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusTeapot {
|
||||
t.Errorf("status=%d", w.Code)
|
||||
}
|
||||
if match, err := i.CheckNetwork().Check(r); err != nil || match {
|
||||
t.Fatalf("match=%v err=%v", match, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user