MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestIsDisallowedWebhookIP

Function TestIsDisallowedWebhookIP

internal/webhook/ssrf_test.go:10–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestIsDisallowedWebhookIP(t *testing.T) {
11 cases := []struct {
12 ip string
13 blocked bool
14 }{
15 {"127.0.0.1", true}, // loopback
16 {"::1", true}, // loopback v6
17 {"10.0.0.5", true}, // RFC-1918
18 {"172.16.3.4", true}, // RFC-1918
19 {"192.168.1.1", true}, // RFC-1918
20 {"169.254.169.254", true}, // cloud metadata (link-local)
21 {"100.64.1.2", true}, // CGNAT (RFC 6598)
22 {"100.127.255.255", true}, // CGNAT upper edge
23 {"0.0.0.0", true}, // unspecified
24 {"224.0.0.1", true}, // multicast
25 {"fc00::1", true}, // IPv6 ULA
26 {"fe80::1", true}, // IPv6 link-local
27 {"8.8.8.8", false}, // public
28 {"1.1.1.1", false}, // public
29 {"100.63.255.255", false}, // just below CGNAT
30 {"100.128.0.0", false}, // just above CGNAT
31 {"2606:4700:4700::1111", false}, // public v6 (Cloudflare)
32 }
33 for _, c := range cases {
34 ip := net.ParseIP(c.ip)
35 if ip == nil {
36 t.Fatalf("bad test IP %q", c.ip)
37 }
38 if got := IsDisallowedWebhookIP(ip); got != c.blocked {
39 t.Errorf("IsDisallowedWebhookIP(%s) = %v, want %v", c.ip, got, c.blocked)
40 }
41 }
42 // nil is treated as disallowed (fail closed).
43 if !IsDisallowedWebhookIP(nil) {
44 t.Error("IsDisallowedWebhookIP(nil) = false, want true (fail closed)")
45 }
46}
47
48func TestGuardedDialControl(t *testing.T) {
49 if err := guardedDialControl("tcp", "127.0.0.1:443", nil); err == nil {

Callers

nothing calls this directly

Calls 2

IsDisallowedWebhookIPFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected