diff --git a/.rubocop.yml b/.rubocop.yml index 20c874e..cf00839 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,12 +23,11 @@ Metrics/BlockNesting: Max: 2 Layout/LineLength: - AllowURI: true - Enabled: false + Max: 120 Metrics/MethodLength: CountComments: false - Max: 15 + Max: 20 Metrics/ParameterLists: Max: 4 @@ -39,10 +38,10 @@ Metrics/AbcSize: Style/CollectionMethods: PreferredMethods: - map: 'collect' - reduce: 'inject' - find: 'detect' - find_all: 'select' + map: "collect" + reduce: "inject" + find: "detect" + find_all: "select" Style/Documentation: Enabled: false @@ -60,10 +59,13 @@ Style/ExpandPathArguments: Enabled: false Style/HashSyntax: - EnforcedStyle: hash_rockets + EnforcedStyle: ruby19 Style/Lambda: Enabled: false Style/RaiseArgs: - EnforcedStyle: compact \ No newline at end of file + EnforcedStyle: compact + +Style/AsciiComments: + Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 414de50..4e04348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,22 @@ -# 0.2.0 +# CHANGELOG + +## 0.2.1 + +- fix rubocop warnings. + +## 0.2.0 - refs #11 fix library dependencies. - remove minitest-reporter. -# 0.1.2 +## 0.1.2 - make the error handling when missing scope for reading user info better. -# 0.1.1 +## 0.1.1 - refs #4 Add tests and make code coverage 100%. -# 0.1.0 +## 0.1.0 - Initial release diff --git a/Rakefile b/Rakefile index d433a1e..4caa98e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,12 @@ -require "bundler/gem_tasks" -require "rake/testtask" +# frozen_string_literal: true + +require 'bundler/gem_tasks' +require 'rake/testtask' Rake::TestTask.new(:test) do |t| - t.libs << "test" - t.libs << "lib" - t.test_files = FileList["test/**/*_test.rb"] + t.libs << 'test' + t.libs << 'lib' + t.test_files = FileList['test/**/*_test.rb'] end -task :default => :test +task default: :test diff --git a/lib/omniauth-zoom/version.rb b/lib/omniauth-zoom/version.rb index 3731cf2..ebb93ce 100644 --- a/lib/omniauth-zoom/version.rb +++ b/lib/omniauth-zoom/version.rb @@ -2,6 +2,6 @@ module OmniAuth module Zoom - VERSION = '0.2.0' + VERSION = '0.2.1' end end diff --git a/lib/omniauth/strategies/zoom.rb b/lib/omniauth/strategies/zoom.rb index 717758e..750d8c1 100644 --- a/lib/omniauth/strategies/zoom.rb +++ b/lib/omniauth/strategies/zoom.rb @@ -9,22 +9,22 @@ module Strategies # OmniAuth strategy for zoom.us class Zoom < OmniAuth::Strategies::OAuth2 option :name, 'zoom' - option :client_options, :site => 'https://zoom.us' + option :client_options, site: 'https://zoom.us' uid { raw_info['id'] } - extra { {:raw_info => raw_info} } + extra { {raw_info: raw_info} } protected def build_access_token params = { - :grant_type => 'authorization_code', - :code => request.params['code'], - :redirect_uri => callback_url + grant_type: 'authorization_code', + code: request.params['code'], + redirect_uri: callback_url } path = "#{client.options[:token_url]}?#{URI.encode_www_form(params)}" headers_secret = Base64.strict_encode64("#{client.id}:#{client.secret}") - opts = {:headers => {:Authorization => "Basic #{headers_secret}"}} + opts = {headers: {Authorization: "Basic #{headers_secret}"}} res = client.request(:post, path, opts) ::OAuth2::AccessToken.from_hash(client, res.parsed) diff --git a/test/omniauth/zoom_test.rb b/test/omniauth/zoom_test.rb index 2bb1164..8ca10b6 100644 --- a/test/omniauth/zoom_test.rb +++ b/test/omniauth/zoom_test.rb @@ -19,7 +19,7 @@ def test_it_has_a_client_options def test_it_returns_auth_hash_in_callback_phase add_mock_exchange_token add_mock_user_info - post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123' + post '/auth/zoom/callback', code: @authorization_code, state: 'state123' actual_auth = auth_hash.to_hash assert(!actual_auth['credentials'].delete('expires_at').nil?) @@ -38,7 +38,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_because_of_missing_scope - post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123' + post '/auth/zoom/callback', code: @authorization_code, state: 'state123' actual_auth = auth_hash.to_hash assert(!actual_auth['credentials'].delete('expires_at').nil?) @@ -55,7 +55,7 @@ def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_ph 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' + post '/auth/zoom/callback', code: @authorization_code, state: 'state123' assert_nil(auth_hash) end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7c9d689..afedb86 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -25,7 +25,7 @@ def setup @client_id = 'DUMMY_CLIENT_ID' @client_secret = 'DUMMY_CLIENT_SECRET' @scope = 'user_profile' - @options = {:scope => @scope, :provider_ignores_state => true} + @options = {scope: @scope, provider_ignores_state: true} @authorization_code = 'DUMMY_AUTH_CODE' @access_token = 'DUMMY_TOKEN' @refresh_token = 'DUMMY_REFRESH_TOKEN' @@ -43,16 +43,16 @@ def add_mock_exchange_token secret = Base64.strict_encode64("#{@client_id}:#{@client_secret}") headers = {'Authorization' => "Basic #{secret}"} res_headers = {'Content-Type' => 'application/json'} - stub_request(:post, url).with(:headers => headers).to_return(:status => 200, :body => dummy_token_response.to_json, :headers => res_headers) + stub_request(:post, url).with(headers: headers).to_return(status: 200, body: dummy_token_response.to_json, headers: res_headers) end def dummy_token_response { - :access_token => @access_token, - :token_type => 'bearer', - :refresh_token => @refresh_token, - :expires_in => 3600, - :scope => 'user_profile' + access_token: @access_token, + token_type: 'bearer', + refresh_token: @refresh_token, + expires_in: 3600, + scope: 'user_profile' } end @@ -61,55 +61,55 @@ def add_mock_user_info url = 'https://zoom.us/v2/users/me' headers = {'Authorization' => "Bearer #{@access_token}"} res_headers = {'Content-Type' => 'application/json'} - stub_request(:get, url).with(:headers => headers).to_return(:status => 200, :body => dummy_user_info_response.to_json, :headers => res_headers) + 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_because_of_missing_scope WebMock.enable! url = 'https://zoom.us/v2/users/me' - response = {:code => 124, :message => 'Invalid access token.'} + response = {code: 124, message: 'Invalid access token.'} headers = {'Authorization' => "Bearer #{@access_token}"} res_headers = {'Content-Type' => 'application/json'} - stub_request(:get, url).with(:headers => headers).to_return(:status => 400, :body => response.to_json, :headers => res_headers) + 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'} + 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) + 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', - :first_name => 'Jane', - :last_name => 'Dev', - :email => 'jane.dev@email.com', - :type => 2, - :role_name => 'Owner', - :pmi => 1_234_567_890, - :use_pmi => false, - :vanity_url => 'https://janedevinc.zoom.us/my/janedev', - :personal_meeting_url => 'https://janedevinc.zoom.us/j/1234567890', - :timezone => 'America/Denver', - :verified => 1, - :dept => '', - :created_at => '2019-04-05T15:24:32Z', - :last_login_time => '2019-12-16T18:02:48Z', - :last_client_version => '4.6.12611.1124(mac)', - :pic_url => 'https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837', - :host_key => '533895', - :jid => 'kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us', - :group_ids => [], - :im_group_ids => ['3NXCD9VFTCOUH8LD-QciGw'], - :account_id => 'gVcjZnYYRLDbb_MfgHuaxg', - :language => 'en-US', - :phone_country => 'US', - :phone_number => '+1 1234567891', - :status => 'active' + id: 'KdYKjnimT4KPd8FFgQt9FQ', + first_name: 'Jane', + last_name: 'Dev', + email: 'jane.dev@email.com', + type: 2, + role_name: 'Owner', + pmi: 1_234_567_890, + use_pmi: false, + vanity_url: 'https://janedevinc.zoom.us/my/janedev', + personal_meeting_url: 'https://janedevinc.zoom.us/j/1234567890', + timezone: 'America/Denver', + verified: 1, + dept: '', + created_at: '2019-04-05T15:24:32Z', + last_login_time: '2019-12-16T18:02:48Z', + last_client_version: '4.6.12611.1124(mac)', + pic_url: 'https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837', + host_key: '533895', + jid: 'kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us', + group_ids: [], + im_group_ids: ['3NXCD9VFTCOUH8LD-QciGw'], + account_id: 'gVcjZnYYRLDbb_MfgHuaxg', + language: 'en-US', + phone_country: 'US', + phone_number: '+1 1234567891', + status: 'active' } end end