From 1b784ffa5f128bea1a22d7d26477f73bb6b3cd08 Mon Sep 17 00:00:00 2001 From: Bobby McDonald Date: Thu, 10 Dec 2020 23:07:38 -0500 Subject: [PATCH] Wrap mock_call in rescue --- lib/omniauth/strategy.rb | 9 +++++++-- spec/omniauth/strategy_spec.rb | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/omniauth/strategy.rb b/lib/omniauth/strategy.rb index d94f1e98b..d8468bcbc 100644 --- a/lib/omniauth/strategy.rb +++ b/lib/omniauth/strategy.rb @@ -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 diff --git a/spec/omniauth/strategy_spec.rb b/spec/omniauth/strategy_spec.rb index 12b341a28..4fed39bc8 100644 --- a/spec/omniauth/strategy_spec.rb +++ b/spec/omniauth/strategy_spec.rb @@ -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