From 095a49b28c6c80b755b159d85e6584750635c4da Mon Sep 17 00:00:00 2001 From: Nikos Date: Tue, 17 Sep 2024 16:19:02 +0300 Subject: [PATCH] fix: fix tests --- consent/handler_test.go | 64 +++++++++++++++++++ .../TestOAuth2ConsentRequest_MarshalJSON.json | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/consent/handler_test.go b/consent/handler_test.go index 1db0f53f6ec..7600afde011 100644 --- a/consent/handler_test.go +++ b/consent/handler_test.go @@ -335,6 +335,14 @@ func TestAcceptDeviceRequest(t *testing.T) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode, sig, err := reg.RFC8628HMACStrategy().GenerateUserCode(ctx) require.NoError(t, err) reg.OAuth2Storage().CreateUserCodeSession(ctx, sig, deviceRequest) @@ -395,6 +403,14 @@ func TestAcceptDuplicateDeviceRequest(t *testing.T) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode, sig, err := reg.RFC8628HMACStrategy().GenerateUserCode(ctx) require.NoError(t, err) reg.OAuth2Storage().CreateUserCodeSession(ctx, sig, deviceRequest) @@ -478,6 +494,14 @@ func TestAcceptCodeDeviceRequestFailure(t *testing.T) { getBody: func() ([]byte, error) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode, _, err := reg.RFC8628HMACStrategy().GenerateUserCode(ctx) require.NoError(t, err) return json.Marshal(&hydra.AcceptDeviceUserCodeRequest{UserCode: &userCode}) @@ -494,6 +518,14 @@ func TestAcceptCodeDeviceRequestFailure(t *testing.T) { getBody: func() ([]byte, error) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode := "" return json.Marshal(&hydra.AcceptDeviceUserCodeRequest{UserCode: &userCode}) }, @@ -509,6 +541,14 @@ func TestAcceptCodeDeviceRequestFailure(t *testing.T) { getBody: func() ([]byte, error) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode, _, err := reg.RFC8628HMACStrategy().GenerateUserCode(ctx) require.NoError(t, err) return json.Marshal(&hydra.AcceptDeviceUserCodeRequest{UserCode: &userCode}) @@ -525,6 +565,14 @@ func TestAcceptCodeDeviceRequestFailure(t *testing.T) { getBody: func() ([]byte, error) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode, _, err := reg.RFC8628HMACStrategy().GenerateUserCode(ctx) require.NoError(t, err) return json.Marshal(&hydra.AcceptDeviceUserCodeRequest{UserCode: &userCode}) @@ -541,6 +589,14 @@ func TestAcceptCodeDeviceRequestFailure(t *testing.T) { getBody: func() ([]byte, error) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode, sig, err := reg.RFC8628HMACStrategy().GenerateUserCode(ctx) require.NoError(t, err) deviceRequest.SetSession( @@ -572,6 +628,14 @@ func TestAcceptCodeDeviceRequestFailure(t *testing.T) { getBody: func() ([]byte, error) { deviceRequest := fosite.NewDeviceRequest() deviceRequest.Client = cl + deviceRequest.SetSession( + &oauth2.Session{ + DefaultSession: &openid.DefaultSession{ + Headers: &jwt.Headers{}, + }, + BrowserFlowCompleted: false, + }, + ) userCode, _, err := reg.RFC8628HMACStrategy().GenerateUserCode(ctx) require.NoError(t, err) ret := struct { diff --git a/flow/.snapshots/TestOAuth2ConsentRequest_MarshalJSON.json b/flow/.snapshots/TestOAuth2ConsentRequest_MarshalJSON.json index 1a39fb2e6c2..58c3808115d 100644 --- a/flow/.snapshots/TestOAuth2ConsentRequest_MarshalJSON.json +++ b/flow/.snapshots/TestOAuth2ConsentRequest_MarshalJSON.json @@ -1 +1 @@ -"{\"challenge\":\"\",\"requested_scope\":[],\"requested_access_token_audience\":[],\"skip\":false,\"subject\":\"\",\"oidc_context\":null,\"client\":null,\"request_url\":\"\",\"login_challenge\":\"\",\"login_session_id\":\"\",\"acr\":\"\",\"amr\":[]}" +"{\"challenge\":\"\",\"requested_scope\":[],\"requested_access_token_audience\":[],\"skip\":false,\"subject\":\"\",\"oidc_context\":null,\"client\":null,\"request_url\":\"\",\"login_challenge\":\"\",\"login_session_id\":\"\",\"device_challenge_id\":\"\",\"acr\":\"\",\"amr\":[]}"