fix(adtracking): 修复生产网关反代路由、成交态统计口径与安全加固
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user