Răsfoiți Sursa

fix(identity e2e): seedWechatUser 补 AppID 对齐 v1.2 唯一键

v1.2 把 t_identity 唯一键扩成 (type,identifier,appid),wechat_service
callback 改传 campus.AppID 查询。但 TestWechatE2E 的 seedWechatUser
只落 AppID 零值 "",而 WechatCampus 配 AppID="appid-e2e",callback
按 appid=appid-e2e 查不到 appid="" 的种子行 → 误返 unbound。

go test ./... -short 跳过 e2e(无 UNIFIED_TEST_DSN),上轮 commit 门禁
未捕获,跑真库 e2e 才暴露。修复:e2eApp 增 wechatAppID 字段(=campus
AppID),seedWechatUser 用它给 wechat 身份补 AppID,使 seed 与 campus
配置一致。

门禁:build/vet/short 全绿;真库 e2e(infra/db reconcile + identity
handler 全链路 + org handler + identity repo)逐包 -p 1 串行跑 PASS
(并行跑会因共享 e2e_test 表建/删竞态误报,非代码缺陷)。
Q 2 zile în urmă
părinte
comite
665e7eb479
1 a modificat fișierele cu 11 adăugiri și 8 ștergeri
  1. 11 8
      internal/identity/handler/login_e2e_test.go

+ 11 - 8
internal/identity/handler/login_e2e_test.go

@@ -52,12 +52,13 @@ func e2eDSNOrSkip(t *testing.T) string {
 
 // e2eApp 端到端测试句柄(真库 + 真仓储 + miniredis + 真 Issuer + 路由应用)。
 type e2eApp struct {
-	t          *testing.T
-	app        *fiber.App
-	pubKeys    []string
-	revocation *appredis.RevocationStore
-	gdb        *gorm.DB
-	wechat     *fakeWechat // 微信扫码打桩(code→openid 映射;供 TestWechatE2E 配置)
+	t           *testing.T
+	app         *fiber.App
+	pubKeys     []string
+	revocation  *appredis.RevocationStore
+	gdb         *gorm.DB
+	wechat      *fakeWechat // 微信扫码打桩(code→openid 映射;供 TestWechatE2E 配置)
+	wechatAppID string     // WechatCampus 配置的 appid(v1.2:t_identity 唯一键含 appid,seed 须与之一致)
 }
 
 // e2eSetup 建真库 + AutoMigrate 4 表 + 真仓储 + miniredis + 真 Issuer + AuthService + Handler + 路由应用。
@@ -111,9 +112,10 @@ func e2eSetup(t *testing.T) *e2eApp {
 	}
 	// 微信扫码登录服务(真库 identities 仓储 + miniredis 双 store + 打桩 wechat.Client)
 	fw := &fakeWechat{byCode: map[string]string{}}
+	const wechatAppID = "appid-e2e" // v1.2:t_identity 唯一键 (type,identifier,appid);seed 的 wechat 身份 appid 须与此一致
 	ws, err := service.NewWechatService(service.WechatConfig{
 		Client: fw, States: wxStates, Tickets: tickets, Identities: identities, Memberships: memberships,
-		Campuses:    []service.WechatCampus{{CampusID: 3, AppID: "appid-e2e", Secret: "secret-e2e"}},
+		Campuses:    []service.WechatCampus{{CampusID: 3, AppID: wechatAppID, Secret: "secret-e2e"}},
 		CallbackURL: "https://unified.test/auth/wechat/callback",
 	})
 	if err != nil {
@@ -140,7 +142,7 @@ func e2eSetup(t *testing.T) *e2eApp {
 	auth.Get("/me", h.Me)
 	auth.Post("/logout", h.Logout)
 
-	return &e2eApp{t: t, app: app, pubKeys: pubKeys, revocation: revocation, gdb: gdb, wechat: fw}
+	return &e2eApp{t: t, app: app, pubKeys: pubKeys, revocation: revocation, gdb: gdb, wechat: fw, wechatAppID: wechatAppID}
 }
 
 // seedUser 落一个 argon2 用户 + username 身份 + 一条 membership(raw SQL 保证 created_at 确定)。
@@ -351,6 +353,7 @@ func (a *e2eApp) seedWechatUser(openid string, inst, campus int64, role string)
 	}
 	if err := a.gdb.WithContext(ctx).Create(&model.Identity{
 		CanonicalUserID: uid, Type: model.IdentityTypeWechat, Identifier: openid,
+		AppID: a.wechatAppID, // v1.2:唯一键含 appid,须与 WechatCampus 配置一致
 		Verified: true, CreatedAt: now,
 	}).Error; err != nil {
 		a.t.Fatalf("插入 t_identity(wechat): %v", err)