Commit a94d8996 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

test GitlabNet allowed method

parent 238fd9b6
......@@ -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
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
......@@ -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)
......
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
......@@ -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
---
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
---
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
---
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment