summaryrefslogtreecommitdiff
path: root/spec/requests/api/deploy_tokens_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-11 06:10:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-11 06:10:11 +0000
commit65a1175e466105fca1f40cb5a995fdb100ff334e (patch)
tree562573b4fc7a0cd748d07d6a1720b4b13d36386a /spec/requests/api/deploy_tokens_spec.rb
parent3a52deac114dda8a1ee0da597c148b0dfc5dcf35 (diff)
downloadgitlab-ce-65a1175e466105fca1f40cb5a995fdb100ff334e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api/deploy_tokens_spec.rb')
-rw-r--r--spec/requests/api/deploy_tokens_spec.rb65
1 files changed, 63 insertions, 2 deletions
diff --git a/spec/requests/api/deploy_tokens_spec.rb b/spec/requests/api/deploy_tokens_spec.rb
index 8076b0958a4..01810e333c1 100644
--- a/spec/requests/api/deploy_tokens_spec.rb
+++ b/spec/requests/api/deploy_tokens_spec.rb
@@ -10,12 +10,24 @@ describe API::DeployTokens do
let!(:deploy_token) { create(:deploy_token, projects: [project]) }
let!(:group_deploy_token) { create(:deploy_token, :group, groups: [group]) }
+ shared_examples 'with feature flag disabled' do
+ context 'disabled feature flag' do
+ before do
+ stub_feature_flags(deploy_tokens_api: false)
+ end
+
+ it { is_expected.to have_gitlab_http_status(:service_unavailable) }
+ end
+ end
+
describe 'GET /deploy_tokens' do
subject do
get api('/deploy_tokens', user)
response
end
+ it_behaves_like 'with feature flag disabled'
+
context 'when unauthenticated' do
let(:user) { nil }
@@ -69,6 +81,8 @@ describe API::DeployTokens do
project.add_maintainer(user)
end
+ it_behaves_like 'with feature flag disabled'
+
it { is_expected.to have_gitlab_http_status(:ok) }
it 'returns all deploy tokens for the project' do
@@ -87,6 +101,53 @@ describe API::DeployTokens do
end
end
+ describe 'GET /groups/:id/deploy_tokens' do
+ subject do
+ get api("/groups/#{group.id}/deploy_tokens", 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
+ let!(:other_deploy_token) { create(:deploy_token, :group) }
+
+ before do
+ group.add_maintainer(user)
+ end
+
+ it_behaves_like 'with feature flag disabled'
+
+ it { is_expected.to have_gitlab_http_status(:ok) }
+
+ it 'returns all deploy tokens for the group' do
+ subject
+
+ expect(response).to include_pagination_headers
+ expect(response).to match_response_schema('public_api/v4/deploy_tokens')
+ end
+
+ it 'does not return deploy tokens for other groups' do
+ subject
+
+ token_ids = json_response.map { |token| token['id'] }
+ expect(token_ids).not_to include(other_deploy_token.id)
+ 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)
@@ -119,10 +180,10 @@ describe API::DeployTokens do
end
context 'invalid request' do
- it 'returns bad request with invalid group id' do
+ it 'returns not found 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)
+ expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns not found with invalid deploy token id' do