fix(dcauth): order_site 白名单补充生产域名 ks.khhao.com
This commit is contained in:
@@ -14,6 +14,9 @@ func TestParseAuthorizeURLAllowedOrigins(t *testing.T) {
|
||||
{name: "localhost", api: "http%3A%2F%2Flocalhost", expected: "http://localhost"},
|
||||
{name: "localhost trailing slash", api: "http%3A%2F%2Flocalhost%2F", expected: "http://localhost"},
|
||||
{name: "lan address", api: "http%3A%2F%2F192.168.10.6", expected: "http://192.168.10.6"},
|
||||
{name: "production ks.khhao.com", api: "https%3A%2F%2Fks.khhao.com", expected: "https://ks.khhao.com"},
|
||||
{name: "production uppercase host", api: "https%3A%2F%2FKS.KHHAO.COM", expected: "https://ks.khhao.com"},
|
||||
{name: "legacy production order.khhao.com", api: "https%3A%2F%2Forder.khhao.com", expected: "https://order.khhao.com"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -31,9 +34,25 @@ func TestParseAuthorizeURLAllowedOrigins(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAuthorizeURLRejectsUnknownOrigin(t *testing.T) {
|
||||
raw := "dcauth://authorize?app=order_site&challenge_id=challenge-id&challenge=challenge-value&api=http%3A%2F%2Fexample.com"
|
||||
if _, err := parseAuthorizeURL(raw); err == nil {
|
||||
t.Fatal("parseAuthorizeURL() accepted an unknown origin")
|
||||
tests := []struct {
|
||||
name string
|
||||
api string
|
||||
}{
|
||||
{name: "unknown host", api: "http%3A%2F%2Fexample.com"},
|
||||
{name: "lookalike suffix", api: "https%3A%2F%2Fks.khhao.com.evil.com"},
|
||||
{name: "lookalike prefix", api: "https%3A%2F%2Fevil-ks.khhao.com"},
|
||||
{name: "unexpected port", api: "https%3A%2F%2Fks.khhao.com%3A8443"},
|
||||
{name: "plain http production host", api: "http%3A%2F%2Fks.khhao.com"},
|
||||
{name: "userinfo trick", api: "https%3A%2F%2Fks.khhao.com%40evil.com"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
raw := "dcauth://authorize?app=order_site&challenge_id=challenge-id&challenge=challenge-value&api=" + tt.api
|
||||
if _, err := parseAuthorizeURL(raw); err == nil {
|
||||
t.Fatalf("parseAuthorizeURL() accepted %q", tt.api)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user