2015-08-29 05:52:21 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::Keys do
|
2015-08-29 05:52:21 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:key) { create(:key, user: user) }
|
2017-06-14 14:18:56 -04:00
|
|
|
let(:email) { create(:email, user: user) }
|
2015-08-29 05:52:21 -04:00
|
|
|
|
|
|
|
describe 'GET /keys/:uid' do
|
|
|
|
context 'when unauthenticated' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns authentication error' do
|
2015-08-29 05:52:21 -04:00
|
|
|
get api("/keys/#{key.id}")
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2015-08-29 05:52:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 404 for non-existing key' do
|
2019-02-26 18:18:40 -05:00
|
|
|
get api('/keys/0', admin)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2015-08-29 05:52:21 -04:00
|
|
|
expect(json_response['message']).to eq('404 Not found')
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns single ssh key with user information' do
|
2015-08-29 05:52:21 -04:00
|
|
|
user.keys << key
|
|
|
|
user.save
|
|
|
|
get api("/keys/#{key.id}", admin)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-08-29 05:52:21 -04:00
|
|
|
expect(json_response['title']).to eq(key.title)
|
|
|
|
expect(json_response['user']['id']).to eq(user.id)
|
|
|
|
expect(json_response['user']['username']).to eq(user.username)
|
|
|
|
end
|
2017-04-21 05:47:58 -04:00
|
|
|
|
|
|
|
it "does not include the user's `is_admin` flag" do
|
|
|
|
get api("/keys/#{key.id}", admin)
|
|
|
|
|
|
|
|
expect(json_response['user']['is_admin']).to be_nil
|
|
|
|
end
|
2015-08-29 05:52:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|