31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package collector
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"git.tornberg.me/go-otel/internal/storage"
|
|
)
|
|
|
|
func TestAssessSourceIP(t *testing.T) {
|
|
ev := func(route string, status uint16, ua string) storage.SourceIPEvent {
|
|
return storage.SourceIPEvent{Route: route, StatusCode: status, UserAgent: ua}
|
|
}
|
|
browser := "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/120 Safari/537.36"
|
|
|
|
if r, _ := assessSourceIP("1.2.3.4", []storage.SourceIPEvent{ev("/", 200, browser), ev("/cart", 200, browser)}); r != "" {
|
|
t.Errorf("normal traffic flagged as %q", r)
|
|
}
|
|
probes := []storage.SourceIPEvent{ev("/.env", 404, browser), ev("/.git/config", 404, browser), ev("/wp-admin", 404, browser)}
|
|
if r, n := assessSourceIP("1.2.3.4", probes); r != "probe-scanner" || n != 3 {
|
|
t.Errorf("probes: got %q, %d", r, n)
|
|
}
|
|
var walk []storage.SourceIPEvent
|
|
for i := 0; i < 15; i++ {
|
|
walk = append(walk, ev(fmt.Sprintf("/missing-%d", i), 404, browser))
|
|
}
|
|
if r, _ := assessSourceIP("1.2.3.4", walk); r != "enumerator" {
|
|
t.Errorf("enumeration: got %q", r)
|
|
}
|
|
}
|