diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 7abe28bd65d..e722ed842f7 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -308,8 +308,8 @@ class CookedPostProcessor end def optimize_urls - # when login is required, attachments can't be on the CDN - if SiteSetting.login_required + # attachments can't be on the CDN when either setting is enabled + if SiteSetting.login_required || SiteSetting.prevent_anons_from_downloading_files @doc.css("a.attachment[href]").each do |a| href = a["href"].to_s a["href"] = UrlHelper.schemaless UrlHelper.absolute_without_cdn(href) if UrlHelper.is_local(href) diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index ba3a701b264..6709417be29 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -446,28 +446,65 @@ describe CookedPostProcessor do it "uses schemaless url for uploads" do cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link
+
+ Google
+
+ text.txt (20 Bytes)
+ :smile: +

' end context "when CDN is enabled" do - it "does use schemaless CDN url for http uploads" do + it "uses schemaless CDN url for http uploads" do Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link
+
+ Google
+
+ text.txt (20 Bytes)
+ :smile: +

' end - it "does not use schemaless CDN url for https uploads" do + it "doesn't use schemaless CDN url for https uploads" do Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link
+
+ Google
+
+ text.txt (20 Bytes)
+ :smile: +

' end - it "does not use CDN when login is required" do + it "doesn't use CDN when login is required" do SiteSetting.login_required = true Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html '

Link

Google

text.txt (20 Bytes)
:smile:

' + expect(cpp.html).to match_html '

Link
+
+ Google
+
+ text.txt (20 Bytes)
+ :smile: +

' + end + + it "doesn't use CDN when preventing anons from downloading files" do + SiteSetting.prevent_anons_from_downloading_files = true + Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") + cpp.optimize_urls + expect(cpp.html).to match_html '

Link
+
+ Google
+
+ text.txt (20 Bytes)
+ :smile: +

' end end