alot more changes
This commit is contained in:
1 parent
23243ddbdc
commit
0ed2935f04
40 files changed
+2889
-115
No files matched your search
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user