onesvm-browser-server/server/internal/fingerprint/profile_test.go
chii 9b689b2476 feat: 落地节点指纹与 Cookie 罐,并按现网能力更新消费/接手文档
公开页抓取改为 Chrome 136 自洽身份 + 每节点 SQLite 养罐,Trafilatura 走 curl_cffi;MCP/README/接手说明与 09-02 现网复测对齐,避免消费方继续抄过期的站点三分表。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 17:04:25 +08:00

73 lines
1.7 KiB
Go

package fingerprint
import (
"strings"
"testing"
)
func TestAllocateSelfConsistent(t *testing.T) {
p := Allocate("node-a|0")
if p.ChromeMajor != ChromeMajor || p.Impersonate != DefaultImpersonate {
t.Fatalf("版本漂移: %+v", p)
}
if !strings.Contains(p.UserAgent, "Chrome/136") {
t.Fatalf("UA 必须是 Chrome/136: %s", p.UserAgent)
}
if strings.Contains(p.UserAgent, "Chrome/151") {
t.Fatal("禁止 Chrome/151")
}
if !strings.Contains(p.SecCHUA, `"136"`) {
t.Fatalf("CH 必须对齐 136: %s", p.SecCHUA)
}
if p.OS == "Windows" && !strings.Contains(p.SecCHUAPlatform, "Windows") {
t.Fatalf("platform 与 OS 不一致: %+v", p)
}
if p.OS == "macOS" && !strings.Contains(p.SecCHUAPlatform, "macOS") {
t.Fatalf("platform 与 OS 不一致: %+v", p)
}
}
func TestAllocateStable(t *testing.T) {
a := Allocate("same-seed")
b := Allocate("same-seed")
if a != b {
t.Fatalf("同 seed 应同脸: %+v vs %+v", a, b)
}
c := Allocate("other-seed")
if c.ID == a.ID && c.UserAgent == a.UserAgent {
t.Fatal("不同 seed 不应撞脸")
}
}
func TestAllocateSetUnique(t *testing.T) {
set := AllocateSet("mgr1", TemplateCount)
if len(set) != TemplateCount {
t.Fatalf("套数=%d", len(set))
}
seen := map[string]bool{}
for _, p := range set {
if seen[p.ID] {
t.Fatalf("模版 id 重复: %s", p.ID)
}
seen[p.ID] = true
}
act := PickActive("mgr1", set)
if act.ID == "" {
t.Fatal("active 空")
}
act2 := PickActive("mgr1", set)
if act.ID != act2.ID {
t.Fatal("active 重启应稳定")
}
}
func TestHeadersAligned(t *testing.T) {
p := Allocate("h")
h := Headers(p)
if h["User-Agent"] != p.UserAgent {
t.Fatal("UA 头不一致")
}
if h["sec-ch-ua"] != p.SecCHUA {
t.Fatal("CH 头不一致")
}
}