Skip to content

Commit

Permalink
Fix updated patch and add missing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Apr 15, 2024
1 parent 519d089 commit 873ab48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/omniauth/dynamic_full_host.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# configures public url for our application
module Omniauth::DynamicFullHost
def full_host_url(url = nil)
def self.full_host_url(url = nil)
# unescapes url on-the-fly because it might be double-escaped in some environments
#(it happens for me at work with 2 reverse-proxies in front of the app...)
url = CGI.unescape(url) if url
Expand All @@ -10,7 +10,7 @@ def full_host_url(url = nil)
url = Setting["host_name"]
# else, parse it and remove both request_uri and query_string
else
uri = URI.parse(URI.encode(url)) # Encode to ensure we only have ASCII charaters in url
uri = URI.parse(URI::Parser.new.escape(url)) # Encode to ensure we only have ASCII charaters in url
url = "#{uri.scheme}://#{uri.host}"
url << ":#{uri.port}" unless uri.default_port == uri.port
end
Expand All @@ -19,5 +19,5 @@ def full_host_url(url = nil)
end

OmniAuth.config.full_host = Proc.new do |env|
full_host_url(env["rack.session"]["omniauth.origin"] || env["omniauth.origin"])
Omniauth::DynamicFullHost.full_host_url(env["rack.session"]["omniauth.origin"] || env["omniauth.origin"])
end
12 changes: 12 additions & 0 deletions spec/models/redmine_omniauth_cas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@
expect(RedmineOmniauthCas.cas_service_validate_url).to be_nil
end
end

context "dynamic full host" do
it "should return host name from setting if no url" do
Setting["host_name"] = "http://redmine.example.com"
expect(Omniauth::DynamicFullHost.full_host_url).to eq "http://redmine.example.com"
end

it "should return host name from url if url is present" do
url = "https://redmine.example.com:3000/some/path"
expect(Omniauth::DynamicFullHost.full_host_url(url)).to eq "https://redmine.example.com:3000"
end
end
end

0 comments on commit 873ab48

Please sign in to comment.