Skip to content

Commit c4f4c00

Browse files
committed
For #33172, support @ in proxy authentication passwords
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
1 parent d1318fa commit c4f4c00

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

shotgun_api3/shotgun.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,9 @@ def __init__(self,
429429

430430
# foo:[email protected]:3456
431431
if http_proxy:
432-
# check if we're using authentication
433-
p = http_proxy.split("@", 1)
432+
# check if we're using authentication. Start from the end since there might be
433+
# @ in the user's password.
434+
p = http_proxy.rsplit("@", 1)
434435
if len(p) > 1:
435436
self.config.proxy_user, self.config.proxy_pass = \
436437
p[0].split(":", 1)

tests/tests_unit.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ def test_http_proxy_server_and_port_with_authentication(self):
8484
self.assertEquals(sg.config.proxy_port, proxy_port)
8585
self.assertEquals(sg.config.proxy_user, proxy_user)
8686
self.assertEquals(sg.config.proxy_pass, proxy_pass)
87+
88+
def test_http_proxy_with_at_in_password(self):
89+
proxy_server = "someserver.com"
90+
proxy_port = 1234
91+
proxy_user = "user"
92+
proxy_pass = "p@ssword"
93+
http_proxy = "%s:%s@%s:%d" % (proxy_user, proxy_pass, proxy_server,
94+
proxy_port)
95+
sg = api.Shotgun(self.server_path,
96+
self.script_name,
97+
self.api_key,
98+
http_proxy=http_proxy,
99+
connect=False)
100+
self.assertEquals(sg.config.proxy_server, proxy_server)
101+
self.assertEquals(sg.config.proxy_port, proxy_port)
102+
self.assertEquals(sg.config.proxy_user, proxy_user)
103+
self.assertEquals(sg.config.proxy_pass, proxy_pass)
87104

88105
def test_malformatted_proxy_info(self):
89106
proxy_server = "someserver.com"

0 commit comments

Comments
 (0)