Skip to content

Commit 22cc1b0

Browse files
davidwessmanstanhu
authored andcommittedFeb 7, 2022
Fix rubocop errors
1 parent 5815ccf commit 22cc1b0

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed
 

‎Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/gem_tasks'
24
require 'rake/testtask'
35

‎test/lib/omniauth/strategies/openid_connect_test.rb

+28-27
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
require_relative '../../../test_helper'
24

35
module OmniAuth
46
module Strategies
5-
class OpenIDConnectTest < StrategyTestCase
7+
class OpenIDConnectTest < StrategyTestCase # rubocop:disable Metrics/ClassLength
68
def test_client_options_defaults
79
assert_equal 'https', strategy.options.client_options.scheme
810
assert_equal 443, strategy.options.client_options.port
@@ -11,15 +13,15 @@ def test_client_options_defaults
1113
end
1214

1315
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}$}
1517
strategy.options.issuer = 'example.com'
1618
strategy.options.client_options.host = 'example.com'
1719
strategy.expects(:redirect).with(regexp_matches(expected_redirect))
1820
strategy.request_phase
1921
end
2022

2123
def test_logout_phase_with_discovery
22-
expected_redirect = %r{^https:\/\/example\.com\/logout$}
24+
expected_redirect = %r{^https://example\.com/logout$}
2325
strategy.options.client_options.host = 'example.com'
2426
strategy.options.discovery = true
2527

@@ -78,7 +80,7 @@ def test_logout_phase
7880
end
7981

8082
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$}
8284
strategy.options.issuer = 'example.com'
8385
strategy.options.client_options.host = 'example.com'
8486
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
8890
end
8991

9092
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}$}
9294
strategy.options.client_options.host = 'example.com'
9395
strategy.options.discovery = true
9496

@@ -115,7 +117,7 @@ def test_request_phase_with_discovery
115117
end
116118

117119
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}$}
119121
strategy.options.issuer = 'example.com'
120122
strategy.options.response_mode = 'form_post'
121123
strategy.options.response_type = 'id_token'
@@ -126,7 +128,7 @@ def test_request_phase_with_response_mode
126128
end
127129

128130
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}$}
130132
strategy.options.issuer = 'example.com'
131133
strategy.options.response_mode = 'form_post'
132134
strategy.options.response_type = :id_token
@@ -139,15 +141,15 @@ def test_request_phase_with_response_mode_symbol
139141
def test_option_acr_values
140142
strategy.options.client_options[:host] = 'foobar.com'
141143

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')
143145

144146
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')
146148
end
147149

148150
def test_option_custom_attributes
149151
strategy.options.client_options[:host] = 'foobar.com'
150-
strategy.options.extra_authorize_params = {resource: 'xyz'}
152+
strategy.options.extra_authorize_params = { resource: 'xyz' }
151153

152154
assert(strategy.authorize_uri =~ /resource=xyz/, 'URI must contain custom params')
153155
end
@@ -175,7 +177,7 @@ def test_uid
175177
assert_equal user_info.sub, strategy.uid
176178
end
177179

178-
def test_callback_phase(session = {}, params = {})
180+
def test_callback_phase(_session = {}, _params = {})
179181
code = SecureRandom.hex(16)
180182
state = SecureRandom.hex(16)
181183
nonce = SecureRandom.hex(16)
@@ -237,7 +239,7 @@ def test_callback_phase_with_id_token
237239
strategy.callback_phase
238240
end
239241

240-
def test_callback_phase_with_discovery
242+
def test_callback_phase_with_discovery # rubocop:disable Metrics/AbcSize
241243
code = SecureRandom.hex(16)
242244
state = SecureRandom.hex(16)
243245
nonce = SecureRandom.hex(16)
@@ -287,7 +289,7 @@ def test_callback_phase_with_error
287289
request.stubs(:params).returns('error' => 'invalid_request')
288290
request.stubs(:path).returns('')
289291

290-
strategy.call!({'rack.session' => {'omniauth.state' => state, 'omniauth.nonce' => nonce}})
292+
strategy.call!({ 'rack.session' => { 'omniauth.state' => state, 'omniauth.nonce' => nonce } })
291293
strategy.expects(:fail!)
292294
strategy.callback_phase
293295
end
@@ -465,19 +467,18 @@ def test_credentials
465467
token: access_token.access_token,
466468
refresh_token: access_token.refresh_token,
467469
expires_in: access_token.expires_in,
468-
scope: access_token.scope
470+
scope: access_token.scope,
469471
},
470472
strategy.credentials
471473
)
472474
end
473475

474476
def test_option_send_nonce
475477
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')
478479

479480
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')
481482
end
482483

483484
def test_failure_endpoint_redirect
@@ -487,9 +488,9 @@ def test_failure_endpoint_redirect
487488

488489
result = strategy.callback_phase
489490

490-
assert(result.is_a? Array)
491+
assert(result.is_a?(Array))
491492
assert(result[0] == 302, 'Redirect')
492-
assert(result[1]["Location"] =~ /\/auth\/failure/)
493+
assert(result[1]['Location'] =~ %r{/auth/failure})
493494
end
494495

495496
def test_state
@@ -518,7 +519,7 @@ def test_state
518519
def test_dynamic_state
519520
# Stub request parameters
520521
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' })
522523

523524
strategy.options.state = lambda { |env|
524525
# Get params from request, e.g. CGI.parse(env['QUERY_STRING'])
@@ -563,7 +564,7 @@ def test_option_client_auth_method
563564
{}
564565
).returns(success)
565566

566-
assert(strategy.send :access_token)
567+
assert(strategy.send(:access_token))
567568
end
568569

569570
def test_public_key_with_jwks
@@ -605,12 +606,12 @@ def test_id_token_auth_hash
605606
id_token.stubs(:verify!).returns(true)
606607
id_token.stubs(:raw_attributes, :to_h).returns(
607608
{
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,
614615
}
615616
)
616617

‎test/strategy_test_case.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class StrategyTestCase < MiniTest::Test
24
class DummyApp
35
def call(env); end
@@ -24,9 +26,9 @@ def user_info
2426
given_name: Faker::Name.first_name,
2527
family_name: Faker::Name.last_name,
2628
gender: 'female',
27-
picture: Faker::Internet.url + '.png',
29+
picture: "#{Faker::Internet.url}.png",
2830
phone_number: Faker::PhoneNumber.phone_number,
29-
website: Faker::Internet.url,
31+
website: Faker::Internet.url
3032
)
3133
end
3234

‎test/test_helper.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
lib = File.expand_path('../../lib', __FILE__)
1+
# frozen_string_literal: true
2+
3+
lib = File.expand_path('../lib', __dir__)
24
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
35

46
require 'simplecov'

0 commit comments

Comments
 (0)
Please sign in to comment.