fix(续期): 支持 Linux Docker 静默自动续期
This commit is contained in:
1 parent
8fdc25483f
commit
9e4e4bcee9
5 files changed
+40
-10
No files matched your search
@@ -386,13 +386,6 @@ func (s Service) RenewAPIFirst(ctx context.Context, cookiesStr string, snapshots
|
||||
result.NeedPasswordLogin = true
|
||||
return result, nil
|
||||
}
|
||||
if ua := strings.ToLower(xianyu.CurrentBrowserFingerprint().UserAgent); ua != "" &&
|
||||
!strings.Contains(ua, "windows") && !strings.Contains(ua, "macintosh") {
|
||||
result.Skipped = true
|
||||
result.SkipReason = "unsupported_desktop_ua"
|
||||
result.Message = autoLoginSkipMessage(result.SkipReason)
|
||||
return result, nil
|
||||
}
|
||||
mode, skipReason := autoLoginMode(firstCookieValues(decisionCookies), now)
|
||||
if skipReason != "" {
|
||||
result.Skipped = true
|
||||
@@ -551,8 +544,6 @@ func autoLoginSkipMessage(reason string) string {
|
||||
return "sdkSilent 疲劳窗口内,跳过静默续期"
|
||||
case "long_login_expired":
|
||||
return "长登录凭证已过期,静默续期不应发起请求"
|
||||
case "unsupported_desktop_ua":
|
||||
return "官网静默续期仅支持 Windows 或 macOS 桌面浏览器"
|
||||
default:
|
||||
return "无需静默续期"
|
||||
}
|
||||
|
||||
@@ -48,6 +48,20 @@ func useTestDesktopFingerprint(t *testing.T) xianyu.BrowserFingerprint {
|
||||
return fingerprint
|
||||
}
|
||||
|
||||
func useTestLinuxFingerprint(t *testing.T) xianyu.BrowserFingerprint {
|
||||
t.Helper()
|
||||
old := xianyu.CurrentBrowserFingerprint()
|
||||
fingerprint := xianyu.BrowserFingerprint{
|
||||
UserAgent: `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36`,
|
||||
SecChUA: `"Chromium";v="138", "Not_A Brand";v="24"`,
|
||||
Platform: "Linux",
|
||||
Mobile: "?0",
|
||||
}
|
||||
xianyu.SetBrowserFingerprint(fingerprint)
|
||||
t.Cleanup(func() { xianyu.SetBrowserFingerprint(old) })
|
||||
return fingerprint
|
||||
}
|
||||
|
||||
func TestAutoLoginModeMatchesBrowserPlugin(t *testing.T) {
|
||||
now := time.Now()
|
||||
tests := []struct {
|
||||
@@ -319,6 +333,27 @@ func TestRenewAPIFirstUsesBrowserCookieScopes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenewAPIFirstRunsWithLinuxChromiumFingerprint(t *testing.T) {
|
||||
fingerprint := useTestLinuxFingerprint(t)
|
||||
var calls atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
calls.Add(1)
|
||||
if got := r.Header.Get("User-Agent"); got != fingerprint.UserAgent {
|
||||
t.Fatalf("User-Agent=%q", got)
|
||||
}
|
||||
if got := r.Header.Get("sec-ch-ua-platform"); got != `"Linux"` {
|
||||
t.Fatalf("sec-ch-ua-platform=%q", got)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"data":{"content":{"data":{"processFinished":true,"resultCode":100}}}}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
svc := Service{HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1}
|
||||
res, err := svc.RenewAPIFirst(context.Background(), "havana_lgc_exp="+futureMillis(time.Hour))
|
||||
if err != nil || res == nil || !res.Success || res.Skipped || res.RequestCount != 1 || calls.Load() != 1 {
|
||||
t.Fatalf("result=%+v calls=%d err=%v", res, calls.Load(), err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenewAPIFirstUsesTopSiteAndAppliesPartitionedSetCookie(t *testing.T) {
|
||||
useTestDesktopFingerprint(t)
|
||||
snapshot := []cookierefresh.BrowserCookie{
|
||||
|
||||
Reference in new issue
Block a user