summaryrefslogtreecommitdiff
path: root/spec/gitlab_net_spec.rb
diff options
context:
space:
mode:
authorGabor Nagy <mail@aigeruth.hu>2014-06-22 22:45:06 +0200
committerGabor Nagy <mail@aigeruth.hu>2014-06-23 20:52:45 +0200
commit32f1893298bc0108df89de0e543193af20bb0e7c (patch)
tree2fcff9cc992f4560be894f41938573ef3e6bb15e /spec/gitlab_net_spec.rb
parentca425566d0266a1786019153757e283d7d246450 (diff)
downloadgitlab-shell-32f1893298bc0108df89de0e543193af20bb0e7c.tar.gz
Improve coverage.
Diffstat (limited to 'spec/gitlab_net_spec.rb')
-rw-r--r--spec/gitlab_net_spec.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb
index 0ceec23..1b7ef4d 100644
--- a/spec/gitlab_net_spec.rb
+++ b/spec/gitlab_net_spec.rb
@@ -58,6 +58,81 @@ describe GitlabNet, vcr: true do
access.should be_false
end
end
+
+ it 'should deny push access for dev.gitlab.org (with user)' do
+ VCR.use_cassette("denied-push-with-user") do
+ access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'user-1', 'master')
+ access.should be_false
+ end
+ end
+ end
+ end
+
+ describe :host do
+ let(:net) { GitlabNet.new }
+ subject { net.send :host }
+
+ it { should include(net.send(:config).gitlab_url) }
+ it("uses API version 3") { should include("api/v3") }
+ 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).http_settings.stub(:[]).with('self_signed_cert') { true }
+ end
+
+ its(:verify_mode) { should eq(OpenSSL::SSL::VERIFY_NONE) }
+ end
+
+ describe :http_request_for do
+ let(:get) do
+ double(Net::HTTP::Get).tap do |get|
+ Net::HTTP::Get.stub(:new) { get }
+ end
+ end
+ let(:user) { 'user' }
+ let(:password) { 'password' }
+ let(:url) { URI 'http://localhost/' }
+ subject { gitlab_net.send :http_request_for, url }
+
+ before do
+ gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
+ gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
+ get.should_receive(:basic_auth).with(user, password).once
+ end
+
+ it { should_not be_nil }
+ end
+
+ describe :cert_store do
+ let(:store) do
+ double(OpenSSL::X509::Store).tap do |store|
+ OpenSSL::X509::Store.stub(:new) { store }
+ end
+ end
+
+ before :each do
+ store.should_receive(:set_default_paths).once
+ end
+
+ after do
+ gitlab_net.send :cert_store
+ 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)
+ 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')
end
end
end