阶段十:完成非冻结 Browser 注释基线清零
This commit is contained in:
1 parent
a45a82a149
commit
393c45a1e3
22 files changed
+684
-4177
No files matched your search
@@ -6,12 +6,15 @@ import (
|
||||
"xianyu-go/internal/xianyu/cookierefresh"
|
||||
)
|
||||
|
||||
// TestCredentialCookieSnapshotUsesCurrentFlatCookieAsAuthority 负责TestCredential登录凭证SnapshotUsesCurrentFlat登录凭证AsAuthority相关处理。
|
||||
func TestCredentialCookieSnapshotUsesCurrentFlatCookieAsAuthority(t *testing.T) {
|
||||
// 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 := credentialCookieSnapshot(existing, map[string]string{
|
||||
"session": "fresh",
|
||||
"new": "value",
|
||||
@@ -19,36 +22,47 @@ func TestCredentialCookieSnapshotUsesCurrentFlatCookieAsAuthority(t *testing.T)
|
||||
if len(got) != 3 {
|
||||
t.Fatalf("snapshot len=%d, want 3: %+v", len(got), got)
|
||||
}
|
||||
// byName 保存by名称,供当前处理流程使用
|
||||
byName := make(map[string]cookierefresh.BrowserCookie, len(got))
|
||||
// cookie 表示当前遍历过程中的登录凭证
|
||||
for _, cookie := range got {
|
||||
byName[cookie.Name] = cookie
|
||||
}
|
||||
// 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 := byName["removed"]; exists {
|
||||
if // exists 保存exists,供当前处理流程使用
|
||||
_, exists := byName["removed"]; exists {
|
||||
t.Fatalf("cookie absent from current flat value was resurrected: %+v", got)
|
||||
}
|
||||
if passport := byName["passport"]; passport.Value != "keep" || passport.Domain != ".taobao.com" {
|
||||
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 := 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相关处理。
|
||||
func TestCredentialCookieSnapshotPreservesAmbiguousSameNameScopes(t *testing.T) {
|
||||
// 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 := credentialCookieSnapshot(existing, map[string]string{"token": "fresh"})
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("same-name scoped cookies collapsed: %+v", got)
|
||||
}
|
||||
// values 保存values,供当前处理流程使用
|
||||
values := map[string]string{}
|
||||
// cookie 表示当前遍历过程中的登录凭证
|
||||
for _, cookie := range got {
|
||||
values[cookie.Path] = cookie.Value
|
||||
}
|
||||
@@ -57,9 +71,12 @@ func TestCredentialCookieSnapshotPreservesAmbiguousSameNameScopes(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
// TestReconcileSnapshotWithCurrentCookie 负责TestReconcileSnapshotWithCurrent登录凭证相关处理。
|
||||
func TestReconcileSnapshotWithCurrentCookie(t *testing.T) {
|
||||
// snapshot 保存snapshot,供当前处理流程使用
|
||||
snapshot := []cookierefresh.BrowserCookie{{Name: "session", Value: "old", Domain: ".goofish.com", Path: "/", Expires: 456}}
|
||||
|
||||
// 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)
|
||||
@@ -74,11 +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 := reconcileSnapshotWithCurrentCookie(nil, "session=legacy", goofishIMURL); got != nil {
|
||||
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相关处理。
|
||||
func TestSilentHasLoginURLMatcher(t *testing.T) {
|
||||
if !isSilentHasLoginURL("https://passport.goofish.com/newlogin/silentHasLogin.do?appName=xianyu") {
|
||||
t.Fatal("official silentHasLogin request was not recognized")
|
||||
|
||||
Reference in new issue
Block a user