将账号、认证、管理员、分析、自动化、卡券、聊天、商品、关键词、设置和订单能力迁移到 application 与 adapter,删除 Server 内对应的旧仓储和业务服务实现,并收紧架构检查。 完善批量发布与订单刷新生命周期、凭证写回、账号任务补偿、订单 reconciliation、通知和敏感数据边界;补充正常、失败、取消、并发、越权及多方言回归测试,并修正 MySQL 延迟任务表的 InnoDB 配置。 修复空卡密响应为 null 时前端加载失败的问题,重建嵌入式前端资产;重写重构总计划,清除历史流水并明确阶段 1 至 10 各对应一次完整迭代和一个 PR。 验证:make check;make test-server-race;npm test/typecheck/comments:check/build;Docker SQLite/MySQL 8.4/PostgreSQL 17 TestMultiDB_*。
36 lines
1.5 KiB
Go
36 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"xianyu-go/internal/auth"
|
|
"xianyu-go/internal/db"
|
|
)
|
|
|
|
// TestRequireCookieOwnerSkipsLoginSecret 验证账号所有权校验不依赖登录密码密文。
|
|
func TestRequireCookieOwnerSkipsLoginSecret(t *testing.T) {
|
|
// srv、store 和 cleanup 分别保存测试服务器、数据库和资源清理函数。
|
|
srv, store, cleanup := newTestServer(t)
|
|
defer cleanup()
|
|
// ctx 是本测试共用的数据库上下文。
|
|
ctx := context.Background()
|
|
// _, updateErr 表示将登录密码替换为损坏密文的数据库操作结果;所有权摘要不应读取该字段。
|
|
if _, updateErr := store.DB.ExecContext(ctx,
|
|
`UPDATE cookies SET password=? WHERE id=?`, "not-a-password-ciphertext", "acc1"); updateErr != nil {
|
|
t.Fatalf("损坏登录密码密文失败: %v", updateErr)
|
|
}
|
|
// request 是携带默认测试用户会话的所有权请求。
|
|
request := httptest.NewRequest(http.MethodGet, "/cookies/acc1", nil)
|
|
request = request.WithContext(auth.WithSession(request.Context(), &db.Session{UserID: 1}))
|
|
// recorder 捕获所有权辅助函数可能写入的 HTTP 错误响应。
|
|
recorder := httptest.NewRecorder()
|
|
// detail、owned 表示所有权校验返回的非敏感应用摘要及校验结果。
|
|
detail, owned := srv.requireCookieOwner(recorder, request, "acc1")
|
|
if !owned || detail.ID != "acc1" || detail.UserID != 1 {
|
|
t.Fatalf("detail=%+v owned=%v status=%d body=%s", detail, owned, recorder.Code, recorder.Body.String())
|
|
}
|
|
}
|