FIX: properly support HTTPS CDN on HTTP site

Previously we changed all CDN links to schemaless.

This is desirable for non HTTPS sites, to ease migration to HTTPS.
It is not desirable for secure sites.

Once site is secure or CDN is secure a rebake should be required
to move it back to non-secure.
This commit is contained in:
Sam 2015-07-24 14:08:32 +10:00
parent b22c890e4b
commit 7a5a195dc0
3 changed files with 12 additions and 4 deletions

View File

@ -18,7 +18,7 @@ class UrlHelper
end end
def self.schemaless(url) def self.schemaless(url)
url.sub(/^https?:/, "") url.sub(/^http:/, "")
end end
end end

View File

@ -317,7 +317,7 @@ describe CookedPostProcessor do
context "when CDN is enabled" do context "when CDN is enabled" do
it "uses schemaless CDN url for uploads" do it "does use schemaless CDN url for http uploads" do
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
cpp.optimize_urls cpp.optimize_urls
expect(cpp.html).to match_html '<a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a> expect(cpp.html).to match_html '<a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a>
@ -325,6 +325,14 @@ describe CookedPostProcessor do
<img src="http://foo.bar/image.png">' <img src="http://foo.bar/image.png">'
end end
it "does not 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 '<a href="https://my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a>
<img src="https://my.cdn.com/uploads/default/1/1234567890123456.jpg"><a href="http://www.google.com">Google</a>
<img src="http://foo.bar/image.png">'
end
end end
end end

View File

@ -56,9 +56,9 @@ describe UrlHelper do
describe "#schemaless" do describe "#schemaless" do
it "removes http or https schemas only" do it "removes http schemas only" do
expect(UrlHelper.schemaless("http://www.discourse.org")).to eq("//www.discourse.org") expect(UrlHelper.schemaless("http://www.discourse.org")).to eq("//www.discourse.org")
expect(UrlHelper.schemaless("https://secure.discourse.org")).to eq("//secure.discourse.org") expect(UrlHelper.schemaless("https://secure.discourse.org")).to eq("https://secure.discourse.org")
expect(UrlHelper.schemaless("ftp://ftp.discourse.org")).to eq("ftp://ftp.discourse.org") expect(UrlHelper.schemaless("ftp://ftp.discourse.org")).to eq("ftp://ftp.discourse.org")
end end