Files
order_site/apps/dcauth/main_test.go
T
yml2213 040100f290 feat(dcauth): 新增后台手机号与设备认证登录
登录链路改为账号密码 + 短信验证码 + DCAuth 设备签名,并新增后台手机号绑定、
登录日志、设备绑定与重置接口。
2026-10-21 20:46:24 +08:00

36 lines
1.1 KiB
Go

package main
import "testing"
func TestParseAuthorizeURLAllowedOrigins(t *testing.T) {
tests := []struct {
name string
api string
expected string
}{
{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"},
}
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
target, err := parseAuthorizeURL(raw)
if err != nil {
t.Fatalf("parseAuthorizeURL() error = %v", err)
}
if target.APIBase != tt.expected {
t.Fatalf("APIBase = %q, want %q", target.APIBase, tt.expected)
}
})
}
}
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")
}
}