重构:完成架构一致性整改与生命周期收口

This commit is contained in:
Christ committed 2026-08-18 14:05:08 +08:00
1 parent 55904cc409
commit 9eb6be2875
344 files changed
+15961 -13926

No files matched your search

+17 -17
View File
@@ -6,15 +6,15 @@ import (
"xianyu-go/internal/xianyu/cookierefresh"
)
// TestCredentialCookieSnapshotUsesCurrentFlatCookieAsAuthority 负责TestCredential登录凭证SnapshotUsesCurrentFlat登录凭证AsAuthority相关处理。
// TestCredentialCookieSnapshotUsesCurrentFlatCookieAsAuthority 封装TestCredential登录凭证SnapshotUsesCurrentFlat登录凭证AsAuthority业务协调。
func TestCredentialCookieSnapshotUsesCurrentFlatCookieAsAuthority(t *testing.T) {
// existing 保存existing,供当前处理流程使用
// existing 用于本次流程后续判断的existing
existing := []cookierefresh.BrowserCookie{
{Name: "session", Value: "stale", Domain: ".goofish.com", Path: "/", Expires: 123, HTTPOnly: true, Secure: true, SameSite: "Lax"},
{Name: "removed", Value: "old", Domain: ".goofish.com", Path: "/", Secure: true},
{Name: "passport", Value: "keep", Domain: ".taobao.com", Path: "/", Secure: true},
}
// got 保存got,供当前处理流程使用
// got 用于本次流程后续判断的got
got := credentialCookieSnapshot(existing, map[string]string{
"session": "fresh",
"new": "value",
@@ -22,45 +22,45 @@ func TestCredentialCookieSnapshotUsesCurrentFlatCookieAsAuthority(t *testing.T)
if len(got) != 3 {
t.Fatalf("snapshot len=%d, want 3: %+v", len(got), got)
}
// byName 保存by名称,供当前处理流程使用
// byName 用于本次流程后续判断的by名称
byName := make(map[string]cookierefresh.BrowserCookie, len(got))
// cookie 表示当前遍历过程中的登录凭证
for _, cookie := range got {
byName[cookie.Name] = cookie
}
// session 保存会话,供当前处理流程使用
// session 用于本次流程后续判断的会话
session := byName["session"]
if session.Value != "fresh" || session.Expires != 123 || !session.HTTPOnly || session.SameSite != "Lax" {
t.Fatalf("existing attributes or fresh value were lost: %+v", session)
}
if // exists 保存exists,供当前处理流程使用
if // exists 用于本次流程后续判断的exists
_, exists := byName["removed"]; exists {
t.Fatalf("cookie absent from current flat value was resurrected: %+v", got)
}
if // passport 保存passport,供当前处理流程使用
if // passport 用于本次流程后续判断的passport
passport := byName["passport"]; passport.Value != "keep" || passport.Domain != ".taobao.com" {
t.Fatalf("out-of-scope cookie was lost: %+v", passport)
}
// added 保存added,供当前处理流程使用
// added 用于本次流程后续判断的added
added := byName["new"]
if added.Value != "value" || added.Domain != goofishDot || added.Path != "/" || !added.Secure {
t.Fatalf("new cookie defaults mismatch: %+v", added)
}
}
// TestCredentialCookieSnapshotPreservesAmbiguousSameNameScopes 负责TestCredential登录凭证SnapshotPreservesAmbiguousSame名称Scopes相关处理。
// TestCredentialCookieSnapshotPreservesAmbiguousSameNameScopes 封装TestCredential登录凭证SnapshotPreservesAmbiguousSame名称Scopes业务协调。
func TestCredentialCookieSnapshotPreservesAmbiguousSameNameScopes(t *testing.T) {
// existing 保存existing,供当前处理流程使用
// existing 用于本次流程后续判断的existing
existing := []cookierefresh.BrowserCookie{
{Name: "token", Value: "old-root", Domain: ".goofish.com", Path: "/"},
{Name: "token", Value: "old-im", Domain: "www.goofish.com", Path: "/im", HTTPOnly: true},
}
// got 保存got,供当前处理流程使用
// got 用于本次流程后续判断的got
got := credentialCookieSnapshot(existing, map[string]string{"token": "fresh"})
if len(got) != 2 {
t.Fatalf("same-name scoped cookies collapsed: %+v", got)
}
// values 保存values,供当前处理流程使用
// values 用于本次流程后续判断的values
values := map[string]string{}
// cookie 表示当前遍历过程中的登录凭证
for _, cookie := range got {
@@ -71,12 +71,12 @@ func TestCredentialCookieSnapshotPreservesAmbiguousSameNameScopes(t *testing.T)
}
}
// TestReconcileSnapshotWithCurrentCookie 负责TestReconcileSnapshotWithCurrent登录凭证相关处理。
// TestReconcileSnapshotWithCurrentCookie 封装TestReconcileSnapshotWithCurrent登录凭证业务协调。
func TestReconcileSnapshotWithCurrentCookie(t *testing.T) {
// snapshot 保存snapshot,供当前处理流程使用
// snapshot 用于本次流程后续判断的snapshot
snapshot := []cookierefresh.BrowserCookie{{Name: "session", Value: "old", Domain: ".goofish.com", Path: "/", Expires: 456}}
// got 保存got,供当前处理流程使用
// got 用于本次流程后续判断的got
got := reconcileSnapshotWithCurrentCookie(snapshot, "session=new", goofishIMURL)
if len(got) != 1 || got[0].Value != "new" || got[0].Expires != 456 {
t.Fatalf("flat cookie did not update snapshot without losing attributes: %+v", got)
@@ -91,13 +91,13 @@ func TestReconcileSnapshotWithCurrentCookie(t *testing.T) {
if got == nil || len(got) != 0 {
t.Fatalf("authoritative empty snapshot must not fall back to flat cookies: %#v", got)
}
if // got 保存got,供当前处理流程使用
if // got 用于本次流程后续判断的got
got := reconcileSnapshotWithCurrentCookie(nil, "session=legacy", goofishIMURL); got != nil {
t.Fatalf("missing snapshot should preserve the legacy flat-cookie fallback: %#v", got)
}
}
// TestSilentHasLoginURLMatcher 负责TestSilentHas登录URLMatcher相关处理。
// TestSilentHasLoginURLMatcher 封装TestSilentHas登录URLMatcher业务协调。
func TestSilentHasLoginURLMatcher(t *testing.T) {
if !isSilentHasLoginURL("https://passport.goofish.com/newlogin/silentHasLogin.do?appName=xianyu") {
t.Fatal("official silentHasLogin request was not recognized")