Commit 1f2bef76 authored by Pablo Carranza's avatar Pablo Carranza

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.
parent f63e1bfc
......@@ -56,6 +56,11 @@ class GitlabNet
get("#{host}/check", read_timeout: CHECK_TIMEOUT)
end
def ssh_key(fingerprint)
resp = get("#{host}/ssh-key?fingerprint=#{fingerprint}")
JSON.parse(resp.body) rescue nil
end
protected
def config
......
......@@ -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
......
---
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
---
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
---
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
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