Skip to content
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

fix: test assertions on declassifying OIDC tokens #3773

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions identity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,22 +610,25 @@ func TestHandler(t *testing.T) {
}
})

t.Run("case=should fail to get oidc credential", func(t *testing.T) {
t.Run("case=should return empty tokens if decryption fails", func(t *testing.T) {
id := createOidcIdentity(t, "foo-failed.oidc@bar.com", "foo_token", "bar_token", "id_token", false)
for name, ts := range map[string]*httptest.Server{"public": publicTS, "admin": adminTS} {
t.Run("endpoint="+name, func(t *testing.T) {
t.Logf("no oidc token")
res := get(t, ts, "/identities/"+i.ID.String()+"?include_credential=oidc", http.StatusOK)
assert.NotContains(t, res.Raw, "identifier_credentials", res.Raw)

t.Logf("get oidc token")
res = get(t, ts, "/identities/"+id+"?include_credential=oidc", http.StatusOK)
assert.NotContains(t, res.Raw, "identifier_credentials", res.Raw)
assert.Equal(t, "bar:foo-failed.oidc@bar.com", res.Get("credentials.oidc.identifiers.0").String(), "%s", res.Raw)
assert.Equal(t, "", res.Get("credentials.oidc.config.providers.0.initial_access_token").String(), "%s", res.Raw)
assert.Equal(t, "", res.Get("credentials.oidc.config.providers.0.initial_id_token").String(), "%s", res.Raw)
assert.Equal(t, "", res.Get("credentials.oidc.config.providers.0.initial_refresh_token").String(), "%s", res.Raw)
})
}
})

t.Run("case=should return decrypted token", func(t *testing.T) {
e, _ := reg.Cipher(ctx).Encrypt(context.Background(), []byte("foo_token"))
id = createOidcIdentity(t, "foo-failed-2.oidc@bar.com", e, "bar_token", "id_token", false)
id := createOidcIdentity(t, "foo-failed-2.oidc@bar.com", e, "bar_token", "id_token", false)
for name, ts := range map[string]*httptest.Server{"public": publicTS, "admin": adminTS} {
t.Run("endpoint="+name, func(t *testing.T) {
t.Logf("no oidc token")
Expand All @@ -634,7 +637,8 @@ func TestHandler(t *testing.T) {

t.Logf("get oidc token")
res = get(t, ts, "/identities/"+id+"?include_credential=oidc", http.StatusOK)
assert.NotContains(t, res.Raw, "identifier_credentials", res.Raw)
assert.Equal(t, "bar:foo-failed-2.oidc@bar.com", res.Get("credentials.oidc.identifiers.0").String(), "%s", res.Raw)
assert.Equal(t, "foo_token", res.Get("credentials.oidc.config.providers.0.initial_access_token").String(), "%s", res.Raw)
})
}
})
Expand Down
Loading