diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-09 00:08:14 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-09 00:08:14 +0000 |
commit | ed4df05ce917d6cf175aeb508b0485ae5f281a0a (patch) | |
tree | 9313abd8fd41a78eb2bf1ffd0f95f10b69cd25cb /spec | |
parent | 1bdb3fe3821fc3d222361d8b2e2ec2fea2915372 (diff) | |
download | gitlab-ce-ed4df05ce917d6cf175aeb508b0485ae5f281a0a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/deploy_tokens_spec.rb | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/spec/requests/api/deploy_tokens_spec.rb b/spec/requests/api/deploy_tokens_spec.rb index 9aa181db7fc..14153fae42f 100644 --- a/spec/requests/api/deploy_tokens_spec.rb +++ b/spec/requests/api/deploy_tokens_spec.rb @@ -3,10 +3,12 @@ require 'spec_helper' describe API::DeployTokens do - let(:user) { create(:user) } - let(:creator) { create(:user) } - let(:project) { create(:project, creator_id: creator.id) } + let_it_be(:user) { create(:user) } + let_it_be(:creator) { create(:user) } + let_it_be(:project) { create(:project, creator_id: creator.id) } + let_it_be(:group) { create(:group) } let!(:deploy_token) { create(:deploy_token, projects: [project]) } + let!(:group_deploy_token) { create(:deploy_token, :group, groups: [group]) } describe 'GET /deploy_tokens' do subject do @@ -84,4 +86,51 @@ describe API::DeployTokens do end end end + + describe 'DELETE /groups/:id/deploy_tokens/:token_id' do + subject do + delete api("/groups/#{group.id}/deploy_tokens/#{group_deploy_token.id}", user) + response + end + + context 'when unauthenticated' do + let(:user) { nil } + + it { is_expected.to have_gitlab_http_status(:forbidden) } + end + + context 'when authenticated as non-admin user' do + before do + group.add_developer(user) + end + + it { is_expected.to have_gitlab_http_status(:forbidden) } + end + + context 'when authenticated as maintainer' do + before do + group.add_maintainer(user) + end + + it 'deletes the deploy token' do + expect { subject }.to change { group.deploy_tokens.count }.by(-1) + + expect(group.deploy_tokens).to be_empty + end + + context 'invalid request' do + it 'returns bad request with invalid group id' do + delete api("/groups/bad_id/deploy_tokens/#{group_deploy_token.id}", user) + + expect(response).to have_gitlab_http_status(:bad_request) + end + + it 'returns not found with invalid deploy token id' do + delete api("/groups/#{group.id}/deploy_tokens/bad_id", user) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + end end |