|
11 | 11 | require 'minitest/autorun' |
12 | 12 | require 'minitest/reporters' |
13 | 13 | Minitest::Reporters.use! |
| 14 | +require 'webmock/minitest' |
14 | 15 |
|
15 | 16 | require 'omniauth-zoom' |
| 17 | +require 'omniauth' |
| 18 | +require 'rack/test' |
| 19 | + |
| 20 | +class StrategyTest < Minitest::Test |
| 21 | + include OmniAuth::Test::StrategyTestCase |
| 22 | + include Rack::Test::Methods |
| 23 | + |
| 24 | + def setup |
| 25 | + ENV['OAUTH_DEBUG'] = 'true' |
| 26 | + @logger = Logger.new STDOUT |
| 27 | + OmniAuth.config.logger = @logger |
| 28 | + |
| 29 | + @client_id = 'DUMMY_CLIENT_ID' |
| 30 | + @client_secret = 'DUMMY_CLIENT_SECRET' |
| 31 | + @scope = 'user_profile' |
| 32 | + @options = {:scope => @scope, :provider_ignores_state => true} |
| 33 | + @authorization_code = 'DUMMY_AUTH_CODE' |
| 34 | + @access_token = 'DUMMY_TOKEN' |
| 35 | + end |
| 36 | + |
| 37 | +protected |
| 38 | + |
| 39 | + def strategy |
| 40 | + [OmniAuth::Strategies::Zoom, @client_id, @client_secret, @options] |
| 41 | + end |
| 42 | + |
| 43 | + def add_mock_exchange_token |
| 44 | + WebMock.enable! |
| 45 | + url = "https://zoom.us/oauth/token?code=#{@authorization_code}&grant_type=authorization_code&redirect_uri=http://example.org/auth/zoom/callback" |
| 46 | + secret = Base64.strict_encode64("#{@client_id}:#{@client_secret}") |
| 47 | + headers = {'Authorization' => "Basic #{secret}"} |
| 48 | + res_headers = {'Content-Type' => 'application/json'} |
| 49 | + stub_request(:post, url).with(:headers => headers).to_return(:status => 200, :body => dummy_token_response.to_json, :headers => res_headers) |
| 50 | + end |
| 51 | + |
| 52 | + def dummy_token_response |
| 53 | + { |
| 54 | + :access_token => @access_token, |
| 55 | + :token_type => 'bearer', |
| 56 | + :refresh_token => 'DUMMY_REFRESH_TOKEN', |
| 57 | + :expires_in => 3600, |
| 58 | + :scope => 'user_profile' |
| 59 | + } |
| 60 | + end |
| 61 | + |
| 62 | + def add_mock_user_info |
| 63 | + WebMock.enable! |
| 64 | + url = 'https://zoom.us/v2/users/me' |
| 65 | + headers = {'Authorization' => "Bearer #{@access_token}"} |
| 66 | + res_headers = {'Content-Type' => 'application/json'} |
| 67 | + stub_request(:get, url).with(:headers => headers).to_return(:status => 200, :body => dummy_user_info_response.to_json, :headers => res_headers) |
| 68 | + end |
| 69 | + |
| 70 | + def add_mock_user_info_then_fail |
| 71 | + WebMock.enable! |
| 72 | + url = 'https://zoom.us/v2/users/me' |
| 73 | + response = {:code => 124, :message => 'Invalid access token.'} |
| 74 | + headers = {'Authorization' => "Bearer #{@access_token}"} |
| 75 | + res_headers = {'Content-Type' => 'application/json'} |
| 76 | + stub_request(:get, url).with(:headers => headers).to_return(:status => 400, :body => response.to_json, :headers => res_headers) |
| 77 | + end |
| 78 | + |
| 79 | + def dummy_user_info_response |
| 80 | + { |
| 81 | + :id => 'KdYKjnimT4KPd8FFgQt9FQ', |
| 82 | + :first_name => 'Jane', |
| 83 | + :last_name => 'Dev', |
| 84 | + :email => 'jane.dev@email.com', |
| 85 | + :type => 2, |
| 86 | + :role_name => 'Owner', |
| 87 | + :pmi => 1_234_567_890, |
| 88 | + :use_pmi => false, |
| 89 | + :vanity_url => 'https://janedevinc.zoom.us/my/janedev', |
| 90 | + :personal_meeting_url => 'https://janedevinc.zoom.us/j/1234567890', |
| 91 | + :timezone => 'America/Denver', |
| 92 | + :verified => 1, |
| 93 | + :dept => '', |
| 94 | + :created_at => '2019-04-05T15:24:32Z', |
| 95 | + :last_login_time => '2019-12-16T18:02:48Z', |
| 96 | + :last_client_version => '4.6.12611.1124(mac)', |
| 97 | + :pic_url => 'https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837', |
| 98 | + :host_key => '533895', |
| 99 | + :jid => 'kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us', |
| 100 | + :group_ids => [], |
| 101 | + :im_group_ids => ['3NXCD9VFTCOUH8LD-QciGw'], |
| 102 | + :account_id => 'gVcjZnYYRLDbb_MfgHuaxg', |
| 103 | + :language => 'en-US', |
| 104 | + :phone_country => 'US', |
| 105 | + :phone_number => '+1 1234567891', |
| 106 | + :status => 'active' |
| 107 | + } |
| 108 | + end |
| 109 | +end |
0 commit comments