Skip to content

Commit

Permalink
Merge pull request #98 from nov/feature/handle_unexpected_format_of_j…
Browse files Browse the repository at this point in the history
…wks_success_response

handle `fail!` in correct way
  • Loading branch information
nov authored Oct 31, 2022
2 parents db3ae84 + eeaf084 commit 33ccf37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 9 additions & 3 deletions lib/omniauth/strategies/apple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
module OmniAuth
module Strategies
class Apple < OmniAuth::Strategies::OAuth2
class JWTFetchingFailed < CallbackError
def initialize(error_reason = nil, error_uri = nil)
super :jwks_fetching_failed, error_reason, error_uri
end
end

option :name, 'apple'

option :client_options,
Expand Down Expand Up @@ -102,10 +108,10 @@ def fetch_jwks
if res.success?
res.body
else
fail!(:jwks_fetching_failed, CallbackError.new(:jwks_fetching_failed, 'HTTP Error when fetching JWKs'))
raise JWTFetchingFailed.new('HTTP Error when fetching JWKs')
end
rescue Faraday::Error => e
fail!(:jwks_fetching_failed, e)
rescue JWTFetchingFailed, Faraday::Error => e
fail!(:jwks_fetching_failed, e) and nil
end

def verify_nonce!(payload)
Expand Down
11 changes: 7 additions & 4 deletions spec/omniauth/strategies/apple_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@

context 'fails nonce' do
before(:each) do
expect(subject).to receive(:fail!).with(:nonce_mismatch, instance_of(OmniAuth::Strategies::OAuth2::CallbackError))
expect(subject).to receive(:fail!).with(
:nonce_mismatch,
instance_of(OmniAuth::Strategies::OAuth2::CallbackError)
).and_return([302, {}, ''])
end
it 'when differs from session' do
subject.session['omniauth.nonce'] = 'abc'
Expand Down Expand Up @@ -356,8 +359,8 @@
it do
expect(subject).to receive(:fail!).with(
:jwks_fetching_failed,
instance_of(OmniAuth::Strategies::OAuth2::CallbackError)
)
instance_of(OmniAuth::Strategies::Apple::JWTFetchingFailed)
).and_return([302, {}, ''])
subject.info
end
end
Expand All @@ -376,7 +379,7 @@
expect(subject).to receive(:fail!).with(
:jwks_fetching_failed,
instance_of(Faraday::ParsingError)
)
).and_return([302, {}, ''])
subject.info
end
end
Expand Down

0 comments on commit 33ccf37

Please sign in to comment.