Skip to content

Commit

Permalink
For #33172, support @ in proxy authentication passwords
Browse files Browse the repository at this point in the history
Splitting the string on @ was the right idea, but we have to do it from the end, since the password might have @ in it. Splitting from the end is safe since the the host and port number can't have this character.
Closes #105
  • Loading branch information
jfboismenu committed Feb 11, 2016
1 parent d1318fa commit c4f4c00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,9 @@ def __init__(self,

# foo:[email protected]:3456
if http_proxy:
# check if we're using authentication
p = http_proxy.split("@", 1)
# check if we're using authentication. Start from the end since there might be
# @ in the user's password.
p = http_proxy.rsplit("@", 1)
if len(p) > 1:
self.config.proxy_user, self.config.proxy_pass = \
p[0].split(":", 1)
Expand Down
17 changes: 17 additions & 0 deletions tests/tests_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ def test_http_proxy_server_and_port_with_authentication(self):
self.assertEquals(sg.config.proxy_port, proxy_port)
self.assertEquals(sg.config.proxy_user, proxy_user)
self.assertEquals(sg.config.proxy_pass, proxy_pass)

def test_http_proxy_with_at_in_password(self):
proxy_server = "someserver.com"
proxy_port = 1234
proxy_user = "user"
proxy_pass = "p@ssword"
http_proxy = "%s:%s@%s:%d" % (proxy_user, proxy_pass, proxy_server,
proxy_port)
sg = api.Shotgun(self.server_path,
self.script_name,
self.api_key,
http_proxy=http_proxy,
connect=False)
self.assertEquals(sg.config.proxy_server, proxy_server)
self.assertEquals(sg.config.proxy_port, proxy_port)
self.assertEquals(sg.config.proxy_user, proxy_user)
self.assertEquals(sg.config.proxy_pass, proxy_pass)

def test_malformatted_proxy_info(self):
proxy_server = "someserver.com"
Expand Down

0 comments on commit c4f4c00

Please sign in to comment.