summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPablo Carranza <pcarranza@gmail.com>2016-03-07 12:43:19 +0000
committerPablo Carranza <pcarranza@gmail.com>2016-03-24 20:48:27 +0000
commit1f2bef765d8aa03b76f991178cfa7513833b4c3b (patch)
tree4f8653ace8b2290687d3b02dec9910923a1f6f3f /spec
parentf63e1bfcf508d9ed3c0e60399960f1c1cf21d899 (diff)
downloadgitlab-shell-1f2bef765d8aa03b76f991178cfa7513833b4c3b.tar.gz
Add ssh-key resource get to gitlab_net
This provides the integration point to the internal API to get the ssh key from the internal API.
Diffstat (limited to 'spec')
-rw-r--r--spec/gitlab_net_spec.rb28
-rw-r--r--spec/vcr_cassettes/ssh-key-not-found.yml50
-rw-r--r--spec/vcr_cassettes/ssh-key-not-implemented.yml50
-rw-r--r--spec/vcr_cassettes/ssh-key-ok.yml40
4 files changed, 168 insertions, 0 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb
index 9a166b5..964e398 100644
--- a/spec/gitlab_net_spec.rb
+++ b/spec/gitlab_net_spec.rb
@@ -76,6 +76,34 @@ describe GitlabNet, vcr: true do
end
end
+ describe :ssh_key do
+ it "should return nil when the resource is not implemented" do
+ VCR.use_cassette("ssh-key-not-implemented") do
+ result = gitlab_net.ssh_key("whatever")
+ result.should be_nil
+ end
+ end
+
+ it "should return nil when the fingerprint is not found" do
+ VCR.use_cassette("ssh-key-not-found") do
+ result = gitlab_net.ssh_key("whatever")
+ result.should be_nil
+ end
+ end
+
+ it "should return a ssh key with a valid fingerprint" do
+ VCR.use_cassette("ssh-key-ok") do
+ result = gitlab_net.ssh_key("42:18:16")
+ result.should eq({
+ "created_at" => "2016-03-04T18:27:36.959Z",
+ "id" => 2,
+ "key" => "ssh-rsa a-made=up-rsa-key dummy@gitlab.com",
+ "title" => "some key title"
+ })
+ end
+ end
+ end
+
describe :check_access do
context 'ssh key with access to project' do
it 'should allow pull access for dev.gitlab.org' do
diff --git a/spec/vcr_cassettes/ssh-key-not-found.yml b/spec/vcr_cassettes/ssh-key-not-found.yml
new file mode 100644
index 0000000..68c646e
--- /dev/null
+++ b/spec/vcr_cassettes/ssh-key-not-found.yml
@@ -0,0 +1,50 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/ssh-key?fingerprint=whatever
+ body:
+ encoding: US-ASCII
+ string: secret_token=a123
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - Ruby
+ Content-Type:
+ - application/x-www-form-urlencoded
+ response:
+ status:
+ code: 404
+ message: Not Found
+ headers:
+ Server:
+ - nginx
+ Date:
+ - Mon, 07 Mar 2016 12:09:59 GMT
+ Content-Type:
+ - text/html; charset=utf-8
+ Connection:
+ - keep-alive
+ Cache-Control:
+ - no-cache
+ Set-Cookie:
+ - _gitlab_session=a924e63729e538c9efe10fa8338077d7; path=/; expires=Mon, 14
+ Mar 2016 12:09:59 -0000; secure; HttpOnly
+ Status:
+ - 404 Not Found
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Request-Id:
+ - 275ad011-515f-4239-80be-e537fd7c9086
+ X-Runtime:
+ - '2.169401'
+ X-Xss-Protection:
+ - 1; mode=block
+ http_version:
+ recorded_at: Mon, 07 Mar 2016 12:10:00 GMT
+recorded_with: VCR 2.4.0
diff --git a/spec/vcr_cassettes/ssh-key-not-implemented.yml b/spec/vcr_cassettes/ssh-key-not-implemented.yml
new file mode 100644
index 0000000..1d4aae0
--- /dev/null
+++ b/spec/vcr_cassettes/ssh-key-not-implemented.yml
@@ -0,0 +1,50 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/ssh-key?fingerprint=whatever
+ body:
+ encoding: US-ASCII
+ string: secret_token=a123
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - Ruby
+ Content-Type:
+ - application/x-www-form-urlencoded
+ response:
+ status:
+ code: 501
+ message: Not Implemented
+ headers:
+ Server:
+ - nginx
+ Date:
+ - Mon, 07 Mar 2016 12:09:59 GMT
+ Content-Type:
+ - text/html; charset=utf-8
+ Connection:
+ - keep-alive
+ Cache-Control:
+ - no-cache
+ Set-Cookie:
+ - _gitlab_session=a924e63729e538c9efe10fa8338077d7; path=/; expires=Mon, 14
+ Mar 2016 12:09:59 -0000; secure; HttpOnly
+ Status:
+ - 501 Not Implemented
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Request-Id:
+ - 275ad011-515f-4239-80be-e537fd7c9086
+ X-Runtime:
+ - '2.169401'
+ X-Xss-Protection:
+ - 1; mode=block
+ http_version:
+ recorded_at: Mon, 07 Mar 2016 12:10:00 GMT
+recorded_with: VCR 2.4.0
diff --git a/spec/vcr_cassettes/ssh-key-ok.yml b/spec/vcr_cassettes/ssh-key-ok.yml
new file mode 100644
index 0000000..3a68709
--- /dev/null
+++ b/spec/vcr_cassettes/ssh-key-ok.yml
@@ -0,0 +1,40 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://dev.gitlab.org/api/v3/internal/ssh-key?fingerprint=42:18:16
+ body:
+ encoding: US-ASCII
+ string: secret_token=a123
+ headers:
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ User-Agent:
+ - Ruby
+ Content-Type:
+ - application/x-www-form-urlencoded
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Server:
+ - nginx/1.1.19
+ Date:
+ - Wed, 03 Sep 2014 11:27:35 GMT
+ Content-Type:
+ - application/json
+ Connection:
+ - keep-alive
+ Status:
+ - 200 OK
+ Cache-Control:
+ - max-age=0, private, must-revalidate
+ body:
+ encoding: UTF-8
+ string: '{"id":2, "title":"some key title", "key":"ssh-rsa a-made=up-rsa-key dummy@gitlab.com", "created_at":"2016-03-04T18:27:36.959Z"}'
+ http_version:
+ recorded_at: Mon, 07 Mar 2016 12:10:00 GMT
+recorded_with: VCR 2.4.0