diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 03:08:57 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 03:08:57 +0000 |
commit | 852f4a85dd199751e4652748461163de85ecda53 (patch) | |
tree | b4160aa19c23582b5ab5ac02f9860b5498007c43 /spec/requests/api/deploy_tokens_spec.rb | |
parent | 82cd20acf9f4cceecf222abe718a9e23cef55687 (diff) | |
download | gitlab-ce-852f4a85dd199751e4652748461163de85ecda53.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.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/requests/api/deploy_tokens_spec.rb b/spec/requests/api/deploy_tokens_spec.rb new file mode 100644 index 00000000000..0e3256edcd8 --- /dev/null +++ b/spec/requests/api/deploy_tokens_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::DeployTokens do + let(:creator) { create(:user) } + let(:project) { create(:project, creator_id: creator.id) } + let!(:deploy_token) { create(:deploy_token, projects: [project]) } + + describe 'GET /deploy_tokens' do + subject { get api('/deploy_tokens', user) } + + context 'when unauthenticated' do + let(:user) { nil } + + it 'rejects the response as unauthorized' do + subject + + expect(response).to have_gitlab_http_status(:unauthorized) + end + end + + context 'when authenticated as non-admin user' do + let(:user) { creator } + + it 'rejects the response as forbidden' do + subject + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'when authenticated as admin' do + let(:user) { create(:admin) } + + it 'returns all deploy tokens' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(deploy_token.id) + end + end + end +end |