-
-
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.
fix: ignore decrypt errors in WithDeclassifiedCredentials (#3731)
- Loading branch information
1 parent
b7e5144
commit 8f5192f
Showing
8 changed files
with
131 additions
and
41 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
22 changes: 22 additions & 0 deletions
22
identity/.snapshots/TestWithDeclassifiedCredentials-case=oidc-credential=oidc.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": "oidc", | ||
"identifiers": [ | ||
"bar", | ||
"baz" | ||
], | ||
"config": { | ||
"providers": [ | ||
{ | ||
"initial_id_token": "foo", | ||
"initial_access_token": "", | ||
"initial_refresh_token": "", | ||
"subject": "", | ||
"provider": "", | ||
"organization": "" | ||
} | ||
] | ||
}, | ||
"version": 0, | ||
"created_at": "0001-01-01T00:00:00Z", | ||
"updated_at": "0001-01-01T00:00:00Z" | ||
} |
10 changes: 10 additions & 0 deletions
10
identity/.snapshots/TestWithDeclassifiedCredentials-case=oidc-credential=password.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,10 @@ | ||
{ | ||
"type": "password", | ||
"identifiers": [ | ||
"zab", | ||
"bar" | ||
], | ||
"version": 0, | ||
"created_at": "0001-01-01T00:00:00Z", | ||
"updated_at": "0001-01-01T00:00:00Z" | ||
} |
10 changes: 10 additions & 0 deletions
10
identity/.snapshots/TestWithDeclassifiedCredentials-case=oidc-credential=webauthn.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,10 @@ | ||
{ | ||
"type": "webauthn", | ||
"identifiers": [ | ||
"foo", | ||
"bar" | ||
], | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,17 +364,19 @@ func TestHandler(t *testing.T) { | |
identities := res.Array() | ||
require.Equal(t, len(identities), listAmount) | ||
}) | ||
|
||
}) | ||
|
||
t.Run("suite=create and update", func(t *testing.T) { | ||
var i identity.Identity | ||
createOidcIdentity := func(t *testing.T, identifier, accessToken, refreshToken, idToken string, encrypt bool) string { | ||
transform := func(token string) string { | ||
transform := func(token, suffix string) string { | ||
if !encrypt { | ||
return token | ||
} | ||
c, err := reg.Cipher(ctx).Encrypt(context.Background(), []byte(token)) | ||
if token == "" { | ||
return "" | ||
} | ||
c, err := reg.Cipher(ctx).Encrypt(context.Background(), []byte(token+suffix)) | ||
require.NoError(t, err) | ||
return c | ||
} | ||
|
@@ -396,16 +398,16 @@ func TestHandler(t *testing.T) { | |
{ | ||
Subject: "foo", | ||
Provider: "bar", | ||
InitialAccessToken: transform(accessToken + "0"), | ||
InitialRefreshToken: transform(refreshToken + "0"), | ||
InitialIDToken: transform(idToken + "0"), | ||
InitialAccessToken: transform(accessToken, "0"), | ||
InitialRefreshToken: transform(refreshToken, "0"), | ||
InitialIDToken: transform(idToken, "0"), | ||
}, | ||
{ | ||
Subject: "baz", | ||
Provider: "zab", | ||
InitialAccessToken: transform(accessToken + "1"), | ||
InitialRefreshToken: transform(refreshToken + "1"), | ||
InitialIDToken: transform(idToken + "1"), | ||
InitialAccessToken: transform(accessToken, "1"), | ||
InitialRefreshToken: transform(refreshToken, "1"), | ||
InitialIDToken: transform(idToken, "1"), | ||
}, | ||
}}), | ||
}, | ||
|
@@ -537,6 +539,34 @@ func TestHandler(t *testing.T) { | |
} | ||
}) | ||
|
||
t.Run("case=should not fail on empty tokens", func(t *testing.T) { | ||
id := createOidcIdentity(t, "[email protected]", "", "", "", true) | ||
for name, ts := range map[string]*httptest.Server{"public": publicTS, "admin": adminTS} { | ||
t.Run("endpoint="+name, func(t *testing.T) { | ||
res := get(t, ts, "/identities/"+id, http.StatusOK) | ||
assert.False(t, res.Get("credentials.oidc.config").Exists(), "credentials config should be omitted: %s", res.Raw) | ||
assert.False(t, res.Get("credentials.password.config").Exists(), "credentials config should be omitted: %s", res.Raw) | ||
|
||
res = get(t, ts, "/identities/"+id+"?include_credential=oidc", http.StatusOK) | ||
assert.True(t, res.Get("credentials").Exists(), "credentials should be included: %s", res.Raw) | ||
assert.True(t, res.Get("credentials.password").Exists(), "password meta should be included: %s", res.Raw) | ||
assert.False(t, res.Get("credentials.password.false").Exists(), "password credentials should not be included: %s", res.Raw) | ||
assert.True(t, res.Get("credentials.oidc.config").Exists(), "oidc credentials should be included: %s", res.Raw) | ||
|
||
assert.EqualValues(t, "foo", res.Get("credentials.oidc.config.providers.0.subject").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "bar", res.Get("credentials.oidc.config.providers.0.provider").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "access_token0", res.Get("credentials.oidc.config.providers.0.initial_access_token").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "refresh_token0", res.Get("credentials.oidc.config.providers.0.initial_refresh_token").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "id_token0", res.Get("credentials.oidc.config.providers.0.initial_id_token").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "baz", res.Get("credentials.oidc.config.providers.1.subject").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "zab", res.Get("credentials.oidc.config.providers.1.provider").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "access_token1", res.Get("credentials.oidc.config.providers.1.initial_access_token").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "refresh_token1", res.Get("credentials.oidc.config.providers.1.initial_refresh_token").String(), "credentials should be included: %s", res.Raw) | ||
assert.EqualValues(t, "id_token1", res.Get("credentials.oidc.config.providers.1.initial_id_token").String(), "credentials should be included: %s", res.Raw) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("case=should get identity with credentials", func(t *testing.T) { | ||
i := identity.NewIdentity(config.DefaultIdentityTraitsSchemaID) | ||
credentials := map[identity.CredentialsType]identity.Credentials{ | ||
|
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