Commit c3f71412 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

test for GitlabNet discover

parent b8ccc7a6
...@@ -2,23 +2,32 @@ require_relative 'spec_helper' ...@@ -2,23 +2,32 @@ require_relative 'spec_helper'
require_relative '../lib/gitlab_net' require_relative '../lib/gitlab_net'
describe GitlabNet do describe GitlabNet, vcr: true do
describe :allowed? do let(:gitlab_net) { GitlabNet.new }
let(:gitlab_net) { GitlabNet.new }
before do
gitlab_net.stub!(:host).and_return('https://dev.gitlab.org/api/v3/internal')
end
before do describe :discover do
gitlab_net.stub!(:host).and_return('https://dev.gitlab.org/api/v3/internal') it 'should return user has based on key id' do
VCR.use_cassette("discover-ok") do
user = gitlab_net.discover('key-1')
user['name'].should == 'Dmitriy Zaporozhets'
end
end end
end
describe :allowed? do
context 'ssh key with access to project' do context 'ssh key with access to project' do
it 'should allow pull access for dev.gitlab.org', vcr: true do it 'should allow pull access for dev.gitlab.org' do
VCR.use_cassette("allowed-pull") do VCR.use_cassette("allowed-pull") do
access = gitlab_net.allowed?('git-receive-pack', 'gitlab/gitlabhq.git', 'key-1', 'master') access = gitlab_net.allowed?('git-receive-pack', 'gitlab/gitlabhq.git', 'key-1', 'master')
access.should be_true access.should be_true
end end
end end
it 'should allow push access for dev.gitlab.org', vcr: true do it 'should allow push access for dev.gitlab.org' do
VCR.use_cassette("allowed-push") do VCR.use_cassette("allowed-push") do
access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-1', 'master') access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-1', 'master')
access.should be_true access.should be_true
...@@ -27,14 +36,14 @@ describe GitlabNet do ...@@ -27,14 +36,14 @@ describe GitlabNet do
end end
context 'ssh key without access to project' do context 'ssh key without access to project' do
it 'should deny pull access for dev.gitlab.org', vcr: true do it 'should deny pull access for dev.gitlab.org' do
VCR.use_cassette("denied-pull") do VCR.use_cassette("denied-pull") do
access = gitlab_net.allowed?('git-receive-pack', 'gitlab/gitlabhq.git', 'key-2', 'master') access = gitlab_net.allowed?('git-receive-pack', 'gitlab/gitlabhq.git', 'key-2', 'master')
access.should be_false access.should be_false
end end
end end
it 'should deny push access for dev.gitlab.org', vcr: true do it 'should deny push access for dev.gitlab.org' do
VCR.use_cassette("denied-push") do VCR.use_cassette("denied-push") do
access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-2', 'master') access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-2', 'master')
access.should be_false access.should be_false
......
---
http_interactions:
- request:
method: get
uri: https://dev.gitlab.org/api/v3/internal/discover?key_id=1
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:25:45 GMT
Content-Type:
- application/json
Content-Length:
- '332'
Connection:
- keep-alive
Status:
- 200 OK
X-Ua-Compatible:
- IE=Edge,chrome=1
Etag:
- ! '"132e22d01addb4fe7fc1ee9f954b69e1"'
Cache-Control:
- max-age=0, private, must-revalidate
X-Request-Id:
- 47a6a45ce3073d1f7497d15290c109ef
X-Runtime:
- '0.007938'
X-Rack-Cache:
- miss
body:
encoding: US-ASCII
string: ! '{"id":1,"username":"dzaporozhets","email":"dmitriy.zaporozhets@gmail.com","name":"Dmitriy
Zaporozhets","bio":"ruby dev.","skype":"dmitriy-zaporozhets","linkedin":"dzaporozhets","twitter":"dzaporozhets","dark_scheme":true,"theme_id":2,"state":"active","created_at":"2011-09-19T09:11:36Z","extern_uid":"23944366","provider":"twitter"}'
http_version:
recorded_at: Mon, 11 Mar 2013 12:25:44 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