Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
do not create an Error instance if there is no error
Browse files Browse the repository at this point in the history
- also re-validate in a test that encoding errors do not cause issues
  • Loading branch information
urkle committed Sep 28, 2016
1 parent d297ee9 commit c89e19d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/oauth2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ def get_token(params, access_token_opts = {}, access_token_class = AccessToken)
opts[:params] = params
end
response = request(options[:token_method], token_url, opts)
error = Error.new(response)
raise(error) if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
error = Error.new(response)
raise(error)
end
access_token_class.from_hash(self, response.parsed.merge(access_token_opts))
end

Expand Down
21 changes: 21 additions & 0 deletions spec/oauth2/strategy/auth_code_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'helper'

describe OAuth2::Strategy::AuthCode do
Expand Down Expand Up @@ -50,6 +52,25 @@
end
end

describe '#get_token (handling utf-8 data)' do
let(:json_token) { MultiJson.encode(:expires_in => 600, :access_token => 'salmon', :refresh_token => 'trout', :extra_param => 'André') }

before do
@mode = 'json'
client.options[:token_method] = :post
end

it 'should not raise an error' do
expect { subject.get_token(code) }.to_not raise_error
end

it 'should not create an error instance' do
expect(OAuth2::Error).to_not receive(:new)

subject.get_token(code)
end
end

%w(json formencoded from_facebook).each do |mode|
[:get, :post].each do |verb|
describe "#get_token (#{mode}, access_token_method=#{verb}" do
Expand Down

0 comments on commit c89e19d

Please sign in to comment.