-
-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow fuzzy-search on credential identifiers #3526
Changes from 8 commits
c214410
9aa0f46
9b78f54
d1f8fc6
1ab4965
8817441
54e8366
dd7a3e1
749116f
5483892
a168798
cd2cc35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,11 +133,19 @@ type listIdentitiesResponse struct { | |
type listIdentitiesParameters struct { | ||
migrationpagination.RequestParameters | ||
|
||
// CredentialsIdentifier is the identifier (username, email) of the credentials to look up. | ||
// CredentialsIdentifier is the identifier (username, email) of the credentials to look up using exact match. | ||
// Only one of CredentialsIdentifier and CredentialsIdentifierSimilar can be used. | ||
// | ||
// required: false | ||
// in: query | ||
CredentialsIdentifier string `json:"credentials_identifier"` | ||
|
||
// CredentialsIdentifierSimilar is the (partial) identifier (username, email) of the credentials to look up using similarity search. | ||
// Only one of CredentialsIdentifier and CredentialsIdentifierSimilar can be used. | ||
// | ||
// required: false | ||
// in: query | ||
CredentialsIdentifierSimilar string `json:"credentials_identifier_similar"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT of prefixing this as preview or something? We will probably need a separate search endpoint to deal with different use cases like:
Alternatively this could also be added to a new endpoint marked as experimental. For me it's primarily about finding the way we will be solving search in Ory to get a consistent API experience. That's why I think that this should be somehow marked as: this api will be changed once we have an appropriate search design doc |
||
} | ||
|
||
// swagger:route GET /admin/identities identity listIdentities | ||
|
@@ -160,7 +168,13 @@ type listIdentitiesParameters struct { | |
func (h *Handler) list(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
page, itemsPerPage := x.ParsePagination(r) | ||
|
||
params := ListIdentityParameters{Expand: ExpandDefault, Page: page, PerPage: itemsPerPage, CredentialsIdentifier: r.URL.Query().Get("credentials_identifier")} | ||
params := ListIdentityParameters{ | ||
Expand: ExpandDefault, | ||
Page: page, | ||
PerPage: itemsPerPage, | ||
CredentialsIdentifier: r.URL.Query().Get("credentials_identifier"), | ||
CredentialsIdentifierSimilar: r.URL.Query().Get("credentials_identifier_similar"), | ||
} | ||
if params.CredentialsIdentifier != "" { | ||
params.Expand = ExpandEverything | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -636,7 +636,8 @@ func TestPool(ctx context.Context, conf *config.Config, p persistence.Persister, | |
t.Run("case=list", func(t *testing.T) { | ||
is, err := p.ListIdentities(ctx, identity.ListIdentityParameters{Expand: identity.ExpandDefault, Page: 0, PerPage: 25}) | ||
require.NoError(t, err) | ||
assert.Len(t, is, len(createdIDs)) | ||
require.NotZero(t, len(is)) | ||
require.Len(t, is, len(createdIDs)) | ||
for _, id := range createdIDs { | ||
var found bool | ||
for _, i := range is { | ||
|
@@ -686,7 +687,7 @@ func TestPool(ctx context.Context, conf *config.Config, p persistence.Persister, | |
Expand: identity.ExpandEverything, | ||
}) | ||
require.NoError(t, err) | ||
require.True(t, len(actual) > 0) | ||
require.Greater(t, len(actual), 0) | ||
|
||
for c, ct := range []identity.CredentialsType{ | ||
identity.CredentialsTypePassword, | ||
|
@@ -705,6 +706,30 @@ func TestPool(ctx context.Context, conf *config.Config, p persistence.Persister, | |
}) | ||
} | ||
|
||
t.Run("similarity search", func(t *testing.T) { | ||
actual, err := p.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
CredentialsIdentifierSimilar: "find-identity-by-identifier", | ||
Expand: identity.ExpandCredentials, | ||
}) | ||
require.NoError(t, err) | ||
assert.Len(t, actual, 3) | ||
|
||
outer: | ||
for _, e := range append(expectedIdentities[:2], create) { | ||
for _, a := range actual { | ||
if e.ID == a.ID { | ||
assertx.EqualAsJSONExcept(t, e, a, []string{"credentials.config", "created_at", "updated_at", "state_changed_at"}) | ||
continue outer | ||
} | ||
} | ||
actualCredentials := make([]map[identity.CredentialsType]identity.Credentials, len(actual)) | ||
for k, a := range actual { | ||
actualCredentials[k] = a.Credentials | ||
} | ||
t.Fatalf("expected identity %+v not found in actual result set %+v", e.Credentials, actualCredentials) | ||
} | ||
}) | ||
|
||
t.Run("only webauthn and password", func(t *testing.T) { | ||
actual, err := p.ListIdentities(ctx, identity.ListIdentityParameters{ | ||
CredentialsIdentifier: "[email protected]", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres 9 is EoL by now, and 11 is currently the oldest supported version.