summaryrefslogtreecommitdiff
path: root/spec/gitlab_net_spec.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2018-08-14 14:54:33 -0500
committerRobert Speicher <rspeicher@gmail.com>2018-08-15 16:04:11 -0500
commitcfec435a64ec7571a8333dc754afac0a41ebc6d8 (patch)
tree7fb17b508a94bcd73deb40318f70205b100d985c /spec/gitlab_net_spec.rb
parentc5c97dd39409290b02209d45b147babdcf1474b5 (diff)
downloadgitlab-shell-cfec435a64ec7571a8333dc754afac0a41ebc6d8.tar.gz
Autocorrect specs via `transpec -k its -v stub_with_hash`
Diffstat (limited to 'spec/gitlab_net_spec.rb')
-rw-r--r--spec/gitlab_net_spec.rb154
1 files changed, 77 insertions, 77 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb
index be2f4ba..c518d0b 100644
--- a/spec/gitlab_net_spec.rb
+++ b/spec/gitlab_net_spec.rb
@@ -14,27 +14,27 @@ describe GitlabNet, vcr: true do
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 eq('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))
+ expect_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)
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
expect { gitlab_net.check }.to raise_error(GitlabNet::ApiUnreachableError)
end
end
@@ -43,21 +43,21 @@ describe GitlabNet, vcr: true do
it 'should return 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'
+ expect(user['name']).to eq('Administrator')
+ expect(user['username']).to eq('root')
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))
+ expect_any_instance_of(Net::HTTP::Get).to 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
- Net::HTTP.any_instance.stub(:request).and_raise(StandardError)
+ allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(StandardError)
expect { gitlab_net.discover(key) }.to raise_error(GitlabNet::ApiUnreachableError)
end
end
@@ -68,9 +68,9 @@ describe GitlabNet, vcr: true 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
+ expect(lfs_access.username).to eq('root')
+ expect(lfs_access.lfs_token).to eq('Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ')
+ expect(lfs_access.repository_http_path).to eq(URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s)
end
end
end
@@ -81,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
- result["message"].should == "Message"
+ expect(result["message"]).to eq("Message")
end
end
end
@@ -90,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
- result.should == {}
+ expect(result).to eq({})
end
end
end
@@ -102,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
- 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,7 +135,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)
+ expect_any_instance_of(Net::HTTP::Post).to receive(:set_form_data)
.with(hash_including(params))
VCR.use_cassette("pre-receive") { subject }
@@ -171,7 +171,7 @@ describe GitlabNet, vcr: true do
subject { gitlab_net.post_receive(gl_repository, key, changes) }
it 'sends the correct parameters' do
- Net::HTTP::Post.any_instance.should_receive(:set_form_data).with(hash_including(params))
+ expect_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params))
VCR.use_cassette("post-receive") do
@@ -200,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")
- 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 eq({
"can_push" => false,
"created_at" => "2017-06-21T09:50:07.150Z",
"id" => 99,
@@ -252,7 +252,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))
+ expect_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
@@ -269,13 +269,13 @@ describe GitlabNet, vcr: true 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
+ expect(access.allowed?).to be_truthy
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))
+ expect_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, key, changes, 'ssh')
end
end
@@ -283,7 +283,7 @@ describe GitlabNet, vcr: true do
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
+ expect(access.allowed?).to be_truthy
end
end
end
@@ -292,16 +292,16 @@ describe GitlabNet, vcr: true do
it 'should deny pull access for host' do
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(access.allowed?).to be_falsey
+ expect(access.message).to eq 'Git access over SSH is not allowed'
end
end
it 'should deny push access for host' do
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(access.allowed?).to be_falsey
+ expect(access.message).to eq 'Git access over SSH is not allowed'
end
end
end
@@ -310,16 +310,16 @@ describe GitlabNet, vcr: true do
it 'should deny pull access for host' do
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(access.allowed?).to be_falsey
+ expect(access.message).to eq '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.'
+ expect(access.allowed?).to be_falsey
+ expect(access.message).to eq 'Pushing over HTTP is not allowed.'
end
end
end
@@ -328,27 +328,27 @@ describe GitlabNet, vcr: true 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
+ expect(access.allowed?).to be_falsey
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
+ expect(access.allowed?).to be_falsey
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
+ expect(access.allowed?).to be_falsey
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')
}.to raise_error(GitlabNet::ApiUnreachableError)
@@ -361,7 +361,7 @@ describe GitlabNet, vcr: true do
subject { net.send :base_api_endpoint }
it { is_expected.to include(net.send(:config).gitlab_url) }
- it("uses API version 4") { should end_with("api/v4") }
+ it("uses API version 4") { is_expected.to end_with("api/v4") }
end
describe '#internal_api_endpoint' do
@@ -370,15 +370,15 @@ describe GitlabNet, vcr: true do
subject { net.send :internal_api_endpoint }
it { is_expected.to include(net.send(:config).gitlab_url) }
- it("uses API version 4") { should end_with("api/v4/internal") }
+ it("uses API version 4") { is_expected.to end_with("api/v4/internal") }
end
describe '#http_client_for' 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) { {'self_signed_cert' => true} }
end
its(:verify_mode) { should eq(OpenSSL::SSL::VERIFY_NONE) }
@@ -398,42 +398,42 @@ 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') { user }
+ allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password') { 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 }
+ it { is_expected.not_to be_nil }
end
context 'with params' 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') { user }
+ allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password') { 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 }
+ it { is_expected.not_to be_nil }
end
context 'with headers' 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') { user }
+ allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password') { 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 }
+ it { is_expected.not_to be_nil }
end
context 'with options' do
@@ -441,15 +441,15 @@ 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') { user }
+ allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('password') { 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).not_to receive(:set_form_data)
end
- it { should_not be_nil }
+ it { is_expected.not_to be_nil }
end
end
end
@@ -457,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
- 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 +469,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) { 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 +482,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') { 'test_file' }
+ allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_path') { nil }
+ expect(store).to receive(:add_file).with('test_file')
+ expect(store).not_to 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') { nil }
+ allow(gitlab_net.send(:config).http_settings).to receive(:[]).with('ca_path') { 'test_path' }
+ expect(store).not_to receive(:add_file)
+ expect(store).to receive(:add_path).with('test_path')
end
end
end