Skip to content

Commit 71da1e3

Browse files
zepatrikory-bot
authored andcommitted
test: deflake SAML config assertion
GitOrigin-RevId: 3cad41ed2ded379328e6c0f50d1b27a9da9b0f38
1 parent cf94909 commit 71da1e3

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

identity/handler_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestHandler(t *testing.T) {
7070
require.NoError(t, err)
7171
require.NoError(t, res.Body.Close())
7272

73-
require.EqualValues(t, expectCode, res.StatusCode, "%s", body)
73+
require.EqualValuesf(t, expectCode, res.StatusCode, "%s", body)
7474
return gjson.ParseBytes(body), res
7575
}
7676

@@ -1839,10 +1839,10 @@ func TestHandler(t *testing.T) {
18391839
for name, ts := range map[string]*httptest.Server{"admin": adminTS} {
18401840
t.Run("endpoint="+name, func(t *testing.T) {
18411841
res := get(t, ts, "/identities", http.StatusOK)
1842-
assert.False(t, res.Get("0.credentials").Exists(), "credentials config should be omitted: %s", res.Raw)
1843-
assert.True(t, res.Get("0.metadata_public").Exists(), "metadata_public config should be included: %s", res.Raw)
1844-
assert.True(t, res.Get("0.metadata_admin").Exists(), "metadata_admin config should be included: %s", res.Raw)
1845-
assert.EqualValues(t, "baz", res.Get(`#(traits.bar=="baz").traits.bar`).String(), "%s", res.Raw)
1842+
assert.Empty(t, res.Get("#.credentials").Array(), "credentials config should be omitted")
1843+
assert.Equal(t, res.Get("#").Int(), res.Get("#.metadata_public|#").Int(), "metadata_public config should be included")
1844+
assert.Equal(t, res.Get("#").Int(), res.Get("#.metadata_admin|#").Int(), "metadata_admin config should be included")
1845+
assert.EqualValues(t, "baz", res.Get(`#(traits.bar=="baz").traits.bar`).String())
18461846
})
18471847
}
18481848
})
@@ -1879,7 +1879,7 @@ func TestHandler(t *testing.T) {
18791879
t.Run("endpoint="+name, func(t *testing.T) {
18801880
id := x.NewUUID()
18811881
res := get(t, ts, "/identities?organization_id="+id.String(), http.StatusOK)
1882-
assert.Len(t, res.Array(), 0)
1882+
assert.Empty(t, res.Array())
18831883
})
18841884
}
18851885
})
@@ -1905,18 +1905,16 @@ func TestHandler(t *testing.T) {
19051905
assert.True(t, foundSAML, "SAML credential included")
19061906
})
19071907

1908-
t.Run("include_credential=saml should not include SAML credentials config", func(t *testing.T) {
1908+
t.Run("include_credential=saml should not include SAML tokens", func(t *testing.T) {
19091909
res := get(t, adminTS, "/identities?include_credential=saml", http.StatusOK)
1910-
t.Log("Result:", res)
1911-
assert.Empty(t, res.Get("0.credentials.saml.config"), "SAML config should not be included")
1910+
samlProviders := res.Get("#.credentials.saml.config.providers|@flatten")
1911+
assert.Greaterf(t, samlProviders.Get("#.subject|#").Int(), int64(0), "SAML config should contain subject: %s", samlProviders.Raw)
1912+
assert.Zerof(t, res.Get("#.initial_id_token|#").Int(), "SAML config should not contain initial_id_token: %s", samlProviders.Raw)
19121913
})
19131914
t.Run("include_credential=totp should not include OIDC credentials config", func(t *testing.T) {
19141915
res := get(t, adminTS, "/identities?include_credential=totp", http.StatusOK)
1915-
t.Log("Result:", res)
1916-
for _, id := range res.Array() {
1917-
assert.False(t, id.Get("credentials.oidc.config").Exists(), "OIDC config should not be included")
1918-
assert.False(t, id.Get("credentials.saml.config").Exists(), "SAML config should not be included")
1919-
}
1916+
assert.Empty(t, res.Get("#.credentials.oidc.config").Array(), "OIDC config should not be included")
1917+
assert.Empty(t, res.Get("#.credentials.saml.config").Array(), "SAML config should not be included")
19201918
})
19211919
})
19221920

0 commit comments

Comments
 (0)