Skip to content

Commit f43bbcd

Browse files
committed
support funky characters in username/passwords for http url parsing
Change-Id: Ia0346a08a1e6bfdafdabe14b3b3be813965ef07f Reviewed-on: https://gerrit.instructure.com/5482 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
1 parent eb7bd86 commit f43bbcd

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/ssl_common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def raw_post(url, payload, headers = {}, form_data = nil)
3636
url = URI.parse(url)
3737
http = self.get_http_conn(url.host, url.port, url.scheme.downcase == 'https')
3838
req = Net::HTTP::Post.new(url.request_uri, headers)
39-
req.basic_auth url.user, url.password if url.user
39+
req.basic_auth URI.unescape(url.user || ""), URI.unescape(url.password || "") if url.user
4040
req.form_data = form_data if form_data
4141
http.start {|http| http.request(req, payload) }
4242
end

spec/lib/ssl_common_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
"somedata"]
3434
end
3535

36+
it "should work with http basic auth, username and password, with encoded characters" do
37+
server, server_thread, post_lines = start_test_http_server
38+
SSLCommon.post_data("http://theusername%40theuseremail.tld:thepassword@localhost:#{server.addr[1]}/endpoint",
39+
"somedata", "application/x-jt-is-so-cool")
40+
server_thread.join
41+
post_lines.should == [
42+
"POST /endpoint HTTP/1.1",
43+
"Accept: */*",
44+
"Content-Type: application/x-jt-is-so-cool",
45+
"Authorization: Basic #{Base64.encode64("theusername@theuseremail.tld:thepassword").strip}",
46+
"",
47+
"somedata"]
48+
end
49+
3650
it "should work with http basic auth, just username" do
3751
server, server_thread, post_lines = start_test_http_server
3852
SSLCommon.post_data("http://theusername@localhost:#{server.addr[1]}/endpoint",

0 commit comments

Comments
 (0)