-
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.
Merge branch 'master' into jonas-jonas/fix/patchMetadata
- Loading branch information
Showing
14 changed files
with
303 additions
and
34 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
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 |
---|---|---|
|
@@ -375,6 +375,36 @@ func TestHandler(t *testing.T) { | |
} | ||
}) | ||
|
||
t.Run("case=should return an empty array on a failed lookup with identifier", func(t *testing.T) { | ||
res := get(t, adminTS, "/identities?credentials_identifier=find.by.non.existing.identifier@bar.com", http.StatusOK) | ||
assert.EqualValues(t, int64(0), res.Get("#").Int(), "%s", res.Raw) | ||
}) | ||
|
||
t.Run("case=should be able to lookup the identity using identifier", func(t *testing.T) { | ||
i1 := &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 | ||
}}, | ||
State: identity.StateActive, | ||
Traits: identity.Traits(`{"username":"[email protected]"}`), | ||
} | ||
|
||
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("case=should get oidc credential", func(t *testing.T) { | ||
id := createOidcIdentity(t, "[email protected]", "access_token", "refresh_token", "id_token", true) | ||
for name, ts := range map[string]*httptest.Server{"public": publicTS, "admin": adminTS} { | ||
|
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 |
---|---|---|
|
@@ -113,7 +113,7 @@ func TestPool(ctx context.Context, conf *config.Config, p interface { | |
}) | ||
|
||
t.Run("list", func(t *testing.T) { | ||
actual, err := p.ListIdentities(ctx, expand, 0, 10) | ||
actual, err := p.ListIdentities(ctx, identity.ListIdentityParameters{Expand: expand, Page: 0, PerPage: 10}) | ||
require.NoError(t, err) | ||
require.Len(t, actual, 1) | ||
assertion(t, &actual[0]) | ||
|
@@ -569,7 +569,7 @@ func TestPool(ctx context.Context, conf *config.Config, p interface { | |
}) | ||
|
||
t.Run("case=list", func(t *testing.T) { | ||
is, err := p.ListIdentities(ctx, identity.ExpandDefault, 0, 25) | ||
is, err := p.ListIdentities(ctx, identity.ListIdentityParameters{Expand: identity.ExpandDefault, Page: 0, PerPage: 25}) | ||
require.NoError(t, err) | ||
assert.Len(t, is, len(createdIDs)) | ||
for _, id := range createdIDs { | ||
|
@@ -587,13 +587,81 @@ func TestPool(ctx context.Context, conf *config.Config, p interface { | |
|
||
t.Run("no results on other network", func(t *testing.T) { | ||
_, p := testhelpers.NewNetwork(t, ctx, p) | ||
is, err := p.ListIdentities(ctx, identity.ExpandDefault, 0, 25) | ||
is, err := p.ListIdentities(ctx, identity.ListIdentityParameters{Expand: identity.ExpandDefault, Page: 0, PerPage: 25}) | ||
require.NoError(t, err) | ||
assert.Len(t, is, 0) | ||
}) | ||
}) | ||
|
||
t.Run("case=find identity by its credentials identifier", func(t *testing.T) { | ||
var expectedIdentifiers []string | ||
var expectedIdentities []*identity.Identity | ||
|
||
for _, c := range []identity.CredentialsType{ | ||
identity.CredentialsTypePassword, | ||
identity.CredentialsTypeWebAuthn, | ||
identity.CredentialsTypeOIDC, | ||
} { | ||
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(`{}`)}) | ||
|
||
require.NoError(t, p.CreateIdentity(ctx, expected)) | ||
createdIDs = append(createdIDs, expected.ID) | ||
expectedIdentifiers = append(expectedIdentifiers, identityIdentifier) | ||
expectedIdentities = append(expectedIdentities, expected) | ||
} | ||
|
||
actual, err := p.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
Expand: identity.ExpandEverything, | ||
}) | ||
require.NoError(t, err) | ||
require.True(t, len(actual) > 0) | ||
|
||
for c, ct := range []identity.CredentialsType{ | ||
identity.CredentialsTypePassword, | ||
identity.CredentialsTypeWebAuthn, | ||
} { | ||
t.Run(ct.String(), func(t *testing.T) { | ||
actual, err := p.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
// Match is normalized | ||
CredentialsIdentifier: expectedIdentifiers[c], | ||
}) | ||
require.NoError(t, err) | ||
|
||
expected := expectedIdentities[c] | ||
require.Len(t, actual, 1) | ||
assertx.EqualAsJSONExcept(t, expected, actual[0], []string{"credentials.config", "created_at", "updated_at", "state_changed_at"}) | ||
}) | ||
} | ||
|
||
t.Run("only webauthn and password", func(t *testing.T) { | ||
actual, err := p.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
CredentialsIdentifier: "[email protected]", | ||
}) | ||
require.NoError(t, err) | ||
assert.Len(t, actual, 0) | ||
}) | ||
|
||
t.Run("non existing identifier", func(t *testing.T) { | ||
actual, err := p.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
CredentialsIdentifier: "[email protected]", | ||
}) | ||
require.NoError(t, err) | ||
assert.Len(t, actual, 0) | ||
}) | ||
|
||
t.Run("not if on another network", func(t *testing.T) { | ||
_, on := testhelpers.NewNetwork(t, ctx, p) | ||
actual, err := on.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
CredentialsIdentifier: expectedIdentifiers[0], | ||
}) | ||
require.NoError(t, err) | ||
assert.Len(t, actual, 0) | ||
}) | ||
}) | ||
|
||
t.Run("case=find identity by its credentials type and identifier", func(t *testing.T) { | ||
expected := passwordIdentity("", "[email protected]") | ||
expected.Traits = identity.Traits(`{}`) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.