Skip to content

Commit

Permalink
test: resolve failing test for empty tokens (#3775)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Feb 22, 2024
1 parent 8f5192f commit 7277368
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions identity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,14 @@ func TestHandler(t *testing.T) {

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, "", res.Get("credentials.oidc.config.providers.0.initial_access_token").String(), "credentials should be included: %s", res.Raw)
assert.EqualValues(t, "", res.Get("credentials.oidc.config.providers.0.initial_refresh_token").String(), "credentials should be included: %s", res.Raw)
assert.EqualValues(t, "", 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)
assert.EqualValues(t, "", res.Get("credentials.oidc.config.providers.1.initial_access_token").String(), "credentials should be included: %s", res.Raw)
assert.EqualValues(t, "", res.Get("credentials.oidc.config.providers.1.initial_refresh_token").String(), "credentials should be included: %s", res.Raw)
assert.EqualValues(t, "", res.Get("credentials.oidc.config.providers.1.initial_id_token").String(), "credentials should be included: %s", res.Raw)
})
}
})
Expand Down Expand Up @@ -619,8 +619,8 @@ func TestHandler(t *testing.T) {
assert.NotContains(t, res.Raw, "identifier_credentials", res.Raw)

t.Logf("get oidc token")
res = get(t, ts, "/identities/"+id+"?include_credential=oidc", http.StatusInternalServerError)
assert.Contains(t, res.Raw, "Internal Server Error", res.Raw)
res = get(t, ts, "/identities/"+id+"?include_credential=oidc", http.StatusOK)
assert.NotContains(t, res.Raw, "identifier_credentials", res.Raw)
})
}

Expand All @@ -633,8 +633,8 @@ func TestHandler(t *testing.T) {
assert.NotContains(t, res.Raw, "identifier_credentials", res.Raw)

t.Logf("get oidc token")
res = get(t, ts, "/identities/"+id+"?include_credential=oidc", http.StatusInternalServerError)
assert.Contains(t, res.Raw, "Internal Server Error", res.Raw)
res = get(t, ts, "/identities/"+id+"?include_credential=oidc", http.StatusOK)
assert.NotContains(t, res.Raw, "identifier_credentials", res.Raw)
})
}
})
Expand Down Expand Up @@ -1344,15 +1344,11 @@ func TestHandler(t *testing.T) {
})

t.Run("case=should list all identities with credentials", func(t *testing.T) {
for name, ts := range map[string]*httptest.Server{"admin": adminTS} {
t.Run("endpoint="+name, func(t *testing.T) {
res := get(t, ts, "/identities?include_credential=totp", http.StatusOK)
assert.True(t, res.Get("0.credentials").Exists(), "credentials config should be included: %s", res.Raw)
assert.True(t, res.Get("0.metadata_public").Exists(), "metadata_public config should be included: %s", res.Raw)
assert.True(t, res.Get("0.metadata_admin").Exists(), "metadata_admin config should be included: %s", res.Raw)
assert.EqualValues(t, "baz", res.Get(`#(traits.bar=="baz").traits.bar`).String(), "%s", res.Raw)
})
}
res := get(t, adminTS, "/identities?include_credential=totp", http.StatusOK)
assert.True(t, res.Get("0.credentials").Exists(), "credentials config should be included: %s", res.Raw)
assert.True(t, res.Get("0.metadata_public").Exists(), "metadata_public config should be included: %s", res.Raw)
assert.True(t, res.Get("0.metadata_admin").Exists(), "metadata_admin config should be included: %s", res.Raw)
assert.EqualValues(t, "baz", res.Get(`#(traits.bar=="baz").traits.bar`).String(), "%s", res.Raw)
})

t.Run("case=should not be able to list all identities with credentials due to wrong credentials type", func(t *testing.T) {
Expand Down

0 comments on commit 7277368

Please sign in to comment.