From 0cd41090149c3e0563c058a876baa5f260e122da Mon Sep 17 00:00:00 2001 From: Christ Date: Fri, 14 Aug 2026 12:21:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=EF=BC=9A=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E9=80=9A=E7=94=A8=20Cookie=20=E5=8D=95=E5=80=BC?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/architecture/refactoring-master-plan.md | 3 ++- internal/automation/center.go | 4 ++-- internal/automation/center_test.go | 23 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index 0d33c51..d2a0a84 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -114,7 +114,8 @@ app shell / routes - 已完成阶段 2 后续切片:`internal/renewal/scheduler.go` 已改用 `RenewalRuntimeAccount` 窄模型及按账号重读接口,只解密 Cookie、续期 metadata 和启用状态,不再把登录密码/用户名带入续期调度器; - 已完成阶段 2 后续切片:`internal/automation/account_tasks.go` 的 Session 阻断指纹已改用 `GetCookieRuntimeData`,只读取 Cookie 与 metadata,不再解密完整账号详情; - 已完成阶段 2 后续切片:`internal/automation/center.go` 的确认发货流程已改用 `GetCookieRuntimeData`,只读取 Cookie 与 metadata,保留凭证锁、Cookie Jar 和重试行为; -- 下一最小工作项:将 `internal/automation/center.go` 的通用 `cookieValue` 回退读取迁移到已有的单值 `GetValue` 接口,继续清除完整详情读取; +- 已完成阶段 2 后续切片:`internal/automation/center.go` 的通用 `cookieValue` 回退读取已迁移到 `GetValue`,Automation 生产代码不再直接读取完整账号详情; +- 下一最小工作项:为 `internal/engine/account.go` 的登录态检查流程建立 Cookie/metadata 窄读取,先处理 `tryLoginStatusCheck`,不改变重试和续期行为; - 随后工作项:再处理 Engine、Automation 等明确需要平台凭证的流程,统一使用按账号 ID 过滤的单值凭证接口; - 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。 diff --git a/internal/automation/center.go b/internal/automation/center.go index 02b8a55..b06a0cf 100644 --- a/internal/automation/center.go +++ b/internal/automation/center.go @@ -1154,11 +1154,11 @@ func (c *Center) cookieValue(ctx context.Context, cookieID string) (string, erro if c.cookieSrc != nil { return c.cookieSrc(ctx, cookieID) } - d, err := c.store.Cookies.GetDetails(ctx, cookieID) + value, err := c.store.Cookies.GetValue(ctx, cookieID) // value 是只读取账号 Cookie 明文的单值结果,不会展开完整账号详情。 if err != nil { return "", err } - return d.Value, nil + return value, nil } func (c *Center) markEventFacts(ctx context.Context, task Task) error { diff --git a/internal/automation/center_test.go b/internal/automation/center_test.go index 9193534..207d666 100644 --- a/internal/automation/center_test.go +++ b/internal/automation/center_test.go @@ -1317,3 +1317,26 @@ func TestReviewRequestCounterFailureMovesCompletedActionToNeedsReview(t *testing t.Fatalf("status=%q message=%q", status, message) } } + +// TestCookieValueFallbackUsesSingleValueQuery 验证订单详情补全的 Cookie 回退不会读取登录密码等完整账号字段。 +func TestCookieValueFallbackUsesSingleValueQuery(t *testing.T) { + t.Setenv("XIANYU_DATA_KEY", "cookie-value-fallback-key") + // store 是当前测试使用的 SQLite repository 聚合器。 + store, cleanup := newAutomationTestStore(t) + defer cleanup() + // ctx 是测试数据库操作共用的上下文。 + ctx := context.Background() + // corruptErr 表示写入故意损坏的登录密码失败的原因。 + if _, corruptErr := store.DB.ExecContext(ctx, + `UPDATE cookies SET username=?,password=? WHERE id=?`, + "fallback-user", "not-a-password-ciphertext", "cid"); corruptErr != nil { + t.Fatalf("corrupt password: %v", corruptErr) + } + // center 是待验证 Cookie 回退读取逻辑的自动化中心。 + center := New(store, nil, nil) + // value 是单值查询返回的 Cookie 明文。 + value, valueErr := center.cookieValue(ctx, "cid") + if valueErr != nil || value != "unb=123; _m_h5_tk=tk_1;" { + t.Fatalf("cookieValue value=%q err=%v", value, valueErr) + } +}