FIX: Safely skip secure_media steps when it's not enabled (#11110)

* FIX: Safely skip secure_media steps when it's not enabled

* DEV: Secure media tests should enable secure media
This commit is contained in:
Rafael dos Santos Silva 2020-11-03 13:53:15 -03:00 committed by GitHub
parent d2116f0029
commit b70b3e867c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -278,7 +278,7 @@ module Email
def to_html
# needs to be before class + id strip because we need to style redacted
# media and also not double-redact already redacted from lower levels
replace_secure_media_urls
replace_secure_media_urls if SiteSetting.secure_media?
strip_classes_and_ids
replace_relative_urls

View File

@ -432,7 +432,7 @@ module PrettyText
# images by themselves or inside a onebox
doc.css('img[src]').each do |img|
url = if img.parent.classes.include?("aspect-image")
url = if img.parent.classes.include?("aspect-image") && img.attributes["srcset"].present?
# we are using the first image from the srcset here so we get the
# optimized image instead of the original, because an optimized

View File

@ -188,6 +188,11 @@ describe Email::Styles do
end
context "replace_secure_media_urls" do
before do
setup_s3
SiteSetting.secure_media = true
end
let(:attachments) { { 'testimage.png' => stub(url: 'email/test.png') } }
it "replaces secure media within a link with a placeholder" do
frag = html_fragment("<a href=\"#{Discourse.base_url}\/secure-media-uploads/original/1X/testimage.png\"><img src=\"/secure-media-uploads/original/1X/testimage.png\"></a>")
@ -208,6 +213,11 @@ describe Email::Styles do
end
context "inline_secure_images" do
before do
setup_s3
SiteSetting.secure_media = true
end
let(:attachments) { { 'testimage.png' => stub(url: 'cid:email/test.png') } }
fab!(:upload) { Fabricate(:upload, original_filename: 'testimage.png', secure: true, sha1: '123456') }
let(:html) { "<a href=\"#{Discourse.base_url}\/secure-media-uploads/original/1X/123456.png\"><img src=\"/secure-media-uploads/original/1X/123456.png\" width=\"20\" height=\"30\"></a>" }