| ... | @@ -6,19 +6,35 @@ describe FaviconUploader do |
... | @@ -6,19 +6,35 @@ describe FaviconUploader do |
|
|
let_it_be(:model) { build_stubbed(:user) }
|
|
let_it_be(:model) { build_stubbed(:user) }
|
|
|
let_it_be(:uploader) { described_class.new(model, :favicon) }
|
|
let_it_be(:uploader) { described_class.new(model, :favicon) }
|
|
|
|
|
|
|
|
context 'upload type check' do
|
|
context 'accept whitelist file content type' do
|
|
|
FaviconUploader::EXTENSION_WHITELIST.each do |ext|
|
|
include_context 'ignore extension whitelist check'
|
|
|
context "#{ext} extension" do
|
|
|
|
|
it_behaves_like 'type checked uploads', filenames: "image.#{ext}"
|
|
# We need to feed through a valid path, but we force the parsed mime type
|
|
|
end
|
|
# in a stub below so we can set any path.
|
|
|
|
let_it_be(:path) { File.join('spec', 'fixtures', 'video_sample.mp4') }
|
|
|
|
|
|
|
|
where(:mime_type) { described_class::MIME_WHITELIST }
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
include_context 'force content type detection to mime_type'
|
|
|
|
|
|
|
|
it_behaves_like 'accepted carrierwave upload'
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'upload non-whitelisted file extensions' do
|
|
context 'upload non-whitelisted file content type' do
|
|
|
it 'will deny upload' do
|
|
include_context 'ignore extension whitelist check'
|
|
|
path = File.join('spec', 'fixtures', 'banana_sample.gif')
|
|
|
|
|
fixture_file = fixture_file_upload(path)
|
|
let_it_be(:path) { File.join('spec', 'fixtures', 'sanitized.svg') }
|
|
|
expect { uploader.cache!(fixture_file) }.to raise_exception(CarrierWave::IntegrityError)
|
|
|
|
|
|
it_behaves_like 'denied carrierwave upload'
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'upload misnamed non-whitelisted file content type' do
|
|
|
|
include_context 'ignore extension whitelist check'
|
|
|
|
|
|
|
|
let_it_be(:path) { File.join('spec', 'fixtures', 'not_a_png.png') }
|
|
|
|
|
|
|
|
it_behaves_like 'denied carrierwave upload'
|
|
|
end
|
|
end
|
|
|
end |
|
end |