Skip to content

Commit

Permalink
Wrap mock_call in rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyMcWho committed Dec 11, 2020
1 parent 49ca577 commit 1b784ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/omniauth/strategy.rb
Expand Up @@ -298,8 +298,13 @@ def options_request?
# in the event that OmniAuth has been configured to be
# in test mode.
def mock_call!(*)
return mock_request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
return mock_callback_call if on_callback_path?
begin
OmniAuth.config.request_validation_phase.call(env) if OmniAuth.config.request_validation_phase
return mock_request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
return mock_callback_call if on_callback_path?
rescue StandardError => e
return fail!(e.message, e)
end

call_app!
end
Expand Down
6 changes: 6 additions & 0 deletions spec/omniauth/strategy_spec.rb
Expand Up @@ -885,6 +885,12 @@ def make_env(path = '/auth/test', props = {})
expect(strategy.env['omniauth.params']).to eq('foo' => 'bar')
end

it 'rescues errors in request_call' do
allow(strategy).to receive(:mock_request_call).and_raise(StandardError.new('Oh no'))
expect(strategy).to receive(:fail!).with('Oh no', kind_of(StandardError))
strategy.call(make_env)
end

after do
OmniAuth.config.test_mode = false
end
Expand Down

0 comments on commit 1b784ff

Please sign in to comment.