Skip to content

Commit

Permalink
Match current code standards & practices
Browse files Browse the repository at this point in the history
  • Loading branch information
joshjordan committed Dec 7, 2020
1 parent ee2ef21 commit 83d2d30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/omniauth/strategy.rb
Expand Up @@ -193,7 +193,7 @@ def call!(env) # rubocop:disable CyclomaticComplexity, PerceivedComplexity
return callback_call if on_callback_path?
return other_phase if respond_to?(:other_phase)
rescue => ex
return fail! ex.message, ex
return fail!(ex.message, ex)
end

@app.call(env)
Expand Down
52 changes: 26 additions & 26 deletions spec/omniauth/strategy_spec.rb
Expand Up @@ -312,7 +312,7 @@ def make_env(path = '/auth/test', props = {})
context 'disabled' do
it 'does not set omniauth.origin' do
@options = {:origin_param => false}
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))

strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'return=/foo'))
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq(nil)
Expand All @@ -322,7 +322,7 @@ def make_env(path = '/auth/test', props = {})
context 'custom' do
it 'sets from a custom param' do
@options = {:origin_param => 'return'}
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))

strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'return=/foo'))
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('/foo')
Expand All @@ -331,21 +331,21 @@ def make_env(path = '/auth/test', props = {})

context 'default flow' do
it 'is set on the request phase' do
strategy.should_receive(:fail!).with("Request Phase", kind_of(StandardError))
expect(strategy).to receive(:fail!).with("Request Phase", kind_of(StandardError))
strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))

expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('http://example.com/origin')
end

it 'is turned into an env variable on the callback phase' do
strategy.should_receive(:fail!).with("Callback Phase", kind_of(StandardError))
expect(strategy).to receive(:fail!).with("Callback Phase", kind_of(StandardError))
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))

expect(strategy.last_env['omniauth.origin']).to eq('http://example.com/origin')
end

it 'sets from the params if provided' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo'))
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('/foo')
end
Expand All @@ -359,7 +359,7 @@ def make_env(path = '/auth/test', props = {})
context 'with script_name' do
it 'is set on the request phase, containing full path' do
env = {'HTTP_REFERER' => 'http://example.com/sub_uri/origin', 'SCRIPT_NAME' => '/sub_uri'}
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))

strategy.call(make_env('/auth/test', env))
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('http://example.com/sub_uri/origin')
Expand All @@ -370,7 +370,7 @@ def make_env(path = '/auth/test', props = {})
'rack.session' => {'omniauth.origin' => 'http://example.com/sub_uri/origin'},
'SCRIPT_NAME' => '/sub_uri'
}
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))

strategy.call(make_env('/auth/test/callback', env))
expect(strategy.last_env['omniauth.origin']).to eq('http://example.com/sub_uri/origin')
Expand All @@ -381,39 +381,39 @@ def make_env(path = '/auth/test', props = {})

context 'default paths' do
it 'uses the default request path' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env)
end

it 'is case insensitive on request path' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env('/AUTH/Test'))
end

it 'is case insensitive on callback path' do
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))
strategy.call(make_env('/AUTH/TeSt/CaLlBAck'))
end

it 'uses the default callback path' do
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))
strategy.call(make_env('/auth/test/callback'))
end

it 'strips trailing spaces on request' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env('/auth/test/'))
end

it 'strips trailing spaces on callback' do
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))
strategy.call(make_env('/auth/test/callback/'))
end

context 'callback_url' do
it 'uses the default callback_path' do
expect(strategy).to receive(:full_host).and_return('http://example.com')
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))

strategy.call(make_env)

Expand Down Expand Up @@ -455,13 +455,13 @@ def make_env(path = '/auth/test', props = {})
context 'dynamic paths' do
it 'runs the request phase if the custom request path evaluator is truthy' do
@options = {:request_path => lambda { |_env| true }}
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env('/asoufibasfi'))
end

it 'runs the callback phase if the custom callback path evaluator is truthy' do
@options = {:callback_path => lambda { |_env| true }}
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))

strategy.call(make_env('/asoufiasod'))
end
Expand All @@ -483,14 +483,14 @@ def make_env(path = '/auth/test', props = {})
context 'custom paths' do
it 'uses a custom request_path if one is provided' do
@options = {:request_path => '/awesome'}
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))

strategy.call(make_env('/awesome'))
end

it 'uses a custom callback_path if one is provided' do
@options = {:callback_path => '/radical'}
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))

strategy.call(make_env('/radical'))
end
Expand All @@ -499,7 +499,7 @@ def make_env(path = '/auth/test', props = {})
it 'uses a custom callback_path if one is provided' do
@options = {:callback_path => '/radical'}
expect(strategy).to receive(:full_host).and_return('http://example.com')
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))

strategy.call(make_env('/radical'))

Expand All @@ -524,19 +524,19 @@ def make_env(path = '/auth/test', props = {})
end

it 'uses a custom prefix for request' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env('/wowzers/test'))
end

it 'uses a custom prefix for callback' do
strategy.should_receive(:fail!).with('Callback Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Callback Phase', kind_of(StandardError))
strategy.call(make_env('/wowzers/test/callback'))
end

context 'callback_url' do
it 'uses a custom prefix' do
expect(strategy).to receive(:full_host).and_return('http://example.com')
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env('/wowzers/test'))

expect(strategy.callback_url).to eq('http://example.com/wowzers/test/callback')
Expand All @@ -563,7 +563,7 @@ def make_env(path = '/auth/test', props = {})
end

it 'allows a request method of the correct type' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))
strategy.call(make_env('/auth/test'))
end

Expand Down Expand Up @@ -857,7 +857,7 @@ def make_env(path = '/auth/test', props = {})
let(:escaped_token) { URI.encode_www_form_component(csrf_token, Encoding::UTF_8) }

it 'allows a request with matching authenticity_token' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))

post_env = make_env('/auth/test', 'rack.session' => {:csrf => csrf_token}, 'rack.input' => StringIO.new("authenticity_token=#{escaped_token}"))
strategy.call(post_env)
Expand All @@ -877,7 +877,7 @@ def make_env(path = '/auth/test', props = {})
end

it 'allows a request without authenticity token' do
strategy.should_receive(:fail!).with('Request Phase', kind_of(StandardError))
expect(strategy).to receive(:fail!).with('Request Phase', kind_of(StandardError))

get_env = make_env('/auth/test', 'REQUEST_METHOD' => 'GET')
strategy.call(get_env)
Expand All @@ -895,7 +895,7 @@ def make_env(path = '/auth/test', props = {})

it 'calls fail! when encountering an unhandled exception' do
strategy.stub(:request_phase).and_raise(Errno::ECONNREFUSED)
strategy.should_receive(:fail!).with('Connection refused', kind_of(Errno::ECONNREFUSED))
expect(strategy).to receive(:fail!).with('Connection refused', kind_of(Errno::ECONNREFUSED))
strategy.call(make_env)
end

Expand Down

0 comments on commit 83d2d30

Please sign in to comment.