diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 00:09:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 00:09:19 +0300 |
commit | fca89bb73ff5b1d14c98c72481f9268fee107ea0 (patch) | |
tree | e1c8a2c4fe5df7f054fd09e49f53bcfb51e51c84 /spec/requests | |
parent | 76e9fc7b29c1ce716c26932e9fbec0f3c99f53f4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/deploy_tokens_spec.rb | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/spec/requests/api/deploy_tokens_spec.rb b/spec/requests/api/deploy_tokens_spec.rb index 01810e333c1..fa46b8017cb 100644 --- a/spec/requests/api/deploy_tokens_spec.rb +++ b/spec/requests/api/deploy_tokens_spec.rb @@ -195,56 +195,71 @@ describe API::DeployTokens do end end - describe 'POST /projects/:id/deploy_tokens' do - let(:params) do - { - name: 'Foo', - expires_at: 1.year.from_now, - scopes: [ - 'read_repository' - ], - username: 'Bar' - } - end + context 'deploy token creation' do + shared_examples 'creating a deploy token' do |entity, unauthenticated_response| + let(:params) do + { + name: 'Foo', + expires_at: 1.year.from_now, + scopes: [ + 'read_repository' + ], + username: 'Bar' + } + end - subject do - post api("/projects/#{project.id}/deploy_tokens", user), params: params - response - end + context 'when unauthenticated' do + let(:user) { nil } - context 'when unauthenticated' do - let(:user) { nil } + it { is_expected.to have_gitlab_http_status(unauthenticated_response) } + end - it { is_expected.to have_gitlab_http_status(:not_found) } - end + context 'when authenticated as non-admin user' do + before do + send(entity).add_developer(user) + end - context 'when authenticated as non-admin user' do - before do - project.add_developer(user) + it { is_expected.to have_gitlab_http_status(:forbidden) } end - it { is_expected.to have_gitlab_http_status(:forbidden) } - end + context 'when authenticated as maintainer' do + before do + send(entity).add_maintainer(user) + end - context 'when authenticated as maintainer' do - before do - project.add_maintainer(user) - end + it 'creates the deploy token' do + expect { subject }.to change { DeployToken.count }.by(1) - it 'creates the deploy token' do - expect { subject }.to change { DeployToken.count }.by(1) + expect(response).to have_gitlab_http_status(:created) + expect(response).to match_response_schema('public_api/v4/deploy_token') + end - expect(response).to have_gitlab_http_status(:created) - expect(response).to match_response_schema('public_api/v4/deploy_token') - end + context 'with an invalid scope' do + before do + params[:scopes] = %w[read_repository all_access] + end - context 'with an invalid scope' do - before do - params[:scopes] = %w[read_repository all_access] + it { is_expected.to have_gitlab_http_status(:bad_request) } end + end + end + + describe 'POST /projects/:id/deploy_tokens' do + subject do + post api("/projects/#{project.id}/deploy_tokens", user), params: params + response + end + + it_behaves_like 'creating a deploy token', :project, :not_found + end - it { is_expected.to have_gitlab_http_status(:bad_request) } + describe 'POST /groups/:id/deploy_tokens' do + subject do + post api("/groups/#{group.id}/deploy_tokens", user), params: params + response end + + it_behaves_like 'creating a deploy token', :group, :forbidden end end end |