Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from koshilife/develop
Browse files Browse the repository at this point in the history
release v0.1.2
  • Loading branch information
koshilife authored Jul 9, 2020
2 parents 901e809 + eb2e7b7 commit ddcbb2e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.2

- make the error handling when missing scope for reading user info better.

# 0.1.1

- refs #4 Add tests and make code coverage 100%.
Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth-zoom/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module OmniAuth
module Zoom
VERSION = '0.1.1'
VERSION = '0.1.2'
end
end
5 changes: 4 additions & 1 deletion lib/omniauth/strategies/zoom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def raw_info
return @raw_info if defined?(@raw_info)

@raw_info = access_token.get('/v2/users/me').parsed || {}
rescue StandardError => e
rescue ::OAuth2::Error => e
raise e unless e.response.status == 400

# in case of missing a scope for reading current user info
log(:error, "#{e.class} occured. message:#{e.message}")
@raw_info = {}
end
Expand Down
9 changes: 8 additions & 1 deletion test/omniauth/zoom_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_it_returns_auth_hash_in_callback_phase

def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_phase
add_mock_exchange_token
add_mock_user_info_then_fail
add_mock_user_info_then_fail_because_of_missing_scope
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'

actual_auth = auth_hash.to_hash
Expand All @@ -52,6 +52,13 @@ def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_ph
assert_equal(expected_auth, actual_auth)
end

def test_it_does_not_return_auth_hash_in_case_of_unkonwn_failure_in_callbach_phase
add_mock_exchange_token
add_mock_user_info_then_fail_because_of_unknown
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
assert_nil(auth_hash)
end

private

def auth_hash
Expand Down
11 changes: 10 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def add_mock_user_info
stub_request(:get, url).with(:headers => headers).to_return(:status => 200, :body => dummy_user_info_response.to_json, :headers => res_headers)
end

def add_mock_user_info_then_fail
def add_mock_user_info_then_fail_because_of_missing_scope
WebMock.enable!
url = 'https://zoom.us/v2/users/me'
response = {:code => 124, :message => 'Invalid access token.'}
Expand All @@ -76,6 +76,15 @@ def add_mock_user_info_then_fail
stub_request(:get, url).with(:headers => headers).to_return(:status => 400, :body => response.to_json, :headers => res_headers)
end

def add_mock_user_info_then_fail_because_of_unknown
WebMock.enable!
url = 'https://zoom.us/v2/users/me'
response = {:code => 999, :message => 'Unknown Error'}
headers = {'Authorization' => "Bearer #{@access_token}"}
res_headers = {'Content-Type' => 'application/json'}
stub_request(:get, url).with(:headers => headers).to_return(:status => 500, :body => response.to_json, :headers => res_headers)
end

def dummy_user_info_response
{
:id => 'KdYKjnimT4KPd8FFgQt9FQ',
Expand Down

0 comments on commit ddcbb2e

Please sign in to comment.