summaryrefslogtreecommitdiff
path: root/spec/gitlab_net_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/gitlab_net_spec.rb')
-rw-r--r--spec/gitlab_net_spec.rb293
1 files changed, 110 insertions, 183 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb
index 8df6fd3..be2f4ba 100644
--- a/spec/gitlab_net_spec.rb
+++ b/spec/gitlab_net_spec.rb
@@ -1,5 +1,6 @@
require_relative 'spec_helper'
require_relative '../lib/gitlab_net'
+require_relative '../lib/gitlab_access_status'
describe GitlabNet, vcr: true do
let(:gitlab_net) { described_class.new }
@@ -7,66 +8,57 @@ describe GitlabNet, vcr: true do
let(:base_api_endpoint) { 'http://localhost:3000/api/v4' }
let(:internal_api_endpoint) { 'http://localhost:3000/api/v4/internal' }
let(:project) { 'gitlab-org/gitlab-test.git' }
-
- let(:actor1) { Actor.new_from('key-1') }
- let(:bad_actor1) { Actor.new_from('key-777') }
- let(:actor2) { Actor.new_from('user-1') }
-
+ let(:key) { 'key-1' }
+ let(:key2) { 'key-2' }
let(:secret) { "0a3938d9d95d807e94d937af3a4fbbea\n" }
before do
$logger = double('logger').as_null_object
- allow(gitlab_net).to receive(:base_api_endpoint).and_return(base_api_endpoint)
- allow(gitlab_net).to receive(:secret_token).and_return(secret)
+ gitlab_net.stub(:base_api_endpoint).and_return(base_api_endpoint)
+ gitlab_net.stub(:secret_token).and_return(secret)
end
describe '#check' do
it 'should return 200 code for gitlab check' do
VCR.use_cassette("check-ok") do
result = gitlab_net.check
- expect(result.code).to eql('200')
+ result.code.should == '200'
end
end
it 'adds the secret_token to request' do
VCR.use_cassette("check-ok") do
- allow_any_instance_of(Net::HTTP::Get).to receive(:set_form_data).with(hash_including(secret_token: secret))
+ Net::HTTP::Get.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
gitlab_net.check
end
end
it "raises an exception if the connection fails" do
- allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
- expect do gitlab_net.check end.to raise_error(GitlabNet::ApiUnreachableError)
+ Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
+ expect { gitlab_net.check }.to raise_error(GitlabNet::ApiUnreachableError)
end
end
describe '#discover' do
- it 'returns user has based on key id' do
+ it 'should return user has based on key id' do
VCR.use_cassette("discover-ok") do
- user = gitlab_net.discover(actor1)
- expect(user['name']).to eql 'Administrator'
- expect(user['username']).to eql 'root'
- end
- end
-
- it 'returns nil if the user cannot be found' do
- VCR.use_cassette("discover-not-found") do
- expect(gitlab_net.discover(actor1)).to be_nil
+ user = gitlab_net.discover(key)
+ user['name'].should == 'Administrator'
+ user['username'].should == 'root'
end
end
it 'adds the secret_token to request' do
VCR.use_cassette("discover-ok") do
- allow_any_instance_of(Net::HTTP::Get).to receive(:set_form_data).with(hash_including(secret_token: secret))
- gitlab_net.discover(actor1)
+ Net::HTTP::Get.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
+ gitlab_net.discover(key)
end
end
it "raises an exception if the connection fails" do
VCR.use_cassette("discover-ok") do
- allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
- expect(gitlab_net.discover(actor1)).to be_nil
+ Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
+ expect { gitlab_net.discover(key) }.to raise_error(GitlabNet::ApiUnreachableError)
end
end
end
@@ -75,10 +67,10 @@ describe GitlabNet, vcr: true do
context 'lfs authentication succeeded' do
it 'should return the correct data' do
VCR.use_cassette('lfs-authenticate-ok') do
- lfs_access = gitlab_net.lfs_authenticate(actor1, project)
- expect(lfs_access.username).to eql 'root'
- expect(lfs_access.lfs_token).to eql 'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
- expect(lfs_access.repository_http_path).to eql URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s
+ lfs_access = gitlab_net.lfs_authenticate(key, project)
+ lfs_access.username.should == 'root'
+ lfs_access.lfs_token.should == 'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
+ lfs_access.repository_http_path.should == URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s
end
end
end
@@ -89,7 +81,7 @@ describe GitlabNet, vcr: true do
it 'should return message' do
VCR.use_cassette("broadcast_message-ok") do
result = gitlab_net.broadcast_message
- expect(result["message"]).to eql "Message"
+ result["message"].should == "Message"
end
end
end
@@ -98,7 +90,7 @@ describe GitlabNet, vcr: true do
it 'should return nil' do
VCR.use_cassette("broadcast_message-none") do
result = gitlab_net.broadcast_message
- expect(result).to eql({})
+ result.should == {}
end
end
end
@@ -110,13 +102,13 @@ describe GitlabNet, vcr: true do
let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" }
it "sends the given arguments as encoded URL parameters" do
- expect(gitlab_net).to receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
+ gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
gitlab_net.merge_request_urls(gl_repository, project, changes)
end
it "omits the gl_repository parameter if it's nil" do
- expect(gitlab_net).to receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
+ gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
gitlab_net.merge_request_urls(nil, project, changes)
end
@@ -143,7 +135,8 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.pre_receive(gl_repository) }
it 'sends the correct parameters and returns the request body parsed' do
- allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
+ Net::HTTP::Post.any_instance.should_receive(:set_form_data)
+ .with(hash_including(params))
VCR.use_cassette("pre-receive") { subject }
end
@@ -154,9 +147,9 @@ describe GitlabNet, vcr: true do
end
end
- it 'throws a NotFoundError when pre-receive is not available' do
+ it 'throws a NotFound error when pre-receive is not available' do
VCR.use_cassette("pre-receive-not-found") do
- expect do subject end.to raise_error(GitlabNet::NotFoundError)
+ expect { subject }.to raise_error(GitlabNet::NotFound)
end
end
end
@@ -165,7 +158,7 @@ describe GitlabNet, vcr: true do
let(:gl_repository) { "project-1" }
let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" }
let(:params) do
- { gl_repository: gl_repository, identifier: actor1.identifier, changes: changes }
+ { gl_repository: gl_repository, identifier: key, changes: changes }
end
let(:merge_request_urls) do
[{
@@ -175,10 +168,11 @@ describe GitlabNet, vcr: true do
}]
end
- subject { gitlab_net.post_receive(gl_repository, actor1, changes) }
+ subject { gitlab_net.post_receive(gl_repository, key, changes) }
it 'sends the correct parameters' do
- allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
+ Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(params))
+
VCR.use_cassette("post-receive") do
subject
@@ -193,9 +187,9 @@ describe GitlabNet, vcr: true do
end
end
- it 'throws a NotFoundError when post-receive is not available' do
+ it 'throws a NotFound error when post-receive is not available' do
VCR.use_cassette("post-receive-not-found") do
- expect do subject end.to raise_error(GitlabNet::NotFoundError)
+ expect { subject }.to raise_error(GitlabNet::NotFound)
end
end
end
@@ -206,21 +200,21 @@ describe GitlabNet, vcr: true do
it "should return nil when the resource is not implemented" do
VCR.use_cassette("ssh-key-not-implemented") do
result = gitlab_net.authorized_key("whatever")
- expect(result).to be_nil
+ result.should be_nil
end
end
it "should return nil when the fingerprint is not found" do
VCR.use_cassette("ssh-key-not-found") do
result = gitlab_net.authorized_key("whatever")
- expect(result).to be_nil
+ result.should be_nil
end
end
it "should return a ssh key with a valid fingerprint" do
VCR.use_cassette("ssh-key-ok") do
result = gitlab_net.authorized_key(ssh_key)
- expect(result).to eql({
+ result.should eq({
"can_push" => false,
"created_at" => "2017-06-21T09:50:07.150Z",
"id" => 99,
@@ -234,7 +228,7 @@ describe GitlabNet, vcr: true do
describe '#two_factor_recovery_codes' do
it 'returns two factor recovery codes' do
VCR.use_cassette('two-factor-recovery-codes') do
- result = gitlab_net.two_factor_recovery_codes(actor1)
+ result = gitlab_net.two_factor_recovery_codes(key)
expect(result['success']).to be_truthy
expect(result['recovery_codes']).to eq(['f67c514de60c4953','41278385fc00c1e0'])
end
@@ -242,7 +236,7 @@ describe GitlabNet, vcr: true do
it 'returns false when recovery codes cannot be generated' do
VCR.use_cassette('two-factor-recovery-codes-fail') do
- result = gitlab_net.two_factor_recovery_codes(bad_actor1)
+ result = gitlab_net.two_factor_recovery_codes('key-777')
expect(result['success']).to be_falsey
expect(result['message']).to eq('Could not find the given key')
end
@@ -258,7 +252,7 @@ describe GitlabNet, vcr: true do
it 'sets the arguments as form parameters' do
VCR.use_cassette('notify-post-receive') do
- allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
+ Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(params))
gitlab_net.notify_post_receive(gl_repository, repo_path)
end
end
@@ -271,159 +265,92 @@ describe GitlabNet, vcr: true do
end
describe '#check_access' do
- context 'something is wrong with the API response' do
- context 'but response is JSON parsable' do
- it 'raises an UnknownError exception' do
- VCR.use_cassette('failed-push') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'ssh')
- end.to raise_error(UnknownError, 'API is not accessible: An internal server error occurred')
- end
- end
- end
-
- context 'but response is not JSON parsable' do
- it 'raises an UnknownError exception' do
- VCR.use_cassette('failed-push-unparsable') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'ssh')
- end.to raise_error(UnknownError, 'API is not accessible')
- end
- end
- end
- end
-
context 'ssh key with access nil, to project' do
- it 'should allow push access for host' do
- VCR.use_cassette('allowed-push') do
- action = gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'ssh')
- expect(action).to be_instance_of(Action::Gitaly)
+ it 'should allow pull access for host' do
+ VCR.use_cassette("allowed-pull") do
+ access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh')
+ access.allowed?.should be_truthy
end
end
it 'adds the secret_token to the request' do
- VCR.use_cassette('allowed-pull') do
- allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(secret_token: secret))
- gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'ssh')
+ VCR.use_cassette("allowed-pull") do
+ Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
+ gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh')
end
end
- it 'should allow pull access for host' do
- VCR.use_cassette("allowed-pull") do
- action = gitlab_net.check_access('git-upload-pack', nil, project, actor1, changes, 'ssh')
- expect(action).to be_instance_of(Action::Gitaly)
+ it 'should allow push access for host' do
+ VCR.use_cassette("allowed-push") do
+ access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'ssh')
+ access.allowed?.should be_truthy
end
end
end
context 'ssh access has been disabled' do
it 'should deny pull access for host' do
- VCR.use_cassette('ssh-pull-disabled-old') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor1, changes, 'http')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
- end
-
VCR.use_cassette('ssh-pull-disabled') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor1, changes, 'http')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
+ access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'ssh')
+ access.allowed?.should be_falsey
+ access.message.should eq 'Git access over SSH is not allowed'
end
end
it 'should deny push access for host' do
- VCR.use_cassette('ssh-push-disabled-old') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
- end
-
VCR.use_cassette('ssh-push-disabled') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
+ access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'ssh')
+ access.allowed?.should be_falsey
+ access.message.should eq 'Git access over SSH is not allowed'
end
end
end
context 'http access has been disabled' do
it 'should deny pull access for host' do
- VCR.use_cassette('http-pull-disabled-old') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor1, changes, 'http')
- end.to raise_error(AccessDeniedError, 'Pulling over HTTP is not allowed.')
- end
-
VCR.use_cassette('http-pull-disabled') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor1, changes, 'http')
- end.to raise_error(AccessDeniedError, 'Pulling over HTTP is not allowed.')
+ access = gitlab_net.check_access('git-upload-pack', nil, project, key, changes, 'http')
+ access.allowed?.should be_falsey
+ access.message.should eq 'Pulling over HTTP is not allowed.'
end
end
it 'should deny push access for host' do
- VCR.use_cassette('http-push-disabled-old') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'http')
- end.to raise_error(AccessDeniedError, 'Pushing over HTTP is not allowed.')
- end
-
- VCR.use_cassette('http-push-disabled') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor1, changes, 'http')
- end.to raise_error(AccessDeniedError, 'Pushing over HTTP is not allowed.')
+ VCR.use_cassette("http-push-disabled") do
+ access = gitlab_net.check_access('git-receive-pack', nil, project, key, changes, 'http')
+ access.allowed?.should be_falsey
+ access.message.should eq 'Pushing over HTTP is not allowed.'
end
end
end
context 'ssh key without access to project' do
it 'should deny pull access for host' do
- VCR.use_cassette('ssh-pull-project-denied-old') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor2, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
- end
-
- VCR.use_cassette('ssh-pull-project-denied') do
- expect do
- gitlab_net.check_access('git-receive-pack', nil, project, actor2, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
+ VCR.use_cassette("ssh-pull-project-denied") do
+ access = gitlab_net.check_access('git-receive-pack', nil, project, key2, changes, 'ssh')
+ access.allowed?.should be_falsey
end
end
it 'should deny push access for host' do
- VCR.use_cassette('ssh-push-project-denied-old') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor2, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
- end
-
- VCR.use_cassette('ssh-push-project-denied') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor2, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
+ VCR.use_cassette("ssh-push-project-denied") do
+ access = gitlab_net.check_access('git-upload-pack', nil, project, key2, changes, 'ssh')
+ access.allowed?.should be_falsey
end
end
it 'should deny push access for host (with user)' do
- VCR.use_cassette('ssh-push-project-denied-with-user-old') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor2, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
- end
-
- VCR.use_cassette('ssh-push-project-denied-with-user') do
- expect do
- gitlab_net.check_access('git-upload-pack', nil, project, actor2, changes, 'ssh')
- end.to raise_error(AccessDeniedError, 'Git access over SSH is not allowed')
+ VCR.use_cassette("ssh-push-project-denied-with-user") do
+ access = gitlab_net.check_access('git-upload-pack', nil, project, 'user-2', changes, 'ssh')
+ access.allowed?.should be_falsey
end
end
end
it "raises an exception if the connection fails" do
- allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
+ Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
expect {
- gitlab_net.check_access('git-upload-pack', nil, project, actor1, changes, 'ssh')
+ gitlab_net.check_access('git-upload-pack', nil, project, 'user-1', changes, 'ssh')
}.to raise_error(GitlabNet::ApiUnreachableError)
end
end
@@ -450,8 +377,8 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_client_for, URI('https://localhost/') }
before do
- allow(gitlab_net).to receive(:cert_store)
- allow(gitlab_net.send(:config)).to receive(:http_settings).and_return({ 'self_signed_cert' => true })
+ gitlab_net.stub :cert_store
+ gitlab_net.send(:config).stub(:http_settings) { {'self_signed_cert' => true} }
end
its(:verify_mode) { should eq(OpenSSL::SSL::VERIFY_NONE) }
@@ -471,11 +398,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url }
before do
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
- expect(Net::HTTP::Get).to receive(:new).with('/', {}).and_return(get)
- expect(get).to receive(:basic_auth).with(user, password).once
- expect(get).to receive(:set_form_data).with(hash_including(secret_token: secret)).once
+ gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
+ gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
+ Net::HTTP::Get.should_receive(:new).with('/', {}).and_return(get)
+ get.should_receive(:basic_auth).with(user, password).once
+ get.should_receive(:set_form_data).with(hash_including(secret_token: secret)).once
end
it { should_not be_nil }
@@ -485,11 +412,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, params: params, headers: headers }
before do
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
- expect(Net::HTTP::Get).to receive(:new).with('/', headers).and_return(get)
- expect(get).to receive(:basic_auth).with(user, password).once
- expect(get).to receive(:set_form_data).with({ 'key1' => 'value1', secret_token: secret }).once
+ gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
+ gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
+ Net::HTTP::Get.should_receive(:new).with('/', headers).and_return(get)
+ get.should_receive(:basic_auth).with(user, password).once
+ get.should_receive(:set_form_data).with({ 'key1' => 'value1', secret_token: secret }).once
end
it { should_not be_nil }
@@ -499,11 +426,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, headers: headers }
before do
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
- expect(Net::HTTP::Get).to receive(:new).with('/', headers).and_return(get)
- expect(get).to receive(:basic_auth).with(user, password).once
- expect(get).to receive(:set_form_data).with(hash_including(secret_token: secret)).once
+ gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
+ gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
+ Net::HTTP::Get.should_receive(:new).with('/', headers).and_return(get)
+ get.should_receive(:basic_auth).with(user, password).once
+ get.should_receive(:set_form_data).with(hash_including(secret_token: secret)).once
end
it { should_not be_nil }
@@ -514,12 +441,12 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, options: options }
before do
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('user').and_return(user)
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password').and_return(password)
- expect(Net::HTTP::Get).to receive(:new).with('/', {}).and_return(get)
- expect(get).to receive(:basic_auth).with(user, password).once
- expect(get).to receive(:body=).with({ 'key2' => 'value2', secret_token: secret }.to_json).once
- expect(get).to_not receive(:set_form_data)
+ gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
+ gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
+ Net::HTTP::Get.should_receive(:new).with('/', {}).and_return(get)
+ get.should_receive(:basic_auth).with(user, password).once
+ get.should_receive(:body=).with({ 'key2' => 'value2', secret_token: secret }.to_json).once
+ get.should_not_receive(:set_form_data)
end
it { should_not be_nil }
@@ -530,7 +457,7 @@ describe GitlabNet, vcr: true do
context 'Unix socket' do
it 'sets the Host header to "localhost"' do
gitlab_net = described_class.new
- expect(gitlab_net).to receive(:secret_token).and_return(secret)
+ gitlab_net.should_receive(:secret_token).and_return(secret)
request = gitlab_net.send(:http_request_for, :get, URI('http+unix://%2Ffoo'))
@@ -542,12 +469,12 @@ describe GitlabNet, vcr: true do
describe '#cert_store' do
let(:store) do
double(OpenSSL::X509::Store).tap do |store|
- allow(OpenSSL::X509::Store).to receive(:new).and_return(store)
+ OpenSSL::X509::Store.stub(:new) { store }
end
end
before :each do
- expect(store).to receive(:set_default_paths).once
+ store.should_receive(:set_default_paths).once
end
after do
@@ -555,17 +482,17 @@ describe GitlabNet, vcr: true do
end
it "calls add_file with http_settings['ca_file']" do
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_file').and_return('test_file')
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_path').and_return(nil)
- expect(store).to receive(:add_file).with('test_file')
- expect(store).to_not receive(:add_path)
+ gitlab_net.send(:config).http_settings.stub(:[]).with('ca_file') { 'test_file' }
+ gitlab_net.send(:config).http_settings.stub(:[]).with('ca_path') { nil }
+ store.should_receive(:add_file).with('test_file')
+ store.should_not_receive(:add_path)
end
it "calls add_path with http_settings['ca_path']" do
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_file').and_return(nil)
- allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_path').and_return('test_path')
- expect(store).to_not receive(:add_file)
- expect(store).to receive(:add_path).with('test_path')
+ gitlab_net.send(:config).http_settings.stub(:[]).with('ca_file') { nil }
+ gitlab_net.send(:config).http_settings.stub(:[]).with('ca_path') { 'test_path' }
+ store.should_not_receive(:add_file)
+ store.should_receive(:add_path).with('test_path')
end
end
end