fix(adtracking): 收紧成交口径、点击去重与生产落地页白名单
成交 GMV 排除已关闭订单,避免未支付关单被计入;点击按访客 5 秒、IP 1 秒双重去重;生产禁止 localhost 落地页,失效短码改用 QueryEscape。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -92,38 +92,40 @@ func TestCodePattern(t *testing.T) {
|
||||
func TestValidateTargetURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
allowLocal bool
|
||||
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},
|
||||
{"", false, "https://hao858.com/", false, nil},
|
||||
{"/listings", false, "https://hao858.com/listings", false, nil},
|
||||
{"https://hao858.com", false, "https://hao858.com", false, nil},
|
||||
{"https://h5.hao858.com/m", false, "https://h5.hao858.com/m", false, nil},
|
||||
{"http://localhost:5189", true, "http://localhost:5189", false, nil},
|
||||
{"http://127.0.0.1:18088", true, "http://127.0.0.1:18088", false, nil},
|
||||
{"http://localhost:5189", false, "", true, ErrDisallowedTargetDomain},
|
||||
{"http://127.0.0.1:18088", false, "", true, ErrDisallowedTargetDomain},
|
||||
{"https://evil-phishing.com", false, "", true, ErrDisallowedTargetDomain},
|
||||
{"https://hao858.com.fake.com", false, "", true, ErrDisallowedTargetDomain},
|
||||
{"https://sub.evil.com/hao858.com", false, "", true, ErrDisallowedTargetDomain},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
got, err := validateTargetURL(tt.input)
|
||||
got, err := validateTargetURL(tt.input, tt.allowLocal)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Errorf("validateTargetURL(%q) expected error, got nil", tt.input)
|
||||
t.Errorf("validateTargetURL(%q, %v) expected error, got nil", tt.input, tt.allowLocal)
|
||||
}
|
||||
if tt.errExpected != nil && err != tt.errExpected {
|
||||
t.Errorf("validateTargetURL(%q) err = %v; want %v", tt.input, err, tt.errExpected)
|
||||
t.Errorf("validateTargetURL(%q, %v) err = %v; want %v", tt.input, tt.allowLocal, err, tt.errExpected)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("validateTargetURL(%q) unexpected error: %v", tt.input, err)
|
||||
t.Errorf("validateTargetURL(%q, %v) unexpected error: %v", tt.input, tt.allowLocal, err)
|
||||
}
|
||||
if got != tt.wantURL {
|
||||
t.Errorf("validateTargetURL(%q) = %q; want %q", tt.input, got, tt.wantURL)
|
||||
t.Errorf("validateTargetURL(%q, %v) = %q; want %q", tt.input, tt.allowLocal, got, tt.wantURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user