diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-11 18:08:10 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-11 18:08:10 +0000 |
commit | 175b4fa261259ab0d033482d10bb4159fee8e538 (patch) | |
tree | e1f1dba5e41177f11ffded5a505e0e7f692b8df5 /spec/requests | |
parent | 4eea104c69e59f6fa53c7bc15b986c69f29b60c8 (diff) | |
download | gitlab-ce-175b4fa261259ab0d033482d10bb4159fee8e538.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/keys_spec.rb | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/spec/requests/api/keys_spec.rb b/spec/requests/api/keys_spec.rb index 6802a0cfdab..f7da1abcfdf 100644 --- a/spec/requests/api/keys_spec.rb +++ b/spec/requests/api/keys_spec.rb @@ -25,7 +25,6 @@ describe API::Keys do it 'returns single ssh key with user information' do user.keys << key - user.save get api("/keys/#{key.id}", admin) expect(response).to have_gitlab_http_status(200) expect(json_response['title']).to eq(key.title) @@ -40,4 +39,73 @@ describe API::Keys do end end end + + describe 'GET /keys?fingerprint=' do + it 'returns authentication error' do + get api("/keys?fingerprint=#{key.fingerprint}") + + expect(response).to have_gitlab_http_status(401) + end + + it 'returns authentication error when authenticated as user' do + get api("/keys?fingerprint=#{key.fingerprint}", user) + + expect(response).to have_gitlab_http_status(403) + end + + context 'when authenticated as admin' do + it 'returns 404 for non-existing SSH md5 fingerprint' do + get api("/keys?fingerprint=11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11", admin) + + expect(response).to have_gitlab_http_status(404) + expect(json_response['message']).to eq('404 Key Not Found') + end + + it 'returns 404 for non-existing SSH sha256 fingerprint' do + get api("/keys?fingerprint=#{URI.encode_www_form_component("SHA256:nUhzNyftwADy8AH3wFY31tAKs7HufskYTte2aXo1lCg")}", admin) + + expect(response).to have_gitlab_http_status(404) + expect(json_response['message']).to eq('404 Key Not Found') + end + + it 'returns user if SSH md5 fingerprint found' do + user.keys << key + + get api("/keys?fingerprint=#{key.fingerprint}", admin) + + expect(response).to have_gitlab_http_status(200) + 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 + + it 'returns user if SSH sha256 fingerprint found' do + user.keys << key + + get api("/keys?fingerprint=#{URI.encode_www_form_component("SHA256:" + key.fingerprint_sha256)}", admin) + + expect(response).to have_gitlab_http_status(200) + 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 + + it 'returns user if SSH sha256 fingerprint found' do + user.keys << key + + get api("/keys?fingerprint=#{URI.encode_www_form_component("sha256:" + key.fingerprint_sha256)}", admin) + + expect(response).to have_gitlab_http_status(200) + 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 + + it "does not include the user's `is_admin` flag" do + get api("/keys?fingerprint=#{key.fingerprint}", admin) + + expect(json_response['user']['is_admin']).to be_nil + end + end + end end |