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, 183 insertions, 110 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb
index be2f4ba..8df6fd3 100644
--- a/spec/gitlab_net_spec.rb
+++ b/spec/gitlab_net_spec.rb
@@ -1,6 +1,5 @@
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 }
@@ -8,57 +7,66 @@ 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(:key) { 'key-1' }
- let(:key2) { 'key-2' }
+
+ let(:actor1) { Actor.new_from('key-1') }
+ let(:bad_actor1) { Actor.new_from('key-777') }
+ let(:actor2) { Actor.new_from('user-1') }
+
let(:secret) { "0a3938d9d95d807e94d937af3a4fbbea\n" }
before do
$logger = double('logger').as_null_object
- gitlab_net.stub(:base_api_endpoint).and_return(base_api_endpoint)
- gitlab_net.stub(:secret_token).and_return(secret)
+ allow(gitlab_net).to receive(:base_api_endpoint).and_return(base_api_endpoint)
+ allow(gitlab_net).to receive(: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
- result.code.should == '200'
+ expect(result.code).to eql('200')
end
end
it 'adds the secret_token to request' do
VCR.use_cassette("check-ok") do
- Net::HTTP::Get.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
+ allow_any_instance_of(Net::HTTP::Get).to receive(:set_form_data).with(hash_including(secret_token: secret))
gitlab_net.check
end
end
it "raises an exception if the connection fails" do
- Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
- expect { gitlab_net.check }.to raise_error(GitlabNet::ApiUnreachableError)
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
+ expect do gitlab_net.check end.to raise_error(GitlabNet::ApiUnreachableError)
end
end
describe '#discover' do
- it 'should return user has based on key id' do
+ it 'returns user has based on key id' do
VCR.use_cassette("discover-ok") do
- user = gitlab_net.discover(key)
- user['name'].should == 'Administrator'
- user['username'].should == 'root'
+ 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
end
end
it 'adds the secret_token to request' do
VCR.use_cassette("discover-ok") do
- Net::HTTP::Get.any_instance.should_receive(:set_form_data).with(hash_including(secret_token: secret))
- gitlab_net.discover(key)
+ allow_any_instance_of(Net::HTTP::Get).to receive(:set_form_data).with(hash_including(secret_token: secret))
+ gitlab_net.discover(actor1)
end
end
it "raises an exception if the connection fails" do
VCR.use_cassette("discover-ok") do
- Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
- expect { gitlab_net.discover(key) }.to raise_error(GitlabNet::ApiUnreachableError)
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
+ expect(gitlab_net.discover(actor1)).to be_nil
end
end
end
@@ -67,10 +75,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(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
+ 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
end
end
end
@@ -81,7 +89,7 @@ describe GitlabNet, vcr: true do
it 'should return message' do
VCR.use_cassette("broadcast_message-ok") do
result = gitlab_net.broadcast_message
- result["message"].should == "Message"
+ expect(result["message"]).to eql "Message"
end
end
end
@@ -90,7 +98,7 @@ describe GitlabNet, vcr: true do
it 'should return nil' do
VCR.use_cassette("broadcast_message-none") do
result = gitlab_net.broadcast_message
- result.should == {}
+ expect(result).to eql({})
end
end
end
@@ -102,13 +110,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
- gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
+ expect(gitlab_net).to 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
- gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
+ expect(gitlab_net).to receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
gitlab_net.merge_request_urls(nil, project, changes)
end
@@ -135,8 +143,7 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.pre_receive(gl_repository) }
it 'sends the correct parameters and returns the request body parsed' do
- Net::HTTP::Post.any_instance.should_receive(:set_form_data)
- .with(hash_including(params))
+ allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
VCR.use_cassette("pre-receive") { subject }
end
@@ -147,9 +154,9 @@ describe GitlabNet, vcr: true do
end
end
- it 'throws a NotFound error when pre-receive is not available' do
+ it 'throws a NotFoundError when pre-receive is not available' do
VCR.use_cassette("pre-receive-not-found") do
- expect { subject }.to raise_error(GitlabNet::NotFound)
+ expect do subject end.to raise_error(GitlabNet::NotFoundError)
end
end
end
@@ -158,7 +165,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: key, changes: changes }
+ { gl_repository: gl_repository, identifier: actor1.identifier, changes: changes }
end
let(:merge_request_urls) do
[{
@@ -168,11 +175,10 @@ describe GitlabNet, vcr: true do
}]
end
- subject { gitlab_net.post_receive(gl_repository, key, changes) }
+ subject { gitlab_net.post_receive(gl_repository, actor1, changes) }
it 'sends the correct parameters' do
- Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(params))
-
+ allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
VCR.use_cassette("post-receive") do
subject
@@ -187,9 +193,9 @@ describe GitlabNet, vcr: true do
end
end
- it 'throws a NotFound error when post-receive is not available' do
+ it 'throws a NotFoundError when post-receive is not available' do
VCR.use_cassette("post-receive-not-found") do
- expect { subject }.to raise_error(GitlabNet::NotFound)
+ expect do subject end.to raise_error(GitlabNet::NotFoundError)
end
end
end
@@ -200,21 +206,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")
- result.should be_nil
+ expect(result).to 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")
- result.should be_nil
+ expect(result).to 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)
- result.should eq({
+ expect(result).to eql({
"can_push" => false,
"created_at" => "2017-06-21T09:50:07.150Z",
"id" => 99,
@@ -228,7 +234,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(key)
+ result = gitlab_net.two_factor_recovery_codes(actor1)
expect(result['success']).to be_truthy
expect(result['recovery_codes']).to eq(['f67c514de60c4953','41278385fc00c1e0'])
end
@@ -236,7 +242,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('key-777')
+ result = gitlab_net.two_factor_recovery_codes(bad_actor1)
expect(result['success']).to be_falsey
expect(result['message']).to eq('Could not find the given key')
end
@@ -252,7 +258,7 @@ describe GitlabNet, vcr: true do
it 'sets the arguments as form parameters' do
VCR.use_cassette('notify-post-receive') do
- Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(params))
+ allow_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
gitlab_net.notify_post_receive(gl_repository, repo_path)
end
end
@@ -265,92 +271,159 @@ 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 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
+ 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)
end
end
it 'adds the secret_token to the request' do
- 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')
+ 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')
end
end
- 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
+ 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)
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
- 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'
+ 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
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
- 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'
+ 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
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
- 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.'
+ 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
end
it 'should deny push access for host' do
- 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.'
+ 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.')
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") do
- access = gitlab_net.check_access('git-receive-pack', nil, project, key2, changes, 'ssh')
- access.allowed?.should be_falsey
+ 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')
end
end
it 'should deny push access for host' do
- 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
+ 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')
end
end
it 'should deny push access for host (with user)' do
- 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
+ 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')
end
end
end
it "raises an exception if the connection fails" do
- Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
expect {
- gitlab_net.check_access('git-upload-pack', nil, project, 'user-1', changes, 'ssh')
+ gitlab_net.check_access('git-upload-pack', nil, project, actor1, changes, 'ssh')
}.to raise_error(GitlabNet::ApiUnreachableError)
end
end
@@ -377,8 +450,8 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_client_for, URI('https://localhost/') }
before do
- gitlab_net.stub :cert_store
- gitlab_net.send(:config).stub(:http_settings) { {'self_signed_cert' => true} }
+ allow(gitlab_net).to receive(:cert_store)
+ allow(gitlab_net.send(:config)).to receive(:http_settings).and_return({ 'self_signed_cert' => true })
end
its(:verify_mode) { should eq(OpenSSL::SSL::VERIFY_NONE) }
@@ -398,11 +471,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url }
before do
- 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
+ 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
end
it { should_not be_nil }
@@ -412,11 +485,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, params: params, headers: headers }
before do
- 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
+ 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
end
it { should_not be_nil }
@@ -426,11 +499,11 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, headers: headers }
before do
- 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
+ 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
end
it { should_not be_nil }
@@ -441,12 +514,12 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.send :http_request_for, :get, url, options: options }
before do
- 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)
+ 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)
end
it { should_not be_nil }
@@ -457,7 +530,7 @@ describe GitlabNet, vcr: true do
context 'Unix socket' do
it 'sets the Host header to "localhost"' do
gitlab_net = described_class.new
- gitlab_net.should_receive(:secret_token).and_return(secret)
+ expect(gitlab_net).to receive(:secret_token).and_return(secret)
request = gitlab_net.send(:http_request_for, :get, URI('http+unix://%2Ffoo'))
@@ -469,12 +542,12 @@ describe GitlabNet, vcr: true do
describe '#cert_store' do
let(:store) do
double(OpenSSL::X509::Store).tap do |store|
- OpenSSL::X509::Store.stub(:new) { store }
+ allow(OpenSSL::X509::Store).to receive(:new).and_return(store)
end
end
before :each do
- store.should_receive(:set_default_paths).once
+ expect(store).to receive(:set_default_paths).once
end
after do
@@ -482,17 +555,17 @@ describe GitlabNet, vcr: true do
end
it "calls add_file with http_settings['ca_file']" do
- 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)
+ 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)
end
it "calls add_path with http_settings['ca_path']" do
- 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')
+ 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')
end
end
end