|
@@ -64,19 +64,22 @@ func (m *mockUsers) UpdatePasswordLazyUpgrade(_ context.Context, uid, newHash st
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-type mockIdentities struct{ byTypeIdent map[string]map[string]*model.Identity }
|
|
|
|
|
|
|
+type mockIdentities struct{ byTypeIdentAppID map[string]map[string]map[string]*model.Identity }
|
|
|
|
|
|
|
|
func newMockIdentities() *mockIdentities {
|
|
func newMockIdentities() *mockIdentities {
|
|
|
- return &mockIdentities{byTypeIdent: map[string]map[string]*model.Identity{}}
|
|
|
|
|
|
|
+ return &mockIdentities{byTypeIdentAppID: map[string]map[string]map[string]*model.Identity{}}
|
|
|
}
|
|
}
|
|
|
-func (m *mockIdentities) add(typ, identifier string, it *model.Identity) {
|
|
|
|
|
- if m.byTypeIdent[typ] == nil {
|
|
|
|
|
- m.byTypeIdent[typ] = map[string]*model.Identity{}
|
|
|
|
|
|
|
+func (m *mockIdentities) add(typ, identifier, appid string, it *model.Identity) {
|
|
|
|
|
+ if m.byTypeIdentAppID[typ] == nil {
|
|
|
|
|
+ m.byTypeIdentAppID[typ] = map[string]map[string]*model.Identity{}
|
|
|
}
|
|
}
|
|
|
- m.byTypeIdent[typ][identifier] = it
|
|
|
|
|
|
|
+ if m.byTypeIdentAppID[typ][identifier] == nil {
|
|
|
|
|
+ m.byTypeIdentAppID[typ][identifier] = map[string]*model.Identity{}
|
|
|
|
|
+ }
|
|
|
|
|
+ m.byTypeIdentAppID[typ][identifier][appid] = it
|
|
|
}
|
|
}
|
|
|
-func (m *mockIdentities) GetByTypeIdentifier(_ context.Context, typ, identifier string) (*model.Identity, error) {
|
|
|
|
|
- it, ok := m.byTypeIdent[typ][identifier]
|
|
|
|
|
|
|
+func (m *mockIdentities) GetByTypeIdentifierAppID(_ context.Context, typ, identifier, appid string) (*model.Identity, error) {
|
|
|
|
|
+ it, ok := m.byTypeIdentAppID[typ][identifier][appid]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
return nil, apperrors.ErrNotFound
|
|
return nil, apperrors.ErrNotFound
|
|
|
}
|
|
}
|
|
@@ -230,14 +233,15 @@ func genRSAKey(t *testing.T) (string, []string) {
|
|
|
return privPEM, []string{pubPEM}
|
|
return privPEM, []string{pubPEM}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// addWechatUser 造一个用户 + wechat 身份(type=wechat, identifier=openid;扫码登录绑定用)。
|
|
|
|
|
|
|
+// addWechatUser 造一个用户 + wechat 身份(type=wechat, identifier=openid, appid=appid-test;扫码登录绑定用)。
|
|
|
|
|
+// v1.2:wechat 类型 appid 进唯一键,须与 WechatCampus 配置一致("appid-test")。
|
|
|
func (fx *fixture) addWechatUser(uid, openid string) {
|
|
func (fx *fixture) addWechatUser(uid, openid string) {
|
|
|
fx.t.Helper()
|
|
fx.t.Helper()
|
|
|
if fx.users.byUID[uid] == nil {
|
|
if fx.users.byUID[uid] == nil {
|
|
|
fx.users.byUID[uid] = &model.User{CanonicalUserID: uid, PersonType: model.PersonTypeStaff, Status: model.UserStatusActive}
|
|
fx.users.byUID[uid] = &model.User{CanonicalUserID: uid, PersonType: model.PersonTypeStaff, Status: model.UserStatusActive}
|
|
|
}
|
|
}
|
|
|
- fx.identities.add(model.IdentityTypeWechat, openid,
|
|
|
|
|
- &model.Identity{CanonicalUserID: uid, Type: model.IdentityTypeWechat, Identifier: openid, Verified: true})
|
|
|
|
|
|
|
+ fx.identities.add(model.IdentityTypeWechat, openid, "appid-test",
|
|
|
|
|
+ &model.Identity{CanonicalUserID: uid, Type: model.IdentityTypeWechat, Identifier: openid, AppID: "appid-test", Verified: true})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// addUser 造一个 argon2 用户 + username 身份(测试夹具快捷构造)。
|
|
// addUser 造一个 argon2 用户 + username 身份(测试夹具快捷构造)。
|
|
@@ -251,7 +255,7 @@ func (fx *fixture) addArgon2User(uid, username, password string) {
|
|
|
CanonicalUserID: uid, PersonType: model.PersonTypeStaff, Status: model.UserStatusActive,
|
|
CanonicalUserID: uid, PersonType: model.PersonTypeStaff, Status: model.UserStatusActive,
|
|
|
PasswordHash: &hash, HashVersion: ptr(model.HashVersionArgon2),
|
|
PasswordHash: &hash, HashVersion: ptr(model.HashVersionArgon2),
|
|
|
}
|
|
}
|
|
|
- fx.identities.add(model.IdentityTypeUsername, username,
|
|
|
|
|
|
|
+ fx.identities.add(model.IdentityTypeUsername, username, "",
|
|
|
&model.Identity{CanonicalUserID: uid, Type: model.IdentityTypeUsername, Identifier: username})
|
|
&model.Identity{CanonicalUserID: uid, Type: model.IdentityTypeUsername, Identifier: username})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -443,7 +447,7 @@ func TestLogin_Md5Salt_LazyUpgrade(t *testing.T) {
|
|
|
CanonicalUserID: uid, PersonType: model.PersonTypeStaff, Status: model.UserStatusActive,
|
|
CanonicalUserID: uid, PersonType: model.PersonTypeStaff, Status: model.UserStatusActive,
|
|
|
PasswordHash: &d, PasswordSalt: ptr(salt), HashVersion: ptr(model.HashVersionMd5Salt),
|
|
PasswordHash: &d, PasswordSalt: ptr(salt), HashVersion: ptr(model.HashVersionMd5Salt),
|
|
|
}
|
|
}
|
|
|
- fx.identities.add(model.IdentityTypeUsername, "testuser",
|
|
|
|
|
|
|
+ fx.identities.add(model.IdentityTypeUsername, "testuser", "",
|
|
|
&model.Identity{CanonicalUserID: uid, Type: model.IdentityTypeUsername, Identifier: "testuser"})
|
|
&model.Identity{CanonicalUserID: uid, Type: model.IdentityTypeUsername, Identifier: "testuser"})
|
|
|
fx.memberships.add(uid, orgmodel.Membership{
|
|
fx.memberships.add(uid, orgmodel.Membership{
|
|
|
MembershipID: 1, CanonicalUserID: uid, InstitutionID: 11, CampusID: 3,
|
|
MembershipID: 1, CanonicalUserID: uid, InstitutionID: 11, CampusID: 3,
|