From 65a1175e466105fca1f40cb5a995fdb100ff334e Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 11 Mar 2020 06:10:11 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/frontend/__mocks__/monaco-editor/index.js | 13 ++++++ spec/requests/api/deploy_tokens_spec.rb | 65 +++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 spec/frontend/__mocks__/monaco-editor/index.js (limited to 'spec') diff --git a/spec/frontend/__mocks__/monaco-editor/index.js b/spec/frontend/__mocks__/monaco-editor/index.js new file mode 100644 index 00000000000..18cc3a7c377 --- /dev/null +++ b/spec/frontend/__mocks__/monaco-editor/index.js @@ -0,0 +1,13 @@ +// NOTE: +// These imports are pulled from 'monaco-editor/esm/vs/editor/editor.main.js' +// We don't want to include 'monaco-editor/esm/vs/editor/edcore' because it causes +// lots of compatability issues with Jest +// Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/209863 +import 'monaco-editor/esm/vs/language/typescript/monaco.contribution'; +import 'monaco-editor/esm/vs/language/css/monaco.contribution'; +import 'monaco-editor/esm/vs/language/json/monaco.contribution'; +import 'monaco-editor/esm/vs/language/html/monaco.contribution'; +import 'monaco-editor/esm/vs/basic-languages/monaco.contribution'; + +export * from 'monaco-editor/esm/vs/editor/editor.api'; +export default global.monaco; 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 -- cgit v1.2.3