summaryrefslogtreecommitdiff
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
parent238fd9b65f243fef552a1e7aa0bf2e3ba6e52b10 (diff)
downloadgitlab-shell-a94d899692f3869c55bd9db5588b337b8fabdaf2.tar.gz
test GitlabNet allowed method
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock8
-rw-r--r--lib/gitlab_net.rb1
-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
8 files changed, 191 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
index 6d28a71..c7516d0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,6 +3,8 @@ source "http://rubygems.org"
group :development do
gem 'coveralls', require: false
gem 'rspec'
+ gem 'webmock'
gem 'guard'
gem 'guard-rspec'
+ gem 'vcr'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index f5733c4..338ee07 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
+ addressable (2.3.2)
coderay (1.0.8)
colorize (0.5.8)
coveralls (0.6.2)
@@ -9,6 +10,7 @@ GEM
rest-client
simplecov (>= 0.7)
thor
+ crack (0.3.1)
diff-lcs (1.1.3)
guard (1.5.4)
listen (>= 0.4.2)
@@ -43,6 +45,10 @@ GEM
simplecov-html (0.7.1)
slop (3.3.3)
thor (0.16.0)
+ vcr (2.4.0)
+ webmock (1.9.0)
+ addressable (>= 2.2.7)
+ crack (>= 0.1.7)
PLATFORMS
ruby
@@ -52,3 +58,5 @@ DEPENDENCIES
guard
guard-rspec
rspec
+ vcr
+ webmock
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index cc2c5a6..635b7cb 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -35,6 +35,7 @@ class GitlabNet
end
def get(url)
+ puts url.inspect
url = URI.parse(url)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.port == 443)
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