Skip to content

Commit f9c0288

Browse files
committed
rescue oauth2 timeout
1 parent 3a43234 commit f9c0288

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/omniauth/strategies/oauth2.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi
9494
end
9595
rescue ::OAuth2::Error, CallbackError => e
9696
fail!(:invalid_credentials, e)
97-
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
97+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT, ::OAuth2::TimeoutError, ::OAuth2::ConnectionError => e
9898
fail!(:timeout, e)
9999
rescue ::SocketError => e
100100
fail!(:failed_to_connect, e)

omniauth-oauth2.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require "omniauth-oauth2/version"
44

55
Gem::Specification.new do |gem|
66
gem.add_dependency "oauth2", [">= 1.4", "< 3"]
7-
gem.add_dependency "omniauth", "~> 2.0"
7+
gem.add_dependency "omniauth", [">= 2.0.2", "< 3"]
88

99
gem.add_development_dependency "bundler", "~> 2.0"
1010

spec/omniauth/strategies/oauth2_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,33 @@ def app
140140
expect(instance).to receive(:fail!).with(:csrf_detected, anything)
141141
instance.callback_phase
142142
end
143+
144+
describe 'exception handlings' do
145+
let(:params) do
146+
{"code" => "code", "state" => state}
147+
end
148+
149+
before do
150+
allow_any_instance_of(OmniAuth::Strategies::OAuth2).to receive(:build_access_token).and_raise(exception)
151+
end
152+
153+
{
154+
invalid_credentials: [OAuth2::Error, OmniAuth::Strategies::OAuth2::CallbackError],
155+
timeout: [Timeout::Error, Errno::ETIMEDOUT, OAuth2::TimeoutError, OAuth2::ConnectionError],
156+
failed_to_connect: [SocketError]
157+
}.each do |error_type, exceptions|
158+
exceptions.each do |klass|
159+
context "when #{klass}" do
160+
let(:exception) { klass.new 'error' }
161+
162+
it do
163+
expect(instance).to receive(:fail!).with(error_type, exception)
164+
instance.callback_phase
165+
end
166+
end
167+
end
168+
end
169+
end
143170
end
144171
end
145172

0 commit comments

Comments
 (0)