diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/requests/api/project_templates_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/requests/api/project_templates_spec.rb')
-rw-r--r-- | spec/requests/api/project_templates_spec.rb | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/spec/requests/api/project_templates_spec.rb b/spec/requests/api/project_templates_spec.rb index 59b2b09f0bf..d242d49fc1b 100644 --- a/spec/requests/api/project_templates_spec.rb +++ b/spec/requests/api/project_templates_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' RSpec.describe API::ProjectTemplates do - let_it_be(:public_project) { create(:project, :public, path: 'path.with.dot') } - let_it_be(:private_project) { create(:project, :private) } + let_it_be(:public_project) { create(:project, :public, :repository, create_templates: :merge_request, path: 'path.with.dot') } + let_it_be(:private_project) { create(:project, :private, :repository, create_templates: :issue) } let_it_be(:developer) { create(:user) } let(:url_encoded_path) { "#{public_project.namespace.path}%2F#{public_project.path}" } @@ -62,6 +62,33 @@ RSpec.describe API::ProjectTemplates do expect(json_response).to satisfy_one { |template| template['key'] == 'mit' } end + it 'returns metrics_dashboard_ymls' do + get api("/projects/#{public_project.id}/templates/metrics_dashboard_ymls") + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(response).to match_response_schema('public_api/v4/template_list') + expect(json_response).to satisfy_one { |template| template['key'] == 'Default' } + end + + it 'returns issue templates' do + get api("/projects/#{private_project.id}/templates/issues", developer) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(response).to match_response_schema('public_api/v4/template_list') + expect(json_response.map {|t| t['key']}).to match_array(%w(bug feature_proposal template_test)) + end + + it 'returns merge request templates' do + get api("/projects/#{public_project.id}/templates/merge_requests") + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(response).to match_response_schema('public_api/v4/template_list') + expect(json_response.map {|t| t['key']}).to match_array(%w(bug feature_proposal template_test)) + end + it 'returns 400 for an unknown template type' do get api("/projects/#{public_project.id}/templates/unknown") @@ -136,6 +163,14 @@ RSpec.describe API::ProjectTemplates do expect(json_response['name']).to eq('Android') end + it 'returns a specific metrics_dashboard_yml' do + get api("/projects/#{public_project.id}/templates/metrics_dashboard_ymls/Default") + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/template') + expect(json_response['name']).to eq('Default') + end + it 'returns a specific license' do get api("/projects/#{public_project.id}/templates/licenses/mit") @@ -143,12 +178,42 @@ RSpec.describe API::ProjectTemplates do expect(response).to match_response_schema('public_api/v4/license') end + it 'returns a specific issue template' do + get api("/projects/#{private_project.id}/templates/issues/bug", developer) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/template') + expect(json_response['name']).to eq('bug') + expect(json_response['content']).to eq('something valid') + end + + it 'returns a specific merge request template' do + get api("/projects/#{public_project.id}/templates/merge_requests/feature_proposal") + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/template') + expect(json_response['name']).to eq('feature_proposal') + expect(json_response['content']).to eq('feature_proposal') # Content is identical to filename here + end + it 'returns 404 for an unknown specific template' do get api("/projects/#{public_project.id}/templates/licenses/unknown") expect(response).to have_gitlab_http_status(:not_found) end + it 'returns 404 for an unknown issue template' do + get api("/projects/#{public_project.id}/templates/issues/unknown") + + expect(response).to have_gitlab_http_status(:not_found) + end + + it 'returns 404 for an unknown merge request template' do + get api("/projects/#{public_project.id}/templates/merge_requests/unknown") + + expect(response).to have_gitlab_http_status(:not_found) + end + it 'denies access to an anonymous user on a private project' do get api("/projects/#{private_project.id}/templates/licenses/mit") @@ -166,6 +231,10 @@ RSpec.describe API::ProjectTemplates do subject { get api("/projects/#{url_encoded_path}/templates/gitlab_ci_ymls/Android") } end + it_behaves_like 'accepts project paths with dots' do + subject { get api("/projects/#{url_encoded_path}/templates/metrics_dashboard_ymls/Default") } + end + shared_examples 'path traversal attempt' do |template_type| it 'rejects invalid filenames' do get api("/projects/#{public_project.id}/templates/#{template_type}/%2e%2e%2fPython%2ea") |