summaryrefslogtreecommitdiff
path: root/spec/models/blob_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-08-12 17:19:17 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2016-08-15 13:42:52 +0200
commit8171544b3d44df6ce810aa436bf87d137bc9b28f (patch)
treeafbc14ae86b9c002a4d58e6ad273b22711ab770d /spec/models/blob_spec.rb
parent30f5b9a5b711b46f1065baf755e413ceced5646b (diff)
downloadgitlab-ce-8171544b3d44df6ce810aa436bf87d137bc9b28f.tar.gz
Limit the size of SVGs when viewing them as blobssvg-render-size-limit
This ensures that SVGs greater than 2 megabytes are not scrubbed and rendered. This in turn prevents requests from timing out due to reading/scrubbing large SVGs potentially taking a lot of time (and memory). The use of 2 megabytes is completely arbitrary. Fixes gitlab-org/gitlab-ce#1435
Diffstat (limited to 'spec/models/blob_spec.rb')
-rw-r--r--spec/models/blob_spec.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/models/blob_spec.rb b/spec/models/blob_spec.rb
index 1e5d6a34f83..cee20234e1f 100644
--- a/spec/models/blob_spec.rb
+++ b/spec/models/blob_spec.rb
@@ -94,4 +94,26 @@ describe Blob do
expect(blob.to_partial_path).to eq 'download'
end
end
+
+ describe '#size_within_svg_limits?' do
+ let(:blob) { described_class.decorate(double(:blob)) }
+
+ it 'returns true when the blob size is smaller than the SVG limit' do
+ expect(blob).to receive(:size).and_return(42)
+
+ expect(blob.size_within_svg_limits?).to eq(true)
+ end
+
+ it 'returns true when the blob size is equal to the SVG limit' do
+ expect(blob).to receive(:size).and_return(Blob::MAXIMUM_SVG_SIZE)
+
+ expect(blob.size_within_svg_limits?).to eq(true)
+ end
+
+ it 'returns false when the blob size is larger than the SVG limit' do
+ expect(blob).to receive(:size).and_return(1.terabyte)
+
+ expect(blob.size_within_svg_limits?).to eq(false)
+ end
+ end
end