diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2016-06-01 22:25:22 -0400 |
---|---|---|
committer | Alejandro RodrÃguez <alejorro70@gmail.com> | 2016-07-20 13:39:19 -0400 |
commit | 818ad89ea5f9ac3cf05506e7b81fd0c2fca5d9dc (patch) | |
tree | d76bcb35392778861ef253e8af002baa468cd3af /spec | |
parent | b4717017e7ad601eaa1d53c9238a242c7fdf0daa (diff) | |
download | gitlab-ce-818ad89ea5f9ac3cf05506e7b81fd0c2fca5d9dc.tar.gz |
Add /deploy_keys API to retrieve all deploy keys regardless of project affiliation
Also, in favour of consistency, deprecate `/projects/:id/keys/...` routes in favour of
`/projects/:id/deploy_keys/...`
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/deploy_keys.rb | 38 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 24 |
2 files changed, 50 insertions, 12 deletions
diff --git a/spec/requests/api/deploy_keys.rb b/spec/requests/api/deploy_keys.rb new file mode 100644 index 00000000000..ac42288bc34 --- /dev/null +++ b/spec/requests/api/deploy_keys.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe API::API, api: true do + include ApiHelpers + + let(:user) { create(:user) } + let(:project) { create(:project, creator_id: user.id) } + let!(:deploy_keys_project) { create(:deploy_keys_project, project: project) } + let(:admin) { create(:admin) } + + describe 'GET /deploy_keys' do + before { admin } + + context 'when unauthenticated' do + it 'should return authentication error' do + get api('/deploy_keys') + expect(response.status).to eq(401) + end + end + + context 'when authenticated as non-admin user' do + it 'should return a 403 error' do + get api('/deploy_keys', user) + expect(response.status).to eq(403) + end + end + + context 'when authenticated as admin' do + it 'should return all deploy keys' do + get api('/deploy_keys', admin) + expect(response.status).to eq(200) + + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(deploy_keys_project.deploy_key.id) + end + end + end +end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 152cd802839..afa0599807f 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -647,33 +647,33 @@ describe API::API, api: true do let(:deploy_keys_project) { create(:deploy_keys_project, project: project) } let(:deploy_key) { deploy_keys_project.deploy_key } - describe 'GET /projects/:id/keys' do + describe 'GET /projects/:id/deploy_keys' do before { deploy_key } it 'should return array of ssh keys' do - get api("/projects/#{project.id}/keys", user) + get api("/projects/#{project.id}/deploy_keys", user) expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['title']).to eq(deploy_key.title) end end - describe 'GET /projects/:id/keys/:key_id' do + describe 'GET /projects/:id/deploy_keys/:key_id' do it 'should return a single key' do - get api("/projects/#{project.id}/keys/#{deploy_key.id}", user) + get api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", user) expect(response).to have_http_status(200) expect(json_response['title']).to eq(deploy_key.title) end it 'should return 404 Not Found with invalid ID' do - get api("/projects/#{project.id}/keys/404", user) + get api("/projects/#{project.id}/deploy_keys/404", user) expect(response).to have_http_status(404) end end - describe 'POST /projects/:id/keys' do + describe 'POST /projects/:id/deploy_keys' do it 'should not create an invalid ssh key' do - post api("/projects/#{project.id}/keys", user), { title: 'invalid key' } + post api("/projects/#{project.id}/deploy_keys", user), { title: 'invalid key' } expect(response).to have_http_status(400) expect(json_response['message']['key']).to eq([ 'can\'t be blank', @@ -683,7 +683,7 @@ describe API::API, api: true do end it 'should not create a key without title' do - post api("/projects/#{project.id}/keys", user), key: 'some key' + post api("/projects/#{project.id}/deploy_keys", user), key: 'some key' expect(response).to have_http_status(400) expect(json_response['message']['title']).to eq([ 'can\'t be blank', @@ -694,22 +694,22 @@ describe API::API, api: true do it 'should create new ssh key' do key_attrs = attributes_for :key expect do - post api("/projects/#{project.id}/keys", user), key_attrs + post api("/projects/#{project.id}/deploy_keys", user), key_attrs end.to change{ project.deploy_keys.count }.by(1) end end - describe 'DELETE /projects/:id/keys/:key_id' do + describe 'DELETE /projects/:id/deploy_keys/:key_id' do before { deploy_key } it 'should delete existing key' do expect do - delete api("/projects/#{project.id}/keys/#{deploy_key.id}", user) + delete api("/projects/#{project.id}/deploy_keys/#{deploy_key.id}", user) end.to change{ project.deploy_keys.count }.by(-1) end it 'should return 404 Not Found with invalid ID' do - delete api("/projects/#{project.id}/keys/404", user) + delete api("/projects/#{project.id}/deploy_keys/404", user) expect(response).to have_http_status(404) end end |