-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: incorrect append of code credential identifier (#4102)
Closes #4076
- Loading branch information
Showing
6 changed files
with
113 additions
and
64 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
identity/.snapshots/TestSchemaExtensionCredentials-case=12.json
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,22 @@ | ||
{ | ||
"type": "code", | ||
"config": { | ||
"addresses": [ | ||
{ | ||
"channel": "sms", | ||
"address": "+4917667111638" | ||
}, | ||
{ | ||
"channel": "email", | ||
"address": "[email protected]" | ||
}, | ||
{ | ||
"channel": "email", | ||
"address": "[email protected]" | ||
} | ||
] | ||
}, | ||
"version": 0, | ||
"created_at": "0001-01-01T00:00:00Z", | ||
"updated_at": "0001-01-01T00:00:00Z" | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ import ( | |
"fmt" | ||
"testing" | ||
|
||
"github.com/ory/x/sqlxx" | ||
|
||
"github.com/ory/x/snapshotx" | ||
|
||
"github.com/ory/jsonschema/v3" | ||
|
@@ -25,103 +27,117 @@ var ctx = context.Background() | |
|
||
func TestSchemaExtensionCredentials(t *testing.T) { | ||
for k, tc := range []struct { | ||
expectErr error | ||
schema string | ||
doc string | ||
expect []string | ||
existing *identity.Credentials | ||
ct identity.CredentialsType | ||
expectErr error | ||
schema string | ||
doc string | ||
expectedIdentifiers []string | ||
existing *identity.Credentials | ||
ct identity.CredentialsType | ||
}{ | ||
{ | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/schema.json", | ||
expect: []string{"[email protected]"}, | ||
ct: identity.CredentialsTypePassword, | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/schema.json", | ||
expectedIdentifiers: []string{"[email protected]"}, | ||
ct: identity.CredentialsTypePassword, | ||
}, | ||
{ | ||
doc: `{"emails":["[email protected]","[email protected]","[email protected]"], "username": "foobar"}`, | ||
schema: "file://./stub/extension/credentials/multi.schema.json", | ||
expect: []string{"[email protected]", "[email protected]", "foobar"}, | ||
ct: identity.CredentialsTypePassword, | ||
doc: `{"emails":["[email protected]","[email protected]","[email protected]"], "username": "foobar"}`, | ||
schema: "file://./stub/extension/credentials/multi.schema.json", | ||
expectedIdentifiers: []string{"[email protected]", "[email protected]", "foobar"}, | ||
ct: identity.CredentialsTypePassword, | ||
}, | ||
{ | ||
doc: `{"emails":["[email protected]","[email protected]","[email protected]"], "username": "foobar"}`, | ||
schema: "file://./stub/extension/credentials/multi.schema.json", | ||
expect: []string{"[email protected]", "[email protected]"}, | ||
ct: identity.CredentialsTypeWebAuthn, | ||
doc: `{"emails":["[email protected]","[email protected]","[email protected]"], "username": "foobar"}`, | ||
schema: "file://./stub/extension/credentials/multi.schema.json", | ||
expectedIdentifiers: []string{"[email protected]", "[email protected]"}, | ||
ct: identity.CredentialsTypeWebAuthn, | ||
}, | ||
{ | ||
doc: `{"emails":["[email protected]","[email protected]"], "username": "foobar"}`, | ||
schema: "file://./stub/extension/credentials/multi.schema.json", | ||
expect: []string{"[email protected]", "[email protected]", "foobar"}, | ||
doc: `{"emails":["[email protected]","[email protected]"], "username": "foobar"}`, | ||
schema: "file://./stub/extension/credentials/multi.schema.json", | ||
expectedIdentifiers: []string{"[email protected]", "[email protected]", "foobar"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]"}, | ||
}, | ||
ct: identity.CredentialsTypePassword, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/webauthn.schema.json", | ||
expect: []string{"[email protected]"}, | ||
ct: identity.CredentialsTypeWebAuthn, | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/webauthn.schema.json", | ||
expectedIdentifiers: []string{"[email protected]"}, | ||
ct: identity.CredentialsTypeWebAuthn, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/webauthn.schema.json", | ||
expect: []string{"[email protected]"}, | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/webauthn.schema.json", | ||
expectedIdentifiers: []string{"[email protected]"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]"}, | ||
}, | ||
ct: identity.CredentialsTypeWebAuthn, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/code.schema.json", | ||
expect: []string{"[email protected]"}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/code.schema.json", | ||
expectedIdentifiers: []string{"[email protected]"}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/code.schema.json", | ||
expect: []string{"[email protected]"}, | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/code.schema.json", | ||
expectedIdentifiers: []string{"[email protected]"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]"}, | ||
}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/code.schema.json", | ||
expect: []string{"[email protected]"}, | ||
doc: `{"email":"[email protected]"}`, | ||
schema: "file://./stub/extension/credentials/code.schema.json", | ||
expectedIdentifiers: []string{"[email protected]"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]", "[email protected]"}, | ||
Config: sqlxx.JSONRawMessage(`{"addresses":[{"channel":"email","address":"[email protected]"}]}`), | ||
}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]","phone":"+49 176 671 11 638"}`, | ||
schema: "file://./stub/extension/credentials/code-phone-email.schema.json", | ||
expect: []string{"+4917667111638", "[email protected]"}, | ||
doc: `{"email":"[email protected]","phone":"+49 176 671 11 638"}`, | ||
schema: "file://./stub/extension/credentials/code-phone-email.schema.json", | ||
expectedIdentifiers: []string{"+4917667111638", "[email protected]"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]", "[email protected]"}, | ||
Config: sqlxx.JSONRawMessage(`{"addresses":[{"channel":"email","address":"[email protected]"}]}`), | ||
}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]","phone":"+49 176 671 11 638"}`, | ||
schema: "file://./stub/extension/credentials/code-phone-email.schema.json", | ||
expect: []string{"+4917667111638", "[email protected]"}, | ||
doc: `{"email":"[email protected]","phone":"+49 176 671 11 638"}`, | ||
schema: "file://./stub/extension/credentials/code-phone-email.schema.json", | ||
expectedIdentifiers: []string{"+4917667111638", "[email protected]"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]", "[email protected]"}, | ||
Config: sqlxx.JSONRawMessage(`{"addresses":[{"channel":"email","address":"[email protected]"}]}`), | ||
}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]","email2":"[email protected]","phone":"+49 176 671 11 638"}`, | ||
schema: "file://./stub/extension/credentials/code-phone-email.schema.json", | ||
expectedIdentifiers: []string{"+4917667111638", "[email protected]"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]", "[email protected]"}, | ||
Config: sqlxx.JSONRawMessage(`{"addresses":[{"channel":"email","address":"[email protected]"}]}`), | ||
}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
}, | ||
{ | ||
doc: `{"email":"[email protected]","email2":"[email protected]","phone":"+49 176 671 11 638"}`, | ||
schema: "file://./stub/extension/credentials/code-phone-email.schema.json", | ||
expect: []string{"+4917667111638", "[email protected]"}, | ||
doc: `{"email":"[email protected]","email2":"FOO@ory.sh","email3":"bar@ory.sh","phone":"+49 176 671 11 638"}`, | ||
schema: "file://./stub/extension/credentials/code-phone-email.schema.json", | ||
expectedIdentifiers: []string{"+4917667111638", "foo@ory.sh", "bar@ory.sh"}, | ||
existing: &identity.Credentials{ | ||
Identifiers: []string{"[email protected]", "[email protected]"}, | ||
Config: sqlxx.JSONRawMessage(`{"addresses":[{"channel":"email","address":"[email protected]"}]}`), | ||
}, | ||
ct: identity.CredentialsTypeCodeAuth, | ||
}, | ||
|
@@ -148,7 +164,7 @@ func TestSchemaExtensionCredentials(t *testing.T) { | |
|
||
credentials, ok := i.GetCredentials(tc.ct) | ||
require.True(t, ok) | ||
assert.ElementsMatch(t, tc.expect, credentials.Identifiers) | ||
assert.ElementsMatch(t, tc.expectedIdentifiers, credentials.Identifiers) | ||
snapshotx.SnapshotT(t, credentials, snapshotx.ExceptPaths("identifiers")) | ||
}) | ||
} | ||
|
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