-
-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow fuzzy-search on credential identifiers (#3526)
This PR adds the ability to search for sub-strings and similar strings in credential identifiers. Note that the **postgres** and **CRDB** migrations create special indexes useful for this feature. To use [online schema changes](https://www.cockroachlabs.com/docs/v23.1/online-schema-changes) with cockroach, we recommend to manually copy the index definition and run it before applying migrations. The migration will then be a no-op. If you run on **mysql** (or **sqlite**), no special index is created. If desired, you can create such an index manually, and it would be highly appreciated if you could contribute its definition. This feature is a preview and will change in behavior! Similarity search is not expected to return deterministic results but are useful for humans.
- Loading branch information
Showing
21 changed files
with
216 additions
and
140 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
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
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 |
---|---|---|
|
@@ -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]", | ||
|
Oops, something went wrong.