summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-11 14:19:38 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-11 14:19:38 +0200
commita94d899692f3869c55bd9db5588b337b8fabdaf2 (patch)
tree03d215660dd90e247f4cb800712a52610e57dc78 /spec
parent238fd9b65f243fef552a1e7aa0bf2e3ba6e52b10 (diff)
downloadgitlab-shell-a94d899692f3869c55bd9db5588b337b8fabdaf2.tar.gz
test GitlabNet allowed method
Diffstat (limited to 'spec')
-rw-r--r--spec/gitlab_net_spec.rb27
-rw-r--r--spec/spec_helper.rb9
-rw-r--r--spec/vcr_cassettes/allowed-pull.yml48
-rw-r--r--spec/vcr_cassettes/allowed-push.yml48
-rw-r--r--spec/vcr_cassettes/dev_gitlab_org.yml48
5 files changed, 180 insertions, 0 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb
new file mode 100644
index 0000000..5bda95e
--- /dev/null
+++ b/spec/gitlab_net_spec.rb
@@ -0,0 +1,27 @@
+require_relative 'spec_helper'
+require_relative '../lib/gitlab_net'
+
+
+describe GitlabNet do
+ describe :allowed? do
+ let(:gitlab_net) { GitlabNet.new }
+
+ before do
+ gitlab_net.stub!(:host).and_return('https://dev.gitlab.org/api/v3/internal')
+ end
+
+ it 'should allow pull access for dev.gitlab.org', vcr: true do
+ VCR.use_cassette("allowed-pull") do
+ access = gitlab_net.allowed?('git-receive-pack', 'gitlab/gitlabhq.git', 'key-1', 'master')
+ access.should be_true
+ end
+ end
+
+ it 'should allow push access for dev.gitlab.org', vcr: true do
+ VCR.use_cassette("allowed-push") do
+ access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-1', 'master')
+ access.should be_true
+ end
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index ccf1b63..ea3872d 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -4,3 +4,12 @@ if ENV['TRAVIS']
require 'coveralls'
Coveralls.wear!
end
+
+require 'vcr'
+require 'webmock'
+
+VCR.configure do |c|
+ c.cassette_library_dir = 'spec/vcr_cassettes'
+ c.hook_into :webmock
+ c.configure_rspec_metadata!
+end
diff --git a/spec/vcr_cassettes/allowed-pull.yml b/spec/vcr_cassettes/allowed-pull.yml
new file mode 100644
index 0000000..db2ef29
--- /dev/null
+++ b/spec/vcr_cassettes/allowed-pull.yml
@@ -0,0 +1,48 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/allowed?action=git-receive-pack&key_id=1&project=gitlab/gitlabhq&ref=master
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Accept:
+ - ! '*/*'
+ User-Agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Server:
+ - nginx/1.1.19
+ Date:
+ - Mon, 11 Mar 2013 12:13:31 GMT
+ Content-Type:
+ - application/json
+ Content-Length:
+ - '4'
+ Connection:
+ - keep-alive
+ Status:
+ - 200 OK
+ X-Ua-Compatible:
+ - IE=Edge,chrome=1
+ Etag:
+ - ! '"b326b5062b2f0e69046810717534cb09"'
+ Cache-Control:
+ - max-age=0, private, must-revalidate
+ X-Request-Id:
+ - ac00b27743e177559476f6575e45d1c2
+ X-Runtime:
+ - '0.017272'
+ X-Rack-Cache:
+ - miss
+ body:
+ encoding: US-ASCII
+ string: 'true'
+ http_version:
+ recorded_at: Mon, 11 Mar 2013 12:13:31 GMT
+recorded_with: VCR 2.4.0
diff --git a/spec/vcr_cassettes/allowed-push.yml b/spec/vcr_cassettes/allowed-push.yml
new file mode 100644
index 0000000..96b8c9a
--- /dev/null
+++ b/spec/vcr_cassettes/allowed-push.yml
@@ -0,0 +1,48 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/allowed?action=git-upload-pack&key_id=1&project=gitlab/gitlabhq&ref=master
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Accept:
+ - ! '*/*'
+ User-Agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Server:
+ - nginx/1.1.19
+ Date:
+ - Mon, 11 Mar 2013 12:13:32 GMT
+ Content-Type:
+ - application/json
+ Content-Length:
+ - '4'
+ Connection:
+ - keep-alive
+ Status:
+ - 200 OK
+ X-Ua-Compatible:
+ - IE=Edge,chrome=1
+ Etag:
+ - ! '"b326b5062b2f0e69046810717534cb09"'
+ Cache-Control:
+ - max-age=0, private, must-revalidate
+ X-Request-Id:
+ - c65f8ea13ac34cf182fcb6daefeb1bdd
+ X-Runtime:
+ - '0.018934'
+ X-Rack-Cache:
+ - miss
+ body:
+ encoding: US-ASCII
+ string: 'true'
+ http_version:
+ recorded_at: Mon, 11 Mar 2013 12:13:31 GMT
+recorded_with: VCR 2.4.0
diff --git a/spec/vcr_cassettes/dev_gitlab_org.yml b/spec/vcr_cassettes/dev_gitlab_org.yml
new file mode 100644
index 0000000..02410e0
--- /dev/null
+++ b/spec/vcr_cassettes/dev_gitlab_org.yml
@@ -0,0 +1,48 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/allowed?action=git-receive-pack&key_id=100&project=gitlab/gitlabhq&ref=master
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Accept:
+ - ! '*/*'
+ User-Agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Server:
+ - nginx/1.1.19
+ Date:
+ - Mon, 11 Mar 2013 12:13:05 GMT
+ Content-Type:
+ - application/json
+ Content-Length:
+ - '4'
+ Connection:
+ - keep-alive
+ Status:
+ - 200 OK
+ X-Ua-Compatible:
+ - IE=Edge,chrome=1
+ Etag:
+ - ! '"b326b5062b2f0e69046810717534cb09"'
+ Cache-Control:
+ - max-age=0, private, must-revalidate
+ X-Request-Id:
+ - aabf04bba02ad88d256633dc34097095
+ X-Runtime:
+ - '0.017099'
+ X-Rack-Cache:
+ - miss
+ body:
+ encoding: US-ASCII
+ string: 'true'
+ http_version:
+ recorded_at: Mon, 11 Mar 2013 12:13:05 GMT
+recorded_with: VCR 2.4.0