parent
993f847a2c
commit
c666ef556d
|
@ -273,7 +273,8 @@ describe CookedPostProcessor do
|
||||||
upload_id: upload.id,
|
upload_id: upload.id,
|
||||||
sha1: SecureRandom.hex,
|
sha1: SecureRandom.hex,
|
||||||
extension: '.jpg',
|
extension: '.jpg',
|
||||||
filesize: 500
|
filesize: 500,
|
||||||
|
version: OptimizedImage::VERSION
|
||||||
)
|
)
|
||||||
|
|
||||||
# fake 3x optimized image, we lose 2 pixels here over original due to rounding on downsize
|
# fake 3x optimized image, we lose 2 pixels here over original due to rounding on downsize
|
||||||
|
@ -407,7 +408,7 @@ describe CookedPostProcessor do
|
||||||
FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
|
FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
|
||||||
|
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/uploads/default/#{upload.sha1}\" title=\"logo.png\"><img src=\"/uploads/default/optimized/1X/#{upload.sha1}_1_690x788.png\" width=\"690\" height=\"788\"><div class=\"meta\">
|
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/uploads/default/#{upload.sha1}\" title=\"logo.png\"><img src=\"/uploads/default/optimized/1X/#{upload.sha1}_#{OptimizedImage::VERSION}_690x788.png\" width=\"690\" height=\"788\"><div class=\"meta\">
|
||||||
<span class=\"filename\">logo.png</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
<span class=\"filename\">logo.png</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
||||||
</div></a></div></p>"
|
</div></a></div></p>"
|
||||||
expect(cpp).to be_dirty
|
expect(cpp).to be_dirty
|
||||||
|
@ -500,7 +501,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "crops the image" do
|
it "crops the image" do
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/uploads/default/#{upload.sha1}\" title=\"logo.png\"><img src=\"/uploads/default/optimized/1X/#{upload.sha1}_1_230x500.png\" width=\"230\" height=\"500\"><div class=\"meta\">
|
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/uploads/default/#{upload.sha1}\" title=\"logo.png\"><img src=\"/uploads/default/optimized/1X/#{upload.sha1}_#{OptimizedImage::VERSION}_230x500.png\" width=\"230\" height=\"500\"><div class=\"meta\">
|
||||||
<span class=\"filename\">logo.png</span><span class=\"informations\">1125×2436 1.21 KB</span><span class=\"expand\"></span>
|
<span class=\"filename\">logo.png</span><span class=\"informations\">1125×2436 1.21 KB</span><span class=\"expand\"></span>
|
||||||
</div></a></div></p>"
|
</div></a></div></p>"
|
||||||
expect(cpp).to be_dirty
|
expect(cpp).to be_dirty
|
||||||
|
@ -531,7 +532,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "generates overlay information" do
|
it "generates overlay information" do
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/subfolder/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/subfolder/uploads/default/#{upload.sha1}\" title=\"logo.png\"><img src=\"/subfolder/uploads/default/optimized/1X/#{upload.sha1}_1_690x788.png\" width=\"690\" height=\"788\"><div class=\"meta\">
|
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/subfolder/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/subfolder/uploads/default/#{upload.sha1}\" title=\"logo.png\"><img src=\"/subfolder/uploads/default/optimized/1X/#{upload.sha1}_#{OptimizedImage::VERSION}_690x788.png\" width=\"690\" height=\"788\"><div class=\"meta\">
|
||||||
<span class=\"filename\">logo.png</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
<span class=\"filename\">logo.png</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
||||||
</div></a></div></p>"
|
</div></a></div></p>"
|
||||||
expect(cpp).to be_dirty
|
expect(cpp).to be_dirty
|
||||||
|
@ -540,7 +541,7 @@ describe CookedPostProcessor do
|
||||||
it "should escape the filename" do
|
it "should escape the filename" do
|
||||||
upload.update_attributes!(original_filename: "><img src=x onerror=alert('haha')>.png")
|
upload.update_attributes!(original_filename: "><img src=x onerror=alert('haha')>.png")
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/subfolder/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/subfolder/uploads/default/#{upload.sha1}\" title=\"&gt;&lt;img src=x onerror=alert(&#39;haha&#39;)&gt;.png\"><img src=\"/subfolder/uploads/default/optimized/1X/#{upload.sha1}_1_690x788.png\" width=\"690\" height=\"788\"><div class=\"meta\">
|
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/subfolder/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/subfolder/uploads/default/#{upload.sha1}\" title=\"&gt;&lt;img src=x onerror=alert(&#39;haha&#39;)&gt;.png\"><img src=\"/subfolder/uploads/default/optimized/1X/#{upload.sha1}_#{OptimizedImage::VERSION}_690x788.png\" width=\"690\" height=\"788\"><div class=\"meta\">
|
||||||
<span class=\"filename\">&gt;&lt;img src=x onerror=alert(&#39;haha&#39;)&gt;.png</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
<span class=\"filename\">&gt;&lt;img src=x onerror=alert(&#39;haha&#39;)&gt;.png</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
||||||
</div></a></div></p>"
|
</div></a></div></p>"
|
||||||
end
|
end
|
||||||
|
@ -566,7 +567,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "generates overlay information" do
|
it "generates overlay information" do
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/uploads/default/#{upload.sha1}\" title=\"WAT\"><img src=\"/uploads/default/optimized/1X/#{upload.sha1}_1_690x788.png\" title=\"WAT\" width=\"690\" height=\"788\"><div class=\"meta\">
|
expect(cpp.html).to match_html "<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"/uploads/default/original/1X/1234567890123456.jpg\" data-download-href=\"/uploads/default/#{upload.sha1}\" title=\"WAT\"><img src=\"/uploads/default/optimized/1X/#{upload.sha1}_#{OptimizedImage::VERSION}_690x788.png\" title=\"WAT\" width=\"690\" height=\"788\"><div class=\"meta\">
|
||||||
<span class=\"filename\">WAT</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
<span class=\"filename\">WAT</span><span class=\"informations\">1750×2000 1.21 KB</span><span class=\"expand\"></span>
|
||||||
</div></a></div></p>"
|
</div></a></div></p>"
|
||||||
expect(cpp).to be_dirty
|
expect(cpp).to be_dirty
|
||||||
|
|
|
@ -176,21 +176,25 @@ describe FileStore::S3Store do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#remove_optimized_image" do
|
describe "#remove_optimized_image" do
|
||||||
let(:optimized_image) do
|
let(:optimized_image) { Fabricate(:optimized_image, upload: upload) }
|
||||||
Fabricate(:optimized_image,
|
|
||||||
url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/optimized/1X/#{upload.sha1}_1_100x200.png",
|
let(:image_path) do
|
||||||
upload: upload
|
FileStore::BaseStore.new.get_path_for_optimized_image(optimized_image)
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
optimized_image.update!(
|
||||||
|
url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com#{image_path}"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes the file from s3 with the right paths" do
|
it "removes the file from s3 with the right paths" do
|
||||||
store.expects(:get_depth_for).with(optimized_image.upload.id).returns(0)
|
|
||||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||||
s3_object = stub
|
s3_object = stub
|
||||||
|
|
||||||
s3_bucket.expects(:object).with("tombstone/optimized/1X/#{upload.sha1}_1_100x200.png").returns(s3_object)
|
s3_bucket.expects(:object).with("tombstone/#{image_path}").returns(s3_object)
|
||||||
s3_object.expects(:copy_from).with(copy_source: "s3-upload-bucket/optimized/1X/#{upload.sha1}_1_100x200.png")
|
s3_object.expects(:copy_from).with(copy_source: "s3-upload-bucket/#{image_path}")
|
||||||
s3_bucket.expects(:object).with("optimized/1X/#{upload.sha1}_1_100x200.png").returns(s3_object)
|
s3_bucket.expects(:object).with("#{image_path}").returns(s3_object)
|
||||||
s3_object.expects(:delete)
|
s3_object.expects(:delete)
|
||||||
|
|
||||||
store.remove_optimized_image(optimized_image)
|
store.remove_optimized_image(optimized_image)
|
||||||
|
@ -202,13 +206,21 @@ describe FileStore::S3Store do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes the file from s3 with the right paths" do
|
it "removes the file from s3 with the right paths" do
|
||||||
store.expects(:get_depth_for).with(optimized_image.upload.id).returns(0)
|
|
||||||
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
|
||||||
s3_object = stub
|
s3_object = stub
|
||||||
|
|
||||||
s3_bucket.expects(:object).with("discourse-uploads/tombstone/optimized/1X/#{upload.sha1}_1_100x200.png").returns(s3_object)
|
s3_bucket.expects(:object)
|
||||||
s3_object.expects(:copy_from).with(copy_source: "s3-upload-bucket/discourse-uploads/optimized/1X/#{upload.sha1}_1_100x200.png")
|
.with("discourse-uploads/tombstone/#{image_path}")
|
||||||
s3_bucket.expects(:object).with("discourse-uploads/optimized/1X/#{upload.sha1}_1_100x200.png").returns(s3_object)
|
.returns(s3_object)
|
||||||
|
|
||||||
|
s3_object.expects(:copy_from).with(
|
||||||
|
copy_source: "s3-upload-bucket/discourse-uploads/#{image_path}"
|
||||||
|
)
|
||||||
|
|
||||||
|
s3_bucket.expects(:object).with(
|
||||||
|
"discourse-uploads/#{image_path}"
|
||||||
|
).returns(s3_object)
|
||||||
|
|
||||||
s3_object.expects(:delete)
|
s3_object.expects(:delete)
|
||||||
|
|
||||||
store.remove_optimized_image(optimized_image)
|
store.remove_optimized_image(optimized_image)
|
||||||
|
|
|
@ -84,7 +84,8 @@ describe UserAvatarsController do
|
||||||
upload: upload,
|
upload: upload,
|
||||||
width: 98,
|
width: 98,
|
||||||
height: 98,
|
height: 98,
|
||||||
url: "//test.s3.dualstack.us-east-1.amazonaws.com/something/else"
|
url: "//test.s3.dualstack.us-east-1.amazonaws.com/something/else",
|
||||||
|
version: OptimizedImage::VERSION
|
||||||
)
|
)
|
||||||
|
|
||||||
user = Fabricate(:user, uploaded_avatar_id: upload.id)
|
user = Fabricate(:user, uploaded_avatar_id: upload.id)
|
||||||
|
|
Loading…
Reference in New Issue