@@ -237,6 +237,38 @@ def test_callback_phase_with_id_token
237
237
strategy . callback_phase
238
238
end
239
239
240
+ def test_callback_phase_with_id_token_and_param_provided_nonce # rubocop:disable Metrics/AbcSize
241
+ code = SecureRandom . hex ( 16 )
242
+ state = SecureRandom . hex ( 16 )
243
+ nonce = SecureRandom . hex ( 16 )
244
+ request . stubs ( :params ) . returns ( 'code' => code , 'state' => state , 'nonce' => nonce )
245
+ request . stubs ( :path ) . returns ( '' )
246
+
247
+ strategy . options . issuer = 'example.com'
248
+ strategy . options . client_signing_alg = :RS256
249
+ strategy . options . client_jwk_signing_key = jwks . to_s
250
+ strategy . options . response_type = 'code'
251
+
252
+ strategy . unstub ( :user_info )
253
+ access_token = stub ( 'OpenIDConnect::AccessToken' )
254
+ access_token . stubs ( :access_token )
255
+ access_token . stubs ( :refresh_token )
256
+ access_token . stubs ( :expires_in )
257
+ access_token . stubs ( :scope )
258
+ access_token . stubs ( :id_token ) . returns ( jwt . to_s )
259
+ client . expects ( :access_token! ) . at_least_once . returns ( access_token )
260
+ access_token . expects ( :userinfo! ) . returns ( user_info )
261
+
262
+ id_token = stub ( 'OpenIDConnect::ResponseObject::IdToken' )
263
+ id_token . stubs ( :raw_attributes ) . returns ( 'sub' => 'sub' , 'name' => 'name' , 'email' => 'email' )
264
+ id_token . stubs ( :verify! ) . with ( issuer : strategy . options . issuer , client_id : @identifier , nonce : nonce ) . returns ( true )
265
+ id_token . expects ( :verify! )
266
+
267
+ strategy . expects ( :decode_id_token ) . twice . with ( access_token . id_token ) . returns ( id_token )
268
+ strategy . call! ( 'rack.session' => { 'omniauth.state' => state } )
269
+ strategy . callback_phase
270
+ end
271
+
240
272
def test_callback_phase_with_discovery # rubocop:disable Metrics/AbcSize
241
273
state = SecureRandom . hex ( 16 )
242
274
0 commit comments