Skip to content

Commit 687cfae

Browse files
zepatrikory-bot
authored andcommitted
test(hydra): add snapshots for login & consent requests
GitOrigin-RevId: 47d041cf207af6c3e9e21bf3016e5ea0cf044344
1 parent 6ba796b commit 687cfae

10 files changed

+284
-95
lines changed

cmd/cmd_helper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func setup(t *testing.T, cmd *cobra.Command) *driver.RegistrySQL {
5252
return reg
5353
}
5454

55-
var snapshotExcludedClientFields = []snapshotx.ExceptOpt{
55+
var snapshotExcludedClientFields = []snapshotx.Opt{
5656
snapshotx.ExceptNestedKeys("client_id"),
5757
snapshotx.ExceptNestedKeys("registration_access_token"),
5858
snapshotx.ExceptNestedKeys("registration_client_uri"),

flow/flow_encoding_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/ory/hydra/v2/x"
2222
"github.com/ory/x/configx"
2323
"github.com/ory/x/snapshotx"
24-
"github.com/ory/x/sqlxx"
2524
)
2625

2726
func createTestFlow(nid uuid.UUID, state int16) *flow.Flow {
@@ -36,7 +35,7 @@ func createTestFlow(nid uuid.UUID, state int16) *flow.Flow {
3635
NID: nid,
3736
},
3837
RequestURL: "https://example.org/oauth2/auth?client_id=test",
39-
SessionID: sqlxx.NullString("session-123"),
38+
SessionID: "session-123",
4039
RequestedAt: time.Now(),
4140
State: state,
4241
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"acr": "acr-value",
3+
"amr": [
4+
"amr1",
5+
"amr2"
6+
],
7+
"client": {
8+
"access_token_strategy": "jwt",
9+
"allowed_cors_origins": [],
10+
"audience": [
11+
"audience-1",
12+
"audience-2"
13+
],
14+
"client_id": "64f78bf1-f388-4eeb-9fee-e7207226c6be-jwt",
15+
"client_name": "",
16+
"client_secret_expires_at": 0,
17+
"client_uri": "",
18+
"contacts": [],
19+
"grant_types": [
20+
"implicit",
21+
"refresh_token",
22+
"authorization_code",
23+
"password",
24+
"client_credentials"
25+
],
26+
"jwks": {},
27+
"logo_uri": "",
28+
"metadata": {},
29+
"owner": "",
30+
"policy_uri": "",
31+
"redirect_uris": [
32+
"https://client.ory/callback"
33+
],
34+
"response_types": [
35+
"id_token",
36+
"code",
37+
"token"
38+
],
39+
"scope": "hydra offline openid",
40+
"skip_consent": false,
41+
"subject_type": "",
42+
"tos_uri": ""
43+
},
44+
"device_challenge_id": "",
45+
"oidc_context": {},
46+
"requested_access_token_audience": [],
47+
"requested_scope": [
48+
"hydra",
49+
"offline",
50+
"openid"
51+
],
52+
"skip": false,
53+
"subject": "c6a8ee1c-e0c4-404c-bba7-6a5b8702a2e9"
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"client": {
3+
"access_token_strategy": "jwt",
4+
"allowed_cors_origins": [],
5+
"audience": [
6+
"audience-1",
7+
"audience-2"
8+
],
9+
"client_id": "64f78bf1-f388-4eeb-9fee-e7207226c6be-jwt",
10+
"client_name": "",
11+
"client_secret_expires_at": 0,
12+
"client_uri": "",
13+
"contacts": [],
14+
"grant_types": [
15+
"implicit",
16+
"refresh_token",
17+
"authorization_code",
18+
"password",
19+
"client_credentials"
20+
],
21+
"jwks": {},
22+
"logo_uri": "",
23+
"metadata": {},
24+
"owner": "",
25+
"policy_uri": "",
26+
"redirect_uris": [
27+
"https://client.ory/callback"
28+
],
29+
"response_types": [
30+
"id_token",
31+
"code",
32+
"token"
33+
],
34+
"scope": "hydra offline openid",
35+
"skip_consent": false,
36+
"subject_type": "",
37+
"tos_uri": ""
38+
},
39+
"oidc_context": {},
40+
"requested_access_token_audience": [],
41+
"requested_scope": [
42+
"hydra",
43+
"offline",
44+
"openid"
45+
],
46+
"skip": false,
47+
"subject": ""
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"acr": "acr-value",
3+
"amr": [
4+
"amr1",
5+
"amr2"
6+
],
7+
"client": {
8+
"access_token_strategy": "opaque",
9+
"allowed_cors_origins": [],
10+
"audience": [
11+
"audience-1",
12+
"audience-2"
13+
],
14+
"client_id": "64f78bf1-f388-4eeb-9fee-e7207226c6be-opaque",
15+
"client_name": "",
16+
"client_secret_expires_at": 0,
17+
"client_uri": "",
18+
"contacts": [],
19+
"grant_types": [
20+
"implicit",
21+
"refresh_token",
22+
"authorization_code",
23+
"password",
24+
"client_credentials"
25+
],
26+
"jwks": {},
27+
"logo_uri": "",
28+
"metadata": {},
29+
"owner": "",
30+
"policy_uri": "",
31+
"redirect_uris": [
32+
"https://client.ory/callback"
33+
],
34+
"response_types": [
35+
"id_token",
36+
"code",
37+
"token"
38+
],
39+
"scope": "hydra offline openid",
40+
"skip_consent": false,
41+
"subject_type": "",
42+
"tos_uri": ""
43+
},
44+
"device_challenge_id": "",
45+
"oidc_context": {},
46+
"requested_access_token_audience": [],
47+
"requested_scope": [
48+
"hydra",
49+
"offline",
50+
"openid"
51+
],
52+
"skip": false,
53+
"subject": "c6a8ee1c-e0c4-404c-bba7-6a5b8702a2e9"
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"client": {
3+
"access_token_strategy": "opaque",
4+
"allowed_cors_origins": [],
5+
"audience": [
6+
"audience-1",
7+
"audience-2"
8+
],
9+
"client_id": "64f78bf1-f388-4eeb-9fee-e7207226c6be-opaque",
10+
"client_name": "",
11+
"client_secret_expires_at": 0,
12+
"client_uri": "",
13+
"contacts": [],
14+
"grant_types": [
15+
"implicit",
16+
"refresh_token",
17+
"authorization_code",
18+
"password",
19+
"client_credentials"
20+
],
21+
"jwks": {},
22+
"logo_uri": "",
23+
"metadata": {},
24+
"owner": "",
25+
"policy_uri": "",
26+
"redirect_uris": [
27+
"https://client.ory/callback"
28+
],
29+
"response_types": [
30+
"id_token",
31+
"code",
32+
"token"
33+
],
34+
"scope": "hydra offline openid",
35+
"skip_consent": false,
36+
"subject_type": "",
37+
"tos_uri": ""
38+
},
39+
"oidc_context": {},
40+
"requested_access_token_audience": [],
41+
"requested_scope": [
42+
"hydra",
43+
"offline",
44+
"openid"
45+
],
46+
"skip": false,
47+
"subject": ""
48+
}

oauth2/e2e_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/ory/hydra/v2/driver"
15-
"github.com/ory/x/pointerx"
16-
1714
"github.com/go-jose/go-jose/v3"
1815
"github.com/stretchr/testify/assert"
1916
"github.com/stretchr/testify/require"
@@ -22,13 +19,15 @@ import (
2219

2320
hydra "github.com/ory/hydra-client-go/v2"
2421
"github.com/ory/hydra/v2/client"
25-
"github.com/ory/x/uuidx"
26-
22+
"github.com/ory/hydra/v2/driver"
2723
"github.com/ory/hydra/v2/driver/config"
2824
"github.com/ory/hydra/v2/internal/testhelpers"
2925
"github.com/ory/hydra/v2/jwk"
3026
"github.com/ory/hydra/v2/x"
3127
"github.com/ory/x/configx"
28+
"github.com/ory/x/pointerx"
29+
"github.com/ory/x/snapshotx"
30+
"github.com/ory/x/uuidx"
3231
)
3332

3433
func TestAuthCodeFlowE2E(t *testing.T) {
@@ -70,19 +69,26 @@ func TestAuthCodeFlowE2E(t *testing.T) {
7069
cl, conf := newOAuth2Client(t, reg, testhelpers.ClientCallbackURL, func(c *client.Client) {
7170
c.AccessTokenStrategy = accessTokenStrategy
7271
c.Audience = []string{"audience-1", "audience-2"}
72+
c.ID = "64f78bf1-f388-4eeb-9fee-e7207226c6be-" + accessTokenStrategy
7373
})
74-
sub := uuidx.NewV4().String()
74+
sub := "c6a8ee1c-e0c4-404c-bba7-6a5b8702a2e9"
7575

7676
t.Run("access and id tokens with extra claims", func(t *testing.T) {
7777
token := testhelpers.PerformAuthCodeFlow(t, conf, adminClient,
78-
func(*testing.T, *hydra.OAuth2LoginRequest) hydra.AcceptOAuth2LoginRequest {
78+
func(t *testing.T, req *hydra.OAuth2LoginRequest) hydra.AcceptOAuth2LoginRequest {
79+
snapshotx.SnapshotT(t, req,
80+
snapshotx.ExceptPaths("challenge", "client.created_at", "client.updated_at", "session_id", "request_url"),
81+
snapshotx.WithName("login_request"))
7982
return hydra.AcceptOAuth2LoginRequest{
8083
Amr: []string{"amr1", "amr2"},
8184
Acr: pointerx.Ptr("acr-value"),
8285
Subject: sub,
8386
}
8487
},
85-
func(*testing.T, *hydra.OAuth2ConsentRequest) hydra.AcceptOAuth2ConsentRequest {
88+
func(t *testing.T, req *hydra.OAuth2ConsentRequest) hydra.AcceptOAuth2ConsentRequest {
89+
snapshotx.SnapshotT(t, req,
90+
snapshotx.ExceptPaths("challenge", "client.created_at", "client.updated_at", "consent_request_id", "login_challenge", "login_session_id", "request_url"),
91+
snapshotx.WithName("consent_request"))
8692
return hydra.AcceptOAuth2ConsentRequest{
8793
GrantScope: []string{"openid"},
8894
Session: &hydra.AcceptOAuth2ConsentRequestSession{

oauth2/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func TestHandlerWellKnown(t *testing.T) {
369369
err = json.NewDecoder(res.Body).Decode(&wellKnownResp)
370370
require.NoError(t, err, "problem decoding wellknown json response: %+v", err)
371371

372-
snapshotOpts := []snapshotx.ExceptOpt{}
372+
snapshotOpts := []snapshotx.Opt{}
373373
if reg.Config().HSMEnabled() {
374374
// The signing algorithm is not stable in the HSM tests, because the key is kept
375375
// in the HSM and persists across test runs.
@@ -415,7 +415,7 @@ func TestHandlerOauthAuthorizationServer(t *testing.T) {
415415
var wellKnownResp hydra.OidcConfiguration
416416
err = json.NewDecoder(res.Body).Decode(&wellKnownResp)
417417
require.NoError(t, err, "problem decoding wellknown json response: %+v", err)
418-
snapshotOpts := []snapshotx.ExceptOpt{}
418+
snapshotOpts := []snapshotx.Opt{}
419419
if reg.Config().HSMEnabled() {
420420
// The signing algorithm is not stable in the HSM tests, because the key is kept
421421
// in the HSM and persists across test runs.

oryx/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ require (
6969
github.com/ssoready/hyrumtoken v1.0.0
7070
github.com/stretchr/testify v1.10.0
7171
github.com/tidwall/gjson v1.18.0
72-
github.com/tidwall/pretty v1.2.1
7372
github.com/tidwall/sjson v1.2.5
7473
github.com/urfave/negroni v1.0.0
7574
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.62.0
@@ -199,6 +198,7 @@ require (
199198
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
200199
github.com/stretchr/objx v0.5.2 // indirect
201200
github.com/tidwall/match v1.1.1 // indirect
201+
github.com/tidwall/pretty v1.2.1 // indirect
202202
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
203203
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
204204
github.com/xeipuuv/gojsonschema v1.2.0 // indirect

0 commit comments

Comments
 (0)