diff --git a/lib/configuration_methods.rb b/lib/configuration_methods.rb index fc085afdd..d9546dce7 100644 --- a/lib/configuration_methods.rb +++ b/lib/configuration_methods.rb @@ -6,15 +6,16 @@ module Configuration return @pod_uri.dup unless @pod_uri.nil? url = environment.url.get - url = "http://#{url}" unless url =~ /^(https?:\/\/)/ - url << "/" unless url.end_with?("/") begin - @pod_uri = Addressable::URI.parse(url) + @pod_uri = Addressable::URI.heuristic_parse(url) rescue puts "WARNING: pod url #{url} is not a legal URI" end + @pod_uri.scheme = "https" if environment.require_ssl? + @pod_uri.path = "/" + @pod_uri.dup end diff --git a/spec/lib/configuration_methods_spec.rb b/spec/lib/configuration_methods_spec.rb index 3783f3fc3..8e474c381 100644 --- a/spec/lib/configuration_methods_spec.rb +++ b/spec/lib/configuration_methods_spec.rb @@ -12,6 +12,7 @@ describe Configuration::Methods do describe "#pod_uri" do before do @settings.environment.url = nil + @settings.environment.require_ssl = false @settings.instance_variable_set(:@pod_uri, nil) end @@ -36,6 +37,18 @@ describe Configuration::Methods do expect(@settings.pod_uri.to_s).to eq("http://example.org/") end + it "adds https:// on the front if require_ssl is true" do + @settings.environment.require_ssl = true + @settings.environment.url = "example.org" + expect(@settings.pod_uri.to_s).to eq("https://example.org/") + end + + it "changes http to https if require_ssl is true" do + @settings.environment.require_ssl = true + @settings.environment.url = "http://example.org/" + expect(@settings.pod_uri.to_s).to eq("https://example.org/") + end + it "does not add a prefix if there already is https:// on the front" do @settings.environment.url = "https://example.org/" expect(@settings.pod_uri.to_s).to eq("https://example.org/")