(t *testing.T, c *client.Client, adminClient *hydra.APIClient, reg *driver.RegistrySQL, subject string, checkRequestPayload func(*hydra.OAuth2ConsentRequest) *hydra.AcceptOAuth2ConsentRequest)
| 112 | } |
| 113 | |
| 114 | func acceptConsentHandler(t *testing.T, c *client.Client, adminClient *hydra.APIClient, reg *driver.RegistrySQL, subject string, checkRequestPayload func(*hydra.OAuth2ConsentRequest) *hydra.AcceptOAuth2ConsentRequest) http.HandlerFunc { |
| 115 | return func(w http.ResponseWriter, r *http.Request) { |
| 116 | challenge := r.URL.Query().Get("consent_challenge") |
| 117 | rr, _, err := adminClient.OAuth2API.GetOAuth2ConsentRequest(context.Background()).ConsentChallenge(challenge).Execute() |
| 118 | require.NoError(t, err) |
| 119 | require.Equal(t, challenge, rr.Challenge) |
| 120 | |
| 121 | assert.EqualValues(t, c.GetID(), pointerx.Deref(rr.Client.ClientId)) |
| 122 | assert.Empty(t, pointerx.Deref(rr.Client.ClientSecret)) |
| 123 | assert.EqualValues(t, c.GrantTypes, rr.Client.GrantTypes) |
| 124 | assert.EqualValues(t, c.LogoURI, pointerx.Deref(rr.Client.LogoUri)) |
| 125 | assert.EqualValues(t, c.RedirectURIs, rr.Client.RedirectUris) |
| 126 | assert.EqualValues(t, subject, pointerx.Deref(rr.Subject)) |
| 127 | assert.EqualValues(t, []string{"hydra", "offline", "openid"}, rr.RequestedScope) |
| 128 | assert.Contains(t, *rr.RequestUrl, reg.Config().OAuth2AuthURL(r.Context()).String()) |
| 129 | assert.Equal(t, map[string]interface{}{"context": "bar"}, rr.Context) |
| 130 | |
| 131 | acceptBody := hydra.AcceptOAuth2ConsentRequest{ |
| 132 | GrantScope: []string{"hydra", "offline", "openid"}, |
| 133 | GrantAccessTokenAudience: rr.RequestedAccessTokenAudience, |
| 134 | Remember: new(true), |
| 135 | RememberFor: new(int64(0)), |
| 136 | Session: &hydra.AcceptOAuth2ConsentRequestSession{ |
| 137 | AccessToken: map[string]interface{}{"foo": "bar"}, |
| 138 | IdToken: map[string]interface{}{"bar": "baz", "email": "foo@bar.com"}, |
| 139 | }, |
| 140 | } |
| 141 | if checkRequestPayload != nil { |
| 142 | if b := checkRequestPayload(rr); b != nil { |
| 143 | acceptBody = *b |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | v, _, err := adminClient.OAuth2API.AcceptOAuth2ConsentRequest(context.Background()). |
| 148 | ConsentChallenge(challenge). |
| 149 | AcceptOAuth2ConsentRequest(acceptBody). |
| 150 | Execute() |
| 151 | require.NoError(t, err) |
| 152 | require.NotEmpty(t, v.RedirectTo) |
| 153 | http.Redirect(w, r, v.RedirectTo, http.StatusFound) |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // TestAuthCodeWithDefaultStrategy runs proper integration tests against in-memory and database connectors, specifically |
| 158 | // we test: |
no test coverage detected