summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/file_type_detection_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/file_type_detection_spec.rb')
-rw-r--r--spec/lib/gitlab/file_type_detection_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/file_type_detection_spec.rb b/spec/lib/gitlab/file_type_detection_spec.rb
index ba5e7cfabf2..c435d3f6097 100644
--- a/spec/lib/gitlab/file_type_detection_spec.rb
+++ b/spec/lib/gitlab/file_type_detection_spec.rb
@@ -192,6 +192,20 @@ RSpec.describe Gitlab::FileTypeDetection do
end
end
+ describe '#image_safe_for_scaling?' do
+ it 'returns true for allowed image formats' do
+ uploader.store!(upload_fixture('rails_sample.jpg'))
+
+ expect(uploader).to be_image_safe_for_scaling
+ end
+
+ it 'returns false for other files' do
+ uploader.store!(upload_fixture('unsanitized.svg'))
+
+ expect(uploader).not_to be_image_safe_for_scaling
+ end
+ end
+
describe '#dangerous_image?' do
it 'returns true if filename has a dangerous extension' do
uploader.store!(upload_fixture('unsanitized.svg'))
@@ -377,6 +391,31 @@ RSpec.describe Gitlab::FileTypeDetection do
end
end
+ describe '#image_safe_for_scaling?' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:filename, :expectation) do
+ 'img.jpg' | true
+ 'img.jpeg' | true
+ 'img.png' | true
+ 'img.svg' | false
+ end
+
+ with_them do
+ it "returns expected result" do
+ allow(custom_class).to receive(:filename).and_return(filename)
+
+ expect(custom_class.image_safe_for_scaling?).to be(expectation)
+ end
+ end
+
+ it 'returns false if filename is blank' do
+ allow(custom_class).to receive(:filename).and_return(nil)
+
+ expect(custom_class).not_to be_image_safe_for_scaling
+ end
+ end
+
describe '#video?' do
it 'returns true for a video file' do
allow(custom_class).to receive(:filename).and_return('video_sample.mp4')