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

Function TestValidateDomain

internal/agent/validate_test.go:63–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestValidateDomain(t *testing.T) {
64 cases := []struct {
65 name string
66 input string
67 wantErr bool
68 wantASCII string // expected normalized output on success; "" means don't check
69 }{
70 // Valid
71 {"plain ASCII", "example.com", false, "example.com"},
72 {"subdomain", "agents.example.com", false, "agents.example.com"},
73 {"with hyphen", "my-domain.example.com", false, "my-domain.example.com"},
74 {"IDN normalizes to Punycode", "пример.рф", false, "xn--e1afmkfd.xn--p1ai"},
75 // Invalid — what today's prod was accepting before the fix
76 {"empty", "", true, ""},
77 {"whitespace + comma — the bug repro", "not a domain, just garbage", true, ""},
78 {"single space", "exam ple.com", true, ""},
79 {"no period — bare label", "localhost", true, ""},
80 {"trailing newline", "example.com\n", true, ""},
81 {"control char", "exa\x00mple.com", true, ""},
82 // Length bounds — IDNA enforces 63-char label and 253-char total
83 {"label exceeds 63 chars", strings.Repeat("a", 64) + ".com", true, ""},
84 }
85 for _, tc := range cases {
86 t.Run(tc.name, func(t *testing.T) {
87 got, err := validateDomain(tc.input)
88 if (err != nil) != tc.wantErr {
89 t.Errorf("validateDomain(%q) err=%v, wantErr=%v", tc.input, err, tc.wantErr)
90 return
91 }
92 if !tc.wantErr && tc.wantASCII != "" && got != tc.wantASCII {
93 t.Errorf("validateDomain(%q) got=%q, want=%q (Punycode normalization)", tc.input, got, tc.wantASCII)
94 }
95 })
96 }
97}

Callers

nothing calls this directly

Calls 2

validateDomainFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected