diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/support/shared_examples/requests/api/snippets_shared_examples.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/support/shared_examples/requests/api/snippets_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/requests/api/snippets_shared_examples.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/support/shared_examples/requests/api/snippets_shared_examples.rb b/spec/support/shared_examples/requests/api/snippets_shared_examples.rb new file mode 100644 index 00000000000..cfbb84dd099 --- /dev/null +++ b/spec/support/shared_examples/requests/api/snippets_shared_examples.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'raw snippet files' do + let_it_be(:unauthorized_user) { create(:user) } + let(:snippet_id) { snippet.id } + let(:user) { snippet.author } + let(:file_path) { '%2Egitattributes' } + let(:ref) { 'master' } + + context 'with no user' do + it 'requires authentication' do + get api(api_path) + + expect(response).to have_gitlab_http_status(:unauthorized) + end + end + + shared_examples 'not found' do + it 'returns 404' do + get api(api_path, user) + + expect(response).to have_gitlab_http_status(:not_found) + expect(json_response['message']).to eq('404 Snippet Not Found') + end + end + + context 'when not authorized' do + let(:user) { unauthorized_user } + + it_behaves_like 'not found' + end + + context 'with an invalid snippet ID' do + let(:snippet_id) { 'invalid' } + + it_behaves_like 'not found' + end + + context 'with valid params' do + it 'returns the raw file info' do + expect(Gitlab::Workhorse).to receive(:send_git_blob).and_call_original + + get api(api_path, user) + + aggregate_failures do + expect(response).to have_gitlab_http_status(:ok) + expect(response.media_type).to eq 'text/plain' + expect(response.header[Gitlab::Workhorse::DETECT_HEADER]).to eq 'true' + expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:') + expect(response.header['Content-Disposition']).to match 'filename=".gitattributes"' + end + end + end + + context 'with invalid params' do + using RSpec::Parameterized::TableSyntax + + where(:file_path, :ref, :status, :key, :message) do + '%2Egitattributes' | 'invalid-ref' | :not_found | 'message' | '404 Reference Not Found' + '%2Egitattributes' | nil | :not_found | 'error' | '404 Not Found' + '%2Egitattributes' | '' | :not_found | 'error' | '404 Not Found' + + 'doesnotexist.rb' | 'master' | :not_found | 'message' | '404 File Not Found' + '/does/not/exist.rb' | 'master' | :not_found | 'error' | '404 Not Found' + '%2E%2E%2Fetc%2Fpasswd' | 'master' | :bad_request | 'error' | 'file_path should be a valid file path' + '%2Fetc%2Fpasswd' | 'master' | :bad_request | 'error' | 'file_path should be a valid file path' + '../../etc/passwd' | 'master' | :not_found | 'error' | '404 Not Found' + end + + with_them do + before do + get api(api_path, user) + end + + it { expect(response).to have_gitlab_http_status(status) } + it { expect(json_response[key]).to eq(message) } + end + end +end |