fix(adtracking): 修复生产网关反代路由、成交态统计口径与安全加固

This commit is contained in:
yml2213
2026-09-10 11:17:40 +08:00
parent 2b11d70ebe
commit 6a3611c1a8
10 changed files with 140 additions and 28 deletions
@@ -88,3 +88,42 @@ func TestCodePattern(t *testing.T) {
}
}
}
func TestValidateTargetURL(t *testing.T) {
tests := []struct {
input string
wantURL string
wantErr bool
errExpected error
}{
{"", "https://hao858.com/", false, nil},
{"/listings", "https://hao858.com/listings", false, nil},
{"https://hao858.com", "https://hao858.com", false, nil},
{"https://h5.hao858.com/m", "https://h5.hao858.com/m", false, nil},
{"http://localhost:5189", "http://localhost:5189", false, nil},
{"http://127.0.0.1:18088", "http://127.0.0.1:18088", false, nil},
{"https://evil-phishing.com", "", true, ErrDisallowedTargetDomain},
{"https://hao858.com.fake.com", "", true, ErrDisallowedTargetDomain},
{"https://sub.evil.com/hao858.com", "", true, ErrDisallowedTargetDomain},
}
for _, tt := range tests {
got, err := validateTargetURL(tt.input)
if tt.wantErr {
if err == nil {
t.Errorf("validateTargetURL(%q) expected error, got nil", tt.input)
}
if tt.errExpected != nil && err != tt.errExpected {
t.Errorf("validateTargetURL(%q) err = %v; want %v", tt.input, err, tt.errExpected)
}
} else {
if err != nil {
t.Errorf("validateTargetURL(%q) unexpected error: %v", tt.input, err)
}
if got != tt.wantURL {
t.Errorf("validateTargetURL(%q) = %q; want %q", tt.input, got, tt.wantURL)
}
}
}
}