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

Add internal api to get ssh key by fingerprint

parent 326c79f4
......@@ -52,6 +52,15 @@ module API
access.check(params[:action], params[:changes])
end
#
# Get a ssh key using the fingerprint
#
get "/ssh-key" do
key = Key.find_by(fingerprint: params[:fingerprint])
not_found!("Key") if key.nil?
present key, with: Entities::SSHKey
end
#
# Discover user by ssh key
#
......
......@@ -48,6 +48,33 @@ describe API::API, api: true do
end
end
describe "GET /internal/ssh-key" do
context "existing key" do
it "finds the key" do
get(api('/internal/ssh-key'), fingerprint: key.fingerprint, secret_token: secret_token)
expect(response.status).to eq(200)
expect(json_response["key"]).to eq(key.key)
end
end
context "non existing key" do
it "returns 404" do
get(api('/internal/ssh-key'), fingerprint: "not-valid", secret_token: secret_token)
expect(response.status).to eq(404)
end
end
context "partial key match" do
it "returns 404" do
get(api('/internal/ssh-key'), fingerprint: "#{key.fingerprint[0..5]}%", secret_token: secret_token)
expect(response.status).to eq(404)
end
end
end
describe "POST /internal/allowed" do
context "access granted" do
before do
......
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