You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.8 KiB
39 lines
1.8 KiB
package console
|
|
|
|
import "testing"
|
|
|
|
// 下载页地址的边界:分发桶是公共读的,这里放宽一点就等于任人挂页面 / 覆盖别的应用。
|
|
func TestParseDistPageURL(t *testing.T) {
|
|
const domain = "https://dl.ymaikj.com/"
|
|
ok := []struct{ in, key, url string }{
|
|
{"https://dl.ymaikj.com/EAIMAR/download.html", "EAIMAR/download.html", "https://dl.ymaikj.com/EAIMAR/download.html"},
|
|
{"http://DL.ymaikj.com/EAIMAR/download2.html?x=1", "EAIMAR/download2.html", "https://dl.ymaikj.com/EAIMAR/download2.html"},
|
|
{"https://dl.ymaikj.com/EAIMAR/a_b-c.html", "EAIMAR/a_b-c.html", "https://dl.ymaikj.com/EAIMAR/a_b-c.html"},
|
|
}
|
|
for _, c := range ok {
|
|
key, u, err := parseDistPageURL(c.in, domain, "EAIMAR")
|
|
if err != nil || key != c.key || u != c.url {
|
|
t.Errorf("%s => (%q,%q,%v), want (%q,%q)", c.in, key, u, err, c.key, c.url)
|
|
}
|
|
}
|
|
bad := []string{
|
|
"",
|
|
"dl.ymaikj.com/EAIMAR/download.html", // 没有 scheme
|
|
"https://evil.com/EAIMAR/download.html", // 别的域名
|
|
"https://dl.ymaikj.com/deepGlass/download.html", // 别的应用
|
|
"https://dl.ymaikj.com/android/EAIMAR/x.html", // 多一层 / 安装包目录
|
|
"https://dl.ymaikj.com/download.html", // 少一层
|
|
"https://dl.ymaikj.com/EAIMAR/x.apk", // 不是 html
|
|
"https://dl.ymaikj.com/EAIMAR/../x.html", // 穿越
|
|
"https://dl.ymaikj.com/EAIMAR/.x.html", // 隐藏文件
|
|
"https://dl.ymaikj.com/EAIMAR/x.HTML", // 扩展名只认小写
|
|
}
|
|
for _, in := range bad {
|
|
if key, _, err := parseDistPageURL(in, domain, "EAIMAR"); err == nil {
|
|
t.Errorf("%q 应被拒,却得到 key=%q", in, key)
|
|
}
|
|
}
|
|
if got := defaultDistPageURL(domain, "EAIMAR"); got != "https://dl.ymaikj.com/EAIMAR/download.html" {
|
|
t.Errorf("默认地址 = %s", got)
|
|
}
|
|
}
|
|
|