|
@@ -52,12 +52,13 @@ func e2eDSNOrSkip(t *testing.T) string {
|
|
|
|
|
|
|
|
// e2eApp 端到端测试句柄(真库 + 真仓储 + miniredis + 真 Issuer + 路由应用)。
|
|
// e2eApp 端到端测试句柄(真库 + 真仓储 + miniredis + 真 Issuer + 路由应用)。
|
|
|
type e2eApp struct {
|
|
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 + 路由应用。
|
|
// e2eSetup 建真库 + AutoMigrate 4 表 + 真仓储 + miniredis + 真 Issuer + AuthService + Handler + 路由应用。
|
|
@@ -111,9 +112,10 @@ func e2eSetup(t *testing.T) *e2eApp {
|
|
|
}
|
|
}
|
|
|
// 微信扫码登录服务(真库 identities 仓储 + miniredis 双 store + 打桩 wechat.Client)
|
|
// 微信扫码登录服务(真库 identities 仓储 + miniredis 双 store + 打桩 wechat.Client)
|
|
|
fw := &fakeWechat{byCode: map[string]string{}}
|
|
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{
|
|
ws, err := service.NewWechatService(service.WechatConfig{
|
|
|
Client: fw, States: wxStates, Tickets: tickets, Identities: identities, Memberships: memberships,
|
|
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",
|
|
CallbackURL: "https://unified.test/auth/wechat/callback",
|
|
|
})
|
|
})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -140,7 +142,7 @@ func e2eSetup(t *testing.T) *e2eApp {
|
|
|
auth.Get("/me", h.Me)
|
|
auth.Get("/me", h.Me)
|
|
|
auth.Post("/logout", h.Logout)
|
|
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 确定)。
|
|
// 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{
|
|
if err := a.gdb.WithContext(ctx).Create(&model.Identity{
|
|
|
CanonicalUserID: uid, Type: model.IdentityTypeWechat, Identifier: openid,
|
|
CanonicalUserID: uid, Type: model.IdentityTypeWechat, Identifier: openid,
|
|
|
|
|
+ AppID: a.wechatAppID, // v1.2:唯一键含 appid,须与 WechatCampus 配置一致
|
|
|
Verified: true, CreatedAt: now,
|
|
Verified: true, CreatedAt: now,
|
|
|
}).Error; err != nil {
|
|
}).Error; err != nil {
|
|
|
a.t.Fatalf("插入 t_identity(wechat): %v", err)
|
|
a.t.Fatalf("插入 t_identity(wechat): %v", err)
|