-
Notifications
You must be signed in to change notification settings - Fork 977
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: persister query and setup more test data
- Loading branch information
Ajay Kelkar
committed
Feb 10, 2023
1 parent
8166ba1
commit 884e6d2
Showing
2 changed files
with
90 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -594,21 +594,46 @@ func TestPool(ctx context.Context, conf *config.Config, p interface { | |
}) | ||
|
||
t.Run("case=find identity by its credentials identifier", func(t *testing.T) { | ||
expected := passwordIdentity("", "[email protected]") | ||
expected.Traits = identity.Traits(`{}`) | ||
var expectedIdentifiers []string | ||
var expectedIdentities []*identity.Identity | ||
|
||
require.NoError(t, p.CreateIdentity(ctx, expected)) | ||
createdIDs = append(createdIDs, expected.ID) | ||
for _, c := range []identity.CredentialsType{ | ||
identity.CredentialsTypePassword, | ||
identity.CredentialsTypeOIDC, | ||
identity.CredentialsTypeWebAuthn, | ||
} { | ||
identityIdentifier := fmt.Sprintf("find-identity-by-identifier-%[email protected]", c) | ||
expected := identity.NewIdentity("") | ||
expected.SetCredentials(c, identity.Credentials{Type: c, Identifiers: []string{identityIdentifier}, Config: sqlxx.JSONRawMessage(`{}`)}) | ||
|
||
actual, err := p.FindByCredentialsIdentifier(ctx, "[email protected]") | ||
require.NoError(t, err) | ||
require.NoError(t, p.CreateIdentity(ctx, expected)) | ||
createdIDs = append(createdIDs, expected.ID) | ||
expectedIdentifiers = append(expectedIdentifiers, identityIdentifier) | ||
expectedIdentities = append(expectedIdentities, expected) | ||
} | ||
|
||
expected.Credentials = nil | ||
assertEqual(t, expected, actual) | ||
for c, ct := range []identity.CredentialsType{ | ||
identity.CredentialsTypePassword, | ||
identity.CredentialsTypeOIDC, | ||
identity.CredentialsTypeWebAuthn, | ||
} { | ||
t.Run(ct.String(), func(t *testing.T) { | ||
actual, err := p.FindByCredentialsIdentifier(ctx, expectedIdentifiers[c]) | ||
require.NoError(t, err) | ||
|
||
expected := expectedIdentities[c] | ||
assert.EqualValues(t, expected.Credentials[ct].ID, actual.Credentials[ct].ID) | ||
assert.EqualValues(t, expected.Credentials[ct].Identifiers, actual.Credentials[ct].Identifiers) | ||
|
||
expected.Credentials = nil | ||
actual.Credentials = nil | ||
assertEqual(t, expected, actual) | ||
}) | ||
} | ||
|
||
t.Run("not if on another network", func(t *testing.T) { | ||
_, p := testhelpers.NewNetwork(t, ctx, p) | ||
_, err := p.FindByCredentialsIdentifier(ctx, "[email protected]") | ||
_, err := p.FindByCredentialsIdentifier(ctx, "find-identity-by-identifier-password@ory.sh") | ||
require.ErrorIs(t, err, sqlcon.ErrNoRows) | ||
}) | ||
}) | ||
|
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