Skip to content

Commit

Permalink
Merge pull request #169 from nov/feature/oauth2_timeout
Browse files Browse the repository at this point in the history
rescue oauth2 timeout
  • Loading branch information
BobbyMcWho committed Jul 18, 2023
2 parents 3534082 + dd60580 commit ed39610
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/omniauth/strategies/oauth2.rb
Expand Up @@ -94,7 +94,7 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi
end
rescue ::OAuth2::Error, CallbackError => e
fail!(:invalid_credentials, e)
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
rescue ::Timeout::Error, ::Errno::ETIMEDOUT, ::OAuth2::TimeoutError, ::OAuth2::ConnectionError => e
fail!(:timeout, e)
rescue ::SocketError => e
fail!(:failed_to_connect, e)
Expand Down
4 changes: 2 additions & 2 deletions omniauth-oauth2.gemspec
Expand Up @@ -3,8 +3,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "omniauth-oauth2/version"

Gem::Specification.new do |gem|
gem.add_dependency "oauth2", [">= 1.4", "< 3"]
gem.add_dependency "omniauth", "~> 2.0"
gem.add_dependency "oauth2", [">= 2.0.2", "< 3"]
gem.add_dependency "omniauth", "~> 2.0"

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

Expand Down
27 changes: 27 additions & 0 deletions spec/omniauth/strategies/oauth2_spec.rb
Expand Up @@ -140,6 +140,33 @@ def app
expect(instance).to receive(:fail!).with(:csrf_detected, anything)
instance.callback_phase
end

describe 'exception handlings' do
let(:params) do
{"code" => "code", "state" => state}
end

before do
allow_any_instance_of(OmniAuth::Strategies::OAuth2).to receive(:build_access_token).and_raise(exception)
end

{
:invalid_credentials => [OAuth2::Error, OmniAuth::Strategies::OAuth2::CallbackError],
:timeout => [Timeout::Error, Errno::ETIMEDOUT, OAuth2::TimeoutError, OAuth2::ConnectionError],
:failed_to_connect => [SocketError]
}.each do |error_type, exceptions|
exceptions.each do |klass|
context "when #{klass}" do
let(:exception) { klass.new 'error' }

it do
expect(instance).to receive(:fail!).with(error_type, exception)
instance.callback_phase
end
end
end
end
end
end
end

Expand Down

0 comments on commit ed39610

Please sign in to comment.