1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Banzai::UploadsController, feature_category: :markdown do
describe '#show' do
let_it_be(:user) { create(:user) }
let(:txt_upload) { fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain') }
let(:jpg_upload) { fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg') }
let(:secret) { FileUploader.generate_secret }
context 'with project upload' do
let_it_be(:project, reload: true) { create(:project, :private) }
before_all do
project.add_guest(user)
end
before do
allow(FileUploader).to receive(:generate_secret).and_return(secret)
end
context 'with non-media uploads' do
before do
UploadService.new(project, txt_upload, FileUploader).execute
end
it 'returns 200 when user has access' do
sign_in(user)
get "/-/project/#{project.id}/uploads/#{secret}/doc_sample.txt"
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns 404 when user does not have access' do
get "/-/project/#{project.id}/uploads/#{secret}/doc_sample.txt"
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'with media uploads' do
before do
UploadService.new(project, jpg_upload, FileUploader).execute
end
context 'when enforce_auth_checks_on_uploads is disabled' do
before do
project.update!(enforce_auth_checks_on_uploads: false)
end
it 'returns 200 even when user has no access' do
get "/-/project/#{project.id}/uploads/#{secret}/rails_sample.jpg"
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when enforce_auth_checks_on_uploads is enabled' do
before do
project.update!(enforce_auth_checks_on_uploads: true)
end
it 'returns 404 when user does not have access' do
get "/-/project/#{project.id}/uploads/#{secret}/rails_sample.jpg"
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
context 'with group upload' do
let_it_be(:group) { create(:group, :private) }
before_all do
group.add_guest(user)
end
before do
allow(NamespaceFileUploader).to receive(:generate_secret).and_return(secret)
end
context 'with non-media uploads' do
before do
UploadService.new(group, txt_upload, NamespaceFileUploader).execute
end
it 'returns 200 when user has access' do
sign_in(user)
get "/-/group/#{group.id}/uploads/#{secret}/doc_sample.txt"
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns 404 when user does not have access' do
get "/-/group/#{group.id}/uploads/#{secret}/doc_sample.txt"
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'with media uploads' do
before do
UploadService.new(group, jpg_upload, NamespaceFileUploader).execute
end
it 'returns 200 even when user has no access' do
get "/-/group/#{group.id}/uploads/#{secret}/rails_sample.jpg"
expect(response).to have_gitlab_http_status(:ok)
end
end
end
end
end
|