diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-11 14:27:16 +0200 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-11 14:27:16 +0200 |
| commit | c3f71412c1795f8472f06d5c9ecb2609e604c0a6 (patch) | |
| tree | ec7e07ba28323e835cc3f77cde43b6662210ee95 | |
| parent | b8ccc7a6b0160dc2e9a50c8949e384f7aea13823 (diff) | |
| download | gitlab-shell-c3f71412c1795f8472f06d5c9ecb2609e604c0a6.tar.gz | |
test for GitlabNet discover
| -rw-r--r-- | spec/gitlab_net_spec.rb | 27 | ||||
| -rw-r--r-- | spec/vcr_cassettes/discover-ok.yml | 49 |
2 files changed, 67 insertions, 9 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb index c2e194f..7d2d7d9 100644 --- a/spec/gitlab_net_spec.rb +++ b/spec/gitlab_net_spec.rb @@ -2,23 +2,32 @@ require_relative 'spec_helper' require_relative '../lib/gitlab_net' -describe GitlabNet do - describe :allowed? do - let(:gitlab_net) { GitlabNet.new } +describe GitlabNet, vcr: true do + let(:gitlab_net) { GitlabNet.new } + + before do + gitlab_net.stub!(:host).and_return('https://dev.gitlab.org/api/v3/internal') + end - before do - gitlab_net.stub!(:host).and_return('https://dev.gitlab.org/api/v3/internal') + describe :discover do + 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 + describe :allowed? 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 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 + it 'should allow push access for dev.gitlab.org' do VCR.use_cassette("allowed-push") do access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-1', 'master') access.should be_true @@ -27,14 +36,14 @@ describe GitlabNet do end 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 access = gitlab_net.allowed?('git-receive-pack', 'gitlab/gitlabhq.git', 'key-2', 'master') access.should be_false 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 access = gitlab_net.allowed?('git-upload-pack', 'gitlab/gitlabhq.git', 'key-2', 'master') access.should be_false diff --git a/spec/vcr_cassettes/discover-ok.yml b/spec/vcr_cassettes/discover-ok.yml new file mode 100644 index 0000000..f1b0cfd --- /dev/null +++ b/spec/vcr_cassettes/discover-ok.yml @@ -0,0 +1,49 @@ +--- +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 |
