debian-mirror-gitlab/spec/lib/google_api/auth_spec.rb

59 lines
1.6 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe GoogleApi::Auth do
2018-03-17 18:26:18 +05:30
let(:redirect_uri) { 'http://localhost:3000/google_api/authorizations/callback' }
let(:redirect_to) { 'http://localhost:3000/namaspace/project/clusters' }
let(:client) do
GoogleApi::CloudPlatform::Client
.new(nil, redirect_uri, state: redirect_to)
end
describe '#authorize_url' do
subject { client.authorize_url }
it 'returns authorize_url' do
is_expected.to start_with('https://accounts.google.com/o/oauth2')
is_expected.to include(URI.encode(redirect_uri, URI::PATTERN::RESERVED))
is_expected.to include(URI.encode(redirect_to, URI::PATTERN::RESERVED))
end
end
describe '#get_token' do
let(:token) do
double.tap do |dbl|
allow(dbl).to receive(:token).and_return('token')
allow(dbl).to receive(:expires_at).and_return('expires_at')
end
end
before do
2020-01-01 13:55:28 +05:30
allow_next_instance_of(OAuth2::Strategy::AuthCode) do |instance|
allow(instance).to receive(:get_token).and_return(token)
end
2018-03-17 18:26:18 +05:30
end
it 'returns token and expires_at' do
token, expires_at = client.get_token('xxx')
expect(token).to eq('token')
expect(expires_at).to eq('expires_at')
end
2020-05-24 23:13:21 +05:30
it 'expects the client to receive default options' do
config = Gitlab::Auth::OAuth::Provider.config_for('google_oauth2')
expect(OAuth2::Client).to receive(:new).with(
config.app_id,
config.app_secret,
hash_including(
**config.args.client_options.deep_symbolize_keys
)
).and_call_original
client.get_token('xxx')
end
2018-03-17 18:26:18 +05:30
end
end