Skip to content

Commit

Permalink
Fixes #32192 - Monkey patch restclient to unescape proxy credentials
Browse files Browse the repository at this point in the history
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
  • Loading branch information
adamruzicka committed Mar 24, 2021
1 parent 2b8d7ae commit 8d918c3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/foreman/http_proxy/rest_client_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ def proxy_uri
end
super
end

def net_http_object(hostname, port)
p_uri = proxy_uri

if p_uri.nil?
# no proxy set
Net::HTTP.new(hostname, port)
elsif !p_uri
# proxy explicitly set to none
Net::HTTP.new(hostname, port, nil, nil, nil, nil)
else
proxy_pass = p_uri.password ? CGI.unescape(p_uri.password) : nil
proxy_user = p_uri.user ? CGI.unescape(p_uri.user) : nil
Net::HTTP.new(hostname, port,
p_uri.hostname, p_uri.port, proxy_user, proxy_pass)
end
end
end
end
end
Expand Down

0 comments on commit 8d918c3

Please sign in to comment.