2015-03-22 21:07:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Gitlab::GithubImport::Client, lib: true do
|
2015-03-22 21:07:33 -04:00
|
|
|
let(:token) { '123456' }
|
2016-04-22 15:43:10 -04:00
|
|
|
let(:github_provider) { Settingslogic.new('app_id' => 'asd123', 'app_secret' => 'asd123', 'name' => 'github', 'args' => { 'client_options' => {} }) }
|
|
|
|
|
|
|
|
subject(:client) { described_class.new(token) }
|
2015-03-22 21:07:33 -04:00
|
|
|
|
|
|
|
before do
|
2016-04-22 15:43:10 -04:00
|
|
|
allow(Gitlab.config.omniauth).to receive(:providers).and_return([github_provider])
|
2015-03-22 21:07:33 -04:00
|
|
|
end
|
|
|
|
|
2016-04-22 15:43:10 -04:00
|
|
|
it 'convert OAuth2 client options to symbols' do
|
2015-03-22 21:07:33 -04:00
|
|
|
client.client.options.keys.each do |key|
|
|
|
|
expect(key).to be_kind_of(Symbol)
|
|
|
|
end
|
|
|
|
end
|
2016-04-22 15:43:10 -04:00
|
|
|
|
|
|
|
it 'does not crash (e.g. Settingslogic::MissingSetting) when verify_ssl config is not present' do
|
|
|
|
expect { client.api }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'allow SSL verification to be configurable on API' do
|
|
|
|
before do
|
|
|
|
github_provider['verify_ssl'] = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses supplied value' do
|
|
|
|
expect(client.client.options[:connection_opts][:ssl]).to eq({ verify: false })
|
|
|
|
expect(client.api.connection_options[:ssl]).to eq({ verify: false })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when provider does not specity an API endpoint' do
|
|
|
|
it 'uses GitHub root API endpoint' do
|
|
|
|
expect(client.api.api_endpoint).to eq 'https://api.github.com/'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when provider specify a custom API endpoint' do
|
|
|
|
before do
|
|
|
|
github_provider['args']['client_options']['site'] = 'https://github.company.com/'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the custom API endpoint' do
|
|
|
|
expect(OmniAuth::Strategies::GitHub).not_to receive(:default_options)
|
|
|
|
expect(client.api.api_endpoint).to eq 'https://github.company.com/'
|
|
|
|
end
|
|
|
|
end
|
2015-03-22 21:07:33 -04:00
|
|
|
end
|