- 新增访问统计:visitstats 服务与查询、visit_capture 中间件、爬虫/来源识别、管理端 analytics 页面 - 新增侧边栏:sidebar 服务与 handler、管理端 sidebar 配置页、前端侧边栏组件 - 新增 widget 嵌入代码生成(widgetCode)与 widgetApi - 遥测逻辑迁移至 handler 层,删除 service/telemetry - env 示例补充 Docker 部署可信代理 IP 说明
32 lines
1.3 KiB
Go
32 lines
1.3 KiB
Go
package service
|
|
|
|
import "testing"
|
|
|
|
func TestClassifyReferrer(t *testing.T) {
|
|
cases := []struct {
|
|
raw, siteHost string
|
|
wantHost string
|
|
wantKind string
|
|
}{
|
|
{"", "example.com", "", RefKindDirect},
|
|
{"not a url", "example.com", "", RefKindDirect},
|
|
{"https://example.com/posts/1", "example.com", "example.com", RefKindInternal},
|
|
{"https://www.google.com/search?q=x", "example.com", "www.google.com", RefKindSearch},
|
|
{"https://www.baidu.com/s?wd=x", "example.com", "www.baidu.com", RefKindSearch},
|
|
{"https://cn.bing.com/search?q=x", "example.com", "cn.bing.com", RefKindSearch},
|
|
{"https://weibo.com/abc", "example.com", "weibo.com", RefKindSocial},
|
|
{"https://x.com/user/status/1", "example.com", "x.com", RefKindSocial},
|
|
{"https://v2ex.com/t/123", "example.com", "v2ex.com", RefKindSocial},
|
|
{"https://blog.other.org/post", "example.com", "blog.other.org", RefKindExternal},
|
|
{"https://google.com:443/search?q=x", "example.com", "google.com", RefKindSearch},
|
|
{"https://evil.com/?u=https://google.com", "example.com", "evil.com", RefKindExternal},
|
|
}
|
|
for _, c := range cases {
|
|
host, kind := ClassifyReferrer(c.raw, c.siteHost)
|
|
if host != c.wantHost || kind != c.wantKind {
|
|
t.Errorf("ClassifyReferrer(%q, %q) = (%q, %q), want (%q, %q)",
|
|
c.raw, c.siteHost, host, kind, c.wantHost, c.wantKind)
|
|
}
|
|
}
|
|
}
|