-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc: return an error if email already used
- Loading branch information
Showing
3 changed files
with
46 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,28 +107,15 @@ func TestRPC_RegisterSession(t *testing.T) { | |
}, | ||
"WithVerifiedEmail": { | ||
tokBuilderFn: func(b *jwt.Builder, url string) { | ||
b.Claim("email", "user@example.com"). | ||
b.Claim("email", "123@example.com"). | ||
Claim("email_verified", "true"). | ||
Claim("sequence:session_hash", sessHash) | ||
}, | ||
assertFn: func(t *testing.T, sess *proto.Session, err error, p assertionParams) { | ||
require.NoError(t, err) | ||
require.NotNil(t, sess) | ||
|
||
assert.Equal(t, "[email protected]", sess.Identity.Email) | ||
}, | ||
}, | ||
"WithUnverifiedEmail": { | ||
tokBuilderFn: func(b *jwt.Builder, url string) { | ||
b.Claim("email", "[email protected]"). | ||
Claim("email_verified", "false"). | ||
Claim("sequence:session_hash", sessHash) | ||
}, | ||
assertFn: func(t *testing.T, sess *proto.Session, err error, p assertionParams) { | ||
require.NoError(t, err) | ||
require.NotNil(t, sess) | ||
|
||
assert.Equal(t, "", sess.Identity.Email) | ||
assert.Equal(t, "[email protected]", sess.Identity.Email) | ||
}, | ||
}, | ||
"MissingSignature": { | ||
|
@@ -159,6 +146,36 @@ func TestRPC_RegisterSession(t *testing.T) { | |
assert.Equal(t, httpsIssuer, sess.Identity.Issuer) | ||
}, | ||
}, | ||
"EmailAlreadyInUse": { | ||
tokBuilderFn: func(b *jwt.Builder, url string) { | ||
b.Claim("email", "[email protected]"). | ||
Claim("sequence:session_hash", sessHash) | ||
}, | ||
assertFn: func(t *testing.T, sess *proto.Session, err error, p assertionParams) { | ||
assert.ErrorIs(t, err, proto.ErrEmailAlreadyInUse) | ||
assert.Nil(t, sess) | ||
}, | ||
}, | ||
"EmailAlreadyInUseWithForceCreateAccount": { | ||
intentBuilderFn: func(t *testing.T, data intents.IntentDataOpenSession) *proto.Intent { | ||
data.ForceCreateAccount = true | ||
return generateSignedIntent(t, intents.IntentName_openSession, data, signingSession) | ||
}, | ||
tokBuilderFn: func(b *jwt.Builder, url string) { | ||
b.Claim("email", "[email protected]"). | ||
Claim("sequence:session_hash", sessHash) | ||
}, | ||
assertFn: func(t *testing.T, sess *proto.Session, err error, p assertionParams) { | ||
require.NoError(t, err) | ||
require.NotNil(t, sess) | ||
|
||
assert.Len(t, p.dbClient.accounts[p.tenant.ProjectID], 2) | ||
assert.Contains(t, p.dbClient.sessions, sess.ID) | ||
assert.Contains(t, p.dbClient.accounts[p.tenant.ProjectID], sess.Identity.String()) | ||
assert.Contains(t, p.walletService.registeredSessions, sess.ID) | ||
assert.Contains(t, p.walletService.registeredUsers, sess.UserID) | ||
}, | ||
}, | ||
} | ||
|
||
for label, testCase := range testCases { | ||
|
@@ -180,11 +197,14 @@ func TestRPC_RegisterSession(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
tenant, _ := newTenant(t, enc, issuer) | ||
account := newAccount(t, enc, "http://another-issuer", nil) | ||
|
||
dbClient := &dbMock{ | ||
sessions: map[string]*data.Session{}, | ||
tenants: map[uint64][]*data.Tenant{tenant.ProjectID: {tenant}}, | ||
accounts: map[uint64]map[string]*data.Account{}, | ||
accounts: map[uint64]map[string]*data.Account{ | ||
tenant.ProjectID: {account.Identity.String(): account}, | ||
}, | ||
} | ||
svc := initRPC(cfg, enc, dbClient) | ||
walletService := newWalletServiceMock(nil) | ||
|