fix: 对齐闲鱼消息连接与登录续期流程

对齐官方 WebSocket 竞速、连接级凭证、注册解码、控制状态与心跳时序。

持久化完整 Cookie Jar,修正请求作用域、删除、分区、加密、并发写回与错误路径。

统一启动续期、长登录开关和业务 MTOP 的原子更新,并补充回归与竞态测试。
This commit is contained in:
Christ committed 2026-07-22 19:33:33 +08:00
1 parent d77c317452
commit de9c12196f
59 files changed
+6170 -1247

No files matched your search

+30 -3
View File
@@ -3,6 +3,8 @@ package engine
import (
"testing"
"time"
"xianyu-go/internal/xianyu/cookierefresh"
)
func TestEffectiveTokenExpireAtUsesServerDeadlineWithSafetyMargin(t *testing.T) {
@@ -23,13 +25,38 @@ func TestEffectiveTokenExpireAtRejectsMissingOrExpiredDeadline(t *testing.T) {
}
}
func TestCredentialCookieFingerprintIsOrderIndependent(t *testing.T) {
func TestCredentialCookieFingerprintPreservesHeaderOrderAndDuplicates(t *testing.T) {
left := credentialCookieFingerprint("unb=1; cookie2=abc; _m_h5_tk=tk_1")
right := credentialCookieFingerprint("_m_h5_tk=tk_1; unb=1; cookie2=abc")
if left == "" || left != right {
t.Fatalf("fingerprints differ: %q != %q", left, right)
if left == "" || left == right {
t.Fatalf("Cookie Header 顺序变化必须改变指纹: %q == %q", left, right)
}
if left == credentialCookieFingerprint("unb=1; cookie2=changed; _m_h5_tk=tk_1") {
t.Fatal("credential change must alter fingerprint")
}
if left != credentialCookieFingerprint(" unb = 1 ; cookie2=abc;_m_h5_tk = tk_1 ;") {
t.Fatal("无语义空白不应改变指纹")
}
firstPathToken := credentialCookieFingerprint("_m_h5_tk=first; _m_h5_tk=second; unb=1")
secondPathToken := credentialCookieFingerprint("_m_h5_tk=second; _m_h5_tk=first; unb=1")
if firstPathToken == secondPathToken {
t.Fatal("同名 Cookie 的路径顺序会影响首值签名,不能折叠")
}
}
func TestCredentialStateFingerprintIncludesAuthoritativeSnapshot(t *testing.T) {
flat := "unb=1; _m_h5_tk=tk_1"
metadataA := cookierefresh.MetadataWithSnapshot("", []cookierefresh.BrowserCookie{
{Name: "_m_h5_tk", Value: "path-a", Domain: ".goofish.com", Path: "/"},
})
metadataB := cookierefresh.MetadataWithSnapshot("", []cookierefresh.BrowserCookie{
{Name: "_m_h5_tk", Value: "path-b", Domain: ".goofish.com", Path: "/"},
})
if credentialStateFingerprint(flat, metadataA) == credentialStateFingerprint(flat, metadataB) {
t.Fatal("权威 Jar 变化必须改变完整凭证指纹")
}
emptyJar := cookierefresh.MetadataWithSnapshot("", []cookierefresh.BrowserCookie{})
if credentialStateFingerprint("", emptyJar) == credentialStateFingerprint("", "") {
t.Fatal("权威空 Jar 必须与没有快照的历史状态区分")
}
}