-
Notifications
You must be signed in to change notification settings - Fork 970
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
19 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 |
---|---|---|
|
@@ -466,29 +466,47 @@ func TestHandler(t *testing.T) { | |
}) | ||
|
||
t.Run("case=should be able to lookup the identity using identifier", func(t *testing.T) { | ||
i1 := &identity.Identity{ | ||
ident := &identity.Identity{ | ||
Credentials: map[identity.CredentialsType]identity.Credentials{ | ||
identity.CredentialsTypePassword: { | ||
Type: identity.CredentialsTypePassword, | ||
Identifiers: []string{"[email protected]"}, | ||
Config: sqlxx.JSONRawMessage(`{"hashed_password":"$2a$08$.cOYmAd.vCpDOoiVJrO5B.hjTLKQQ6cAK40u8uB.FnZDyPvVvQ9Q."}`), // foobar | ||
}, | ||
identity.CredentialsTypeOIDC: { | ||
Type: identity.CredentialsTypeOIDC, | ||
Identifiers: []string{"ProviderID:293b5d9b-1009-4600-a3e9-bd1845de22f2"}, | ||
Config: sqlxx.JSONRawMessage("{\"some\" : \"secret\"}"), | ||
}, | ||
}, | ||
State: identity.StateActive, | ||
Traits: identity.Traits(`{"username":"[email protected]"}`), | ||
} | ||
require.NoError(t, reg.PrivilegedIdentityPool().CreateIdentity(context.Background(), ident)) | ||
|
||
t.Run("type=password", func(t *testing.T) { | ||
res := get(t, adminTS, "/[email protected]", http.StatusOK) | ||
assert.EqualValues(t, ident.ID.String(), res.Get("0.id").String(), "%s", res.Raw) | ||
assert.EqualValues(t, "[email protected]", res.Get("0.traits.username").String(), "%s", res.Raw) | ||
assert.EqualValues(t, defaultSchemaExternalURL, res.Get("0.schema_url").String(), "%s", res.Raw) | ||
assert.EqualValues(t, config.DefaultIdentityTraitsSchemaID, res.Get("0.schema_id").String(), "%s", res.Raw) | ||
assert.EqualValues(t, identity.StateActive, res.Get("0.state").String(), "%s", res.Raw) | ||
assert.EqualValues(t, "password", res.Get("0.credentials.password.type").String(), res.Raw) | ||
assert.EqualValues(t, "1", res.Get("0.credentials.password.identifiers.#").String(), res.Raw) | ||
assert.EqualValues(t, "[email protected]", res.Get("0.credentials.password.identifiers.0").String(), res.Raw) | ||
}) | ||
|
||
require.NoError(t, reg.PrivilegedIdentityPool().CreateIdentity(context.Background(), i1)) | ||
|
||
res := get(t, adminTS, "/[email protected]", http.StatusOK) | ||
assert.EqualValues(t, i1.ID.String(), res.Get("0.id").String(), "%s", res.Raw) | ||
assert.EqualValues(t, "[email protected]", res.Get("0.traits.username").String(), "%s", res.Raw) | ||
assert.EqualValues(t, defaultSchemaExternalURL, res.Get("0.schema_url").String(), "%s", res.Raw) | ||
assert.EqualValues(t, config.DefaultIdentityTraitsSchemaID, res.Get("0.schema_id").String(), "%s", res.Raw) | ||
assert.EqualValues(t, identity.StateActive, res.Get("0.state").String(), "%s", res.Raw) | ||
assert.EqualValues(t, "password", res.Get("0.credentials.password.type").String(), res.Raw) | ||
assert.EqualValues(t, "1", res.Get("0.credentials.password.identifiers.#").String(), res.Raw) | ||
assert.EqualValues(t, "[email protected]", res.Get("0.credentials.password.identifiers.0").String(), res.Raw) | ||
t.Run("type=oidc", func(t *testing.T) { | ||
res := get(t, adminTS, "/identities?credentials_identifier=ProviderID:293b5d9b-1009-4600-a3e9-bd1845de22f2", http.StatusOK) | ||
assert.EqualValues(t, ident.ID.String(), res.Get("0.id").String(), "%s", res.Raw) | ||
assert.EqualValues(t, "[email protected]", res.Get("0.traits.username").String(), "%s", res.Raw) | ||
assert.EqualValues(t, defaultSchemaExternalURL, res.Get("0.schema_url").String(), "%s", res.Raw) | ||
assert.EqualValues(t, config.DefaultIdentityTraitsSchemaID, res.Get("0.schema_id").String(), "%s", res.Raw) | ||
assert.EqualValues(t, identity.StateActive, res.Get("0.state").String(), "%s", res.Raw) | ||
assert.EqualValues(t, "oidc", res.Get("0.credentials.oidc.type").String(), res.Raw) | ||
assert.EqualValues(t, "1", res.Get("0.credentials.oidc.identifiers.#").String(), res.Raw) | ||
assert.EqualValues(t, "ProviderID:293b5d9b-1009-4600-a3e9-bd1845de22f2", res.Get("0.credentials.oidc.identifiers.0").String(), res.Raw) | ||
}) | ||
}) | ||
|
||
t.Run("case=should get oidc credential", func(t *testing.T) { | ||
|
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 |
---|---|---|
|
@@ -771,7 +771,7 @@ func TestPool(ctx context.Context, conf *config.Config, p persistence.Persister, | |
Expand: identity.ExpandCredentials, | ||
}) | ||
require.NoError(t, err) | ||
assert.Len(t, actual, 3) | ||
assert.Len(t, actual, 4) // webauthn, common, password, oidc | ||
|
||
outer: | ||
for _, e := range append(expectedIdentities[:2], create) { | ||
|
@@ -789,13 +789,13 @@ func TestPool(ctx context.Context, conf *config.Config, p persistence.Persister, | |
} | ||
}) | ||
|
||
t.Run("only webauthn and password", func(t *testing.T) { | ||
t.Run("find by OIDC identifier", func(t *testing.T) { | ||
actual, next, err := p.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
CredentialsIdentifier: "[email protected]", | ||
Expand: identity.ExpandEverything, | ||
}) | ||
require.NoError(t, err) | ||
assert.Len(t, actual, 0) | ||
assert.Len(t, actual, 1) | ||
assert.True(t, next.IsLast()) | ||
}) | ||
|
||
|
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