1
+ # frozen_string_literal: true
2
+
1
3
require_relative '../../../test_helper'
2
4
3
5
module OmniAuth
4
6
module Strategies
5
- class OpenIDConnectTest < StrategyTestCase
7
+ class OpenIDConnectTest < StrategyTestCase # rubocop:disable Metrics/ClassLength
6
8
def test_client_options_defaults
7
9
assert_equal 'https' , strategy . options . client_options . scheme
8
10
assert_equal 443 , strategy . options . client_options . port
@@ -11,15 +13,15 @@ def test_client_options_defaults
11
13
end
12
14
13
15
def test_request_phase
14
- expected_redirect = / ^https:\/ \ / example\. com\ / authorize\? client_id=1234&nonce=\w {32}&response_type=code&scope=openid&state=\w {32}$/
16
+ expected_redirect = %r{ ^https:/ /example\. com/authorize\? client_id=1234&nonce=\w {32}&response_type=code&scope=openid&state=\w {32}$}
15
17
strategy . options . issuer = 'example.com'
16
18
strategy . options . client_options . host = 'example.com'
17
19
strategy . expects ( :redirect ) . with ( regexp_matches ( expected_redirect ) )
18
20
strategy . request_phase
19
21
end
20
22
21
23
def test_logout_phase_with_discovery
22
- expected_redirect = %r{^https:\/ \ / example\. com\ / logout$}
24
+ expected_redirect = %r{^https:/ /example\. com/logout$}
23
25
strategy . options . client_options . host = 'example.com'
24
26
strategy . options . discovery = true
25
27
@@ -78,7 +80,7 @@ def test_logout_phase
78
80
end
79
81
80
82
def test_request_phase_with_params
81
- expected_redirect = / ^https:\/ \ / example\. com\ / authorize\? claims_locales=es&client_id=1234&login_hint=john.doe%40example.com&nonce=\w {32}&response_type=code&scope=openid&state=\w {32}&ui_locales=en$/
83
+ expected_redirect = %r{ ^https:/ /example\. com/authorize\? claims_locales=es&client_id=1234&login_hint=john.doe%40example.com&nonce=\w {32}&response_type=code&scope=openid&state=\w {32}&ui_locales=en$}
82
84
strategy . options . issuer = 'example.com'
83
85
strategy . options . client_options . host = 'example.com'
84
86
request . stubs ( :params ) . returns ( 'login_hint' => 'john.doe@example.com' , 'ui_locales' => 'en' , 'claims_locales' => 'es' )
@@ -88,7 +90,7 @@ def test_request_phase_with_params
88
90
end
89
91
90
92
def test_request_phase_with_discovery
91
- expected_redirect = / ^https:\/ \ / example\. com\ / authorization\? client_id=1234&nonce=\w {32}&response_type=code&scope=openid&state=\w {32}$/
93
+ expected_redirect = %r{ ^https:/ /example\. com/authorization\? client_id=1234&nonce=\w {32}&response_type=code&scope=openid&state=\w {32}$}
92
94
strategy . options . client_options . host = 'example.com'
93
95
strategy . options . discovery = true
94
96
@@ -115,7 +117,7 @@ def test_request_phase_with_discovery
115
117
end
116
118
117
119
def test_request_phase_with_response_mode
118
- expected_redirect = / ^https:\/ \ / example\. com\ / authorize\? client_id=1234&nonce=\w {32}&response_mode=form_post&response_type=id_token&scope=openid&state=\w {32}$/
120
+ expected_redirect = %r{ ^https:/ /example\. com/authorize\? client_id=1234&nonce=\w {32}&response_mode=form_post&response_type=id_token&scope=openid&state=\w {32}$}
119
121
strategy . options . issuer = 'example.com'
120
122
strategy . options . response_mode = 'form_post'
121
123
strategy . options . response_type = 'id_token'
@@ -126,7 +128,7 @@ def test_request_phase_with_response_mode
126
128
end
127
129
128
130
def test_request_phase_with_response_mode_symbol
129
- expected_redirect = / ^https:\/ \ / example\. com\ / authorize\? client_id=1234&nonce=\w {32}&response_mode=form_post&response_type=id_token&scope=openid&state=\w {32}$/
131
+ expected_redirect = %r{ ^https:/ /example\. com/authorize\? client_id=1234&nonce=\w {32}&response_mode=form_post&response_type=id_token&scope=openid&state=\w {32}$}
130
132
strategy . options . issuer = 'example.com'
131
133
strategy . options . response_mode = 'form_post'
132
134
strategy . options . response_type = :id_token
@@ -139,15 +141,15 @@ def test_request_phase_with_response_mode_symbol
139
141
def test_option_acr_values
140
142
strategy . options . client_options [ :host ] = 'foobar.com'
141
143
142
- assert ( ! ( strategy . authorize_uri =~ /acr_values=/ ) , 'URI must not contain acr_values' )
144
+ refute_match ( /acr_values=/ , strategy . authorize_uri , 'URI must not contain acr_values' )
143
145
144
146
strategy . options . acr_values = 'urn:some:acr:values:value'
145
- assert ( strategy . authorize_uri =~ /acr_values=/ , 'URI must contain acr_values' )
147
+ assert_match ( /acr_values=/ , strategy . authorize_uri , 'URI must contain acr_values' )
146
148
end
147
149
148
150
def test_option_custom_attributes
149
151
strategy . options . client_options [ :host ] = 'foobar.com'
150
- strategy . options . extra_authorize_params = { resource : 'xyz' }
152
+ strategy . options . extra_authorize_params = { resource : 'xyz' }
151
153
152
154
assert ( strategy . authorize_uri =~ /resource=xyz/ , 'URI must contain custom params' )
153
155
end
@@ -175,7 +177,7 @@ def test_uid
175
177
assert_equal user_info . sub , strategy . uid
176
178
end
177
179
178
- def test_callback_phase ( session = { } , params = { } )
180
+ def test_callback_phase ( _session = { } , _params = { } )
179
181
code = SecureRandom . hex ( 16 )
180
182
state = SecureRandom . hex ( 16 )
181
183
nonce = SecureRandom . hex ( 16 )
@@ -237,7 +239,7 @@ def test_callback_phase_with_id_token
237
239
strategy . callback_phase
238
240
end
239
241
240
- def test_callback_phase_with_discovery
242
+ def test_callback_phase_with_discovery # rubocop:disable Metrics/AbcSize
241
243
code = SecureRandom . hex ( 16 )
242
244
state = SecureRandom . hex ( 16 )
243
245
nonce = SecureRandom . hex ( 16 )
@@ -287,7 +289,7 @@ def test_callback_phase_with_error
287
289
request . stubs ( :params ) . returns ( 'error' => 'invalid_request' )
288
290
request . stubs ( :path ) . returns ( '' )
289
291
290
- strategy . call! ( { 'rack.session' => { 'omniauth.state' => state , 'omniauth.nonce' => nonce } } )
292
+ strategy . call! ( { 'rack.session' => { 'omniauth.state' => state , 'omniauth.nonce' => nonce } } )
291
293
strategy . expects ( :fail! )
292
294
strategy . callback_phase
293
295
end
@@ -465,19 +467,18 @@ def test_credentials
465
467
token : access_token . access_token ,
466
468
refresh_token : access_token . refresh_token ,
467
469
expires_in : access_token . expires_in ,
468
- scope : access_token . scope
470
+ scope : access_token . scope ,
469
471
} ,
470
472
strategy . credentials
471
473
)
472
474
end
473
475
474
476
def test_option_send_nonce
475
477
strategy . options . client_options [ :host ] = 'foobar.com'
476
-
477
- assert ( strategy . authorize_uri =~ /nonce=/ , 'URI must contain nonce' )
478
+ assert_match ( /nonce/ , strategy . authorize_uri , 'URI must contain nonce' )
478
479
479
480
strategy . options . send_nonce = false
480
- assert ( ! ( strategy . authorize_uri =~ /nonce=/ ) , 'URI must not contain nonce' )
481
+ refute_match ( /nonce/ , strategy . authorize_uri , 'URI must not contain nonce' )
481
482
end
482
483
483
484
def test_failure_endpoint_redirect
@@ -487,9 +488,9 @@ def test_failure_endpoint_redirect
487
488
488
489
result = strategy . callback_phase
489
490
490
- assert ( result . is_a? Array )
491
+ assert ( result . is_a? ( Array ) )
491
492
assert ( result [ 0 ] == 302 , 'Redirect' )
492
- assert ( result [ 1 ] [ " Location" ] =~ / \/ auth\ / failure/ )
493
+ assert ( result [ 1 ] [ ' Location' ] =~ %r{/ auth/failure} )
493
494
end
494
495
495
496
def test_state
@@ -518,7 +519,7 @@ def test_state
518
519
def test_dynamic_state
519
520
# Stub request parameters
520
521
request . stubs ( :path ) . returns ( '' )
521
- strategy . call! ( 'rack.session' => { } , QUERY_STRING : { state : 'abc' , client_id : '123' } )
522
+ strategy . call! ( 'rack.session' => { } , QUERY_STRING : { state : 'abc' , client_id : '123' } )
522
523
523
524
strategy . options . state = lambda { |env |
524
525
# Get params from request, e.g. CGI.parse(env['QUERY_STRING'])
@@ -563,7 +564,7 @@ def test_option_client_auth_method
563
564
{ }
564
565
) . returns ( success )
565
566
566
- assert ( strategy . send :access_token )
567
+ assert ( strategy . send ( :access_token ) )
567
568
end
568
569
569
570
def test_public_key_with_jwks
@@ -605,12 +606,12 @@ def test_id_token_auth_hash
605
606
id_token . stubs ( :verify! ) . returns ( true )
606
607
id_token . stubs ( :raw_attributes , :to_h ) . returns (
607
608
{
608
- "iss" : " http://server.example.com" ,
609
- "sub" : " 248289761001" ,
610
- "aud" : " s6BhdRkqt3" ,
611
- "nonce" : " n-0S6_WzA2Mj" ,
612
- "exp" : 1311281970 ,
613
- "iat" : 1311280970 ,
609
+ "iss" : ' http://server.example.com' ,
610
+ "sub" : ' 248289761001' ,
611
+ "aud" : ' s6BhdRkqt3' ,
612
+ "nonce" : ' n-0S6_WzA2Mj' ,
613
+ "exp" : 1_311_281_970 ,
614
+ "iat" : 1_311_280_970 ,
614
615
}
615
616
)
616
617
0 commit comments