-
-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: parse UUID, add tests and index
- Loading branch information
1 parent
5cfbf66
commit 23670e5
Showing
4 changed files
with
62 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1457,6 +1457,44 @@ func TestHandler(t *testing.T) { | |
} | ||
}) | ||
|
||
t.Run("organizations", func(t *testing.T) { | ||
t.Run("case=should list organization identities", func(t *testing.T) { | ||
for name, ts := range map[string]*httptest.Server{"admin": adminTS} { | ||
t.Run("endpoint="+name, func(t *testing.T) { | ||
orgID := uuid.Must(uuid.NewV4()) | ||
email := x.NewUUID().String() + "@ory.sh" | ||
reg.IdentityManager().Create(ctx, &identity.Identity{ | ||
Traits: identity.Traits(`{"email":"` + email + `"}`), | ||
OrganizationID: uuid.NullUUID{UUID: orgID, Valid: true}, | ||
}) | ||
|
||
res := get(t, ts, "/identities?organization_id="+orgID.String(), http.StatusOK) | ||
assert.Len(t, res.Array(), 1) | ||
assert.EqualValues(t, email, res.Get(`0.traits.email`).String(), "%s", res.Raw) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("case=malformed organization id should return an error", func(t *testing.T) { | ||
for name, ts := range map[string]*httptest.Server{"admin": adminTS} { | ||
t.Run("endpoint="+name, func(t *testing.T) { | ||
res := get(t, ts, "/identities?organization_id=not-a-uuid", http.StatusBadRequest) | ||
assert.Contains(t, res.Get("error.reason").String(), "Invalid UUID value `not-a-uuid` for parameter `organization_id`.", "%s", res.Raw) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("case=unknown organization id should return an empty list", func(t *testing.T) { | ||
for name, ts := range map[string]*httptest.Server{"admin": adminTS} { | ||
t.Run("endpoint="+name, func(t *testing.T) { | ||
id := x.NewUUID() | ||
res := get(t, ts, "/identities?organization_id="+id.String(), http.StatusOK) | ||
assert.Len(t, res.Array(), 0) | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
t.Run("case=should list all identities with credentials", func(t *testing.T) { | ||
t.Run("include_credential=oidc should include OIDC credentials config", func(t *testing.T) { | ||
res := get(t, adminTS, "/identities?include_credential=oidc&credentials_identifier=bar:[email protected]", http.StatusOK) | ||
|
1 change: 1 addition & 0 deletions
1
persistence/sql/migrations/sql/20240923095000000001_organization_id_index.down.sql
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX identities_organization_id; |
1 change: 1 addition & 0 deletions
1
persistence/sql/migrations/sql/20240923095000000001_organization_id_index.up.sql
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE INDEX identities_organization_id ON identities (organization_id ASC); |