2

Add lazy IP enrichment and bot hints

This commit is contained in:
2026-03-12 02:00:41 +01:00
parent c5e1c4ff36
commit 7bd3933215
3 changed files with 81 additions and 1 deletions

View File

@@ -138,6 +138,44 @@ func TestInvestigateLoadsRegistrationAndSpamhausForNonBot(t *testing.T) {
}
}
func TestInvestigateAddsBotHintFromUserAgent(t *testing.T) {
t.Parallel()
serverURL := ""
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/bootstrap-v4.json":
_, _ = w.Write([]byte(`{"services":[[["216.73.216.0/22"],["` + serverURL + `/rdap/"]]]}`))
case "/rdap/ip/216.73.216.112":
_, _ = w.Write([]byte(`{"handle":"NET-216-73-216-0-1","name":"AWS-ANTHROPIC","entities":[{"roles":["abuse"],"vcardArray":["vcard",[["fn",{},"text","Anthropic, PBC"]]]}]}`))
default:
http.NotFound(w, r)
}
}))
serverURL = server.URL
defer server.Close()
svc := newService(
config.InvestigationConfig{Enabled: true, Timeout: config.Duration{Duration: time.Second}, UserAgent: "test-agent", SpamhausEnabled: true},
server.Client(),
&fakeResolver{},
log.New(testWriter{t}, "", 0),
nil,
map[string]string{"ipv4": server.URL + "/bootstrap-v4.json", "ipv6": server.URL + "/bootstrap-v6.json"},
)
investigation, err := svc.Investigate(context.Background(), "216.73.216.112", []string{"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"})
if err != nil {
t.Fatalf("investigate ip: %v", err)
}
if investigation.Bot == nil || investigation.Bot.Name != "ClaudeBot" || investigation.Bot.Verified {
t.Fatalf("expected unverified ClaudeBot hint, got %+v", investigation.Bot)
}
if investigation.Registration == nil || investigation.Registration.Organization != "Anthropic, PBC" {
t.Fatalf("expected registration enrichment to continue after bot hint, got %+v", investigation.Registration)
}
}
func TestPublishedNetworksAreCached(t *testing.T) {
t.Parallel()