Skip to content

Commit

Permalink
fix(test): OIDC storategy test (#1836)
Browse files Browse the repository at this point in the history
Co-authored-by: hackerman <3372410+aeneasr@users.noreply.github.com>
  • Loading branch information
sawadashota and aeneasr committed Oct 13, 2021
1 parent db98d01 commit b877dbe
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions selfservice/strategy/oidc/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,33 @@ func TestStrategy(t *testing.T) {
subject = "register-then-login@ory.sh"
scope = []string{"openid", "offline"}

expectTokens := func(t *testing.T, body []byte) {
expectTokens := func(t *testing.T, provider string, body []byte) {
i, err := reg.PrivilegedIdentityPool().GetIdentityConfidential(context.Background(), uuid.FromStringOrNil(gjson.GetBytes(body, "identity.id").String()))
require.NoError(t, err)
c := i.Credentials[identity.CredentialsTypeOIDC].Config
assertx.EqualAsJSON(t, json.RawMessage(`{"baz":"bar"}`), json.RawMessage(c))
assert.NotEmpty(t, gjson.GetBytes(c, "providers.0.initial_access_token").String())
assertx.EqualAsJSONExcept(
t,
json.RawMessage(fmt.Sprintf(`{"providers": [{"subject":"%s","provider":"%s"}]}`, subject, provider)),
json.RawMessage(c),
[]string{"providers.0.initial_id_token", "providers.0.initial_access_token", "providers.0.initial_refresh_token"},
)
}

t.Run("case=should pass registration", func(t *testing.T) {
r := newRegistrationFlow(t, returnTS.URL, time.Minute)
action := afv(t, r.ID, "valid")
res, body := makeRequest(t, "valid", action, url.Values{})
ai(t, res, body)
expectTokens(t, body)
expectTokens(t, "valid", body)
})

t.Run("case=should pass login", func(t *testing.T) {
r := newLoginFlow(t, returnTS.URL, time.Minute)
action := afv(t, r.ID, "valid")
res, body := makeRequest(t, "valid", action, url.Values{})
ai(t, res, body)
expectTokens(t, body)
expectTokens(t, "valid", body)
})
})

Expand Down

0 comments on commit b877dbe

Please sign in to comment.