Skip to content

Commit ed39610

Browse files
authored
Merge pull request #169 from nov/feature/oauth2_timeout
rescue oauth2 timeout
2 parents 3534082 + dd60580 commit ed39610

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

lib/omniauth/strategies/oauth2.rb

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
33
require "omniauth-oauth2/version"
44

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

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

spec/omniauth/strategies/oauth2_spec.rb

Lines changed: 27 additions & 0 deletions
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)