debian-mirror-gitlab/spec/uploaders/content_type_whitelist_spec.rb

41 lines
1 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ContentTypeWhitelist do
2020-05-24 23:13:21 +05:30
let_it_be(:model) { build_stubbed(:user) }
2021-09-30 23:02:18 +05:30
2020-05-24 23:13:21 +05:30
let!(:uploader) do
stub_const('DummyUploader', Class.new(CarrierWave::Uploader::Base))
DummyUploader.class_eval do
include ContentTypeWhitelist::Concern
2020-04-08 14:13:33 +05:30
2020-05-24 23:13:21 +05:30
def content_type_whitelist
%w[image/png image/jpeg]
end
2020-04-08 14:13:33 +05:30
end
2020-05-24 23:13:21 +05:30
DummyUploader.new(model, :dummy)
end
2020-04-08 14:13:33 +05:30
context 'upload whitelisted file content type' do
let(:path) { File.join('spec', 'fixtures', 'rails_sample.jpg') }
it_behaves_like 'accepted carrierwave upload'
it_behaves_like 'upload with content type', 'image/jpeg'
end
context 'upload non-whitelisted file content type' do
let(:path) { File.join('spec', 'fixtures', 'sanitized.svg') }
it_behaves_like 'denied carrierwave upload'
end
context 'upload misnamed non-whitelisted file content type' do
let(:path) { File.join('spec', 'fixtures', 'not_a_png.png') }
it_behaves_like 'denied carrierwave upload'
end
end