Skip to content

Commit

Permalink
Fix non-ascii characters support in curl_httpclient username and pass…
Browse files Browse the repository at this point in the history
…word
  • Loading branch information
ptylenda authored and bdarnell committed May 20, 2018
1 parent 6410cd9 commit cc3ca85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tornado/curl_httpclient.py
Expand Up @@ -450,7 +450,7 @@ def ioctl(cmd):
else:
raise ValueError("Unsupported auth_mode %s" % request.auth_mode)

curl.setopt(pycurl.USERPWD, native_str(userpwd))
curl.setopt(pycurl.USERPWD, utf8(userpwd))
curl_log.debug("%s %s (username: %r)", request.method, request.url,
request.auth_username)
else:
Expand Down
18 changes: 13 additions & 5 deletions tornado/test/curl_httpclient_test.py
Expand Up @@ -32,13 +32,15 @@ def get_http_client(self):


class DigestAuthHandler(RequestHandler):
def initialize(self, username, password):
self.username = username
self.password = password

def get(self):
realm = 'test'
opaque = 'asdf'
# Real implementations would use a random nonce.
nonce = "1234"
username = 'foo'
password = 'bar'

auth_header = self.request.headers.get('Authorization', None)
if auth_header is not None:
Expand All @@ -53,9 +55,9 @@ def get(self):
assert param_dict['realm'] == realm
assert param_dict['opaque'] == opaque
assert param_dict['nonce'] == nonce
assert param_dict['username'] == username
assert param_dict['username'] == self.username
assert param_dict['uri'] == self.request.path
h1 = md5(utf8('%s:%s:%s' % (username, realm, password))).hexdigest()
h1 = md5(utf8('%s:%s:%s' % (self.username, realm, self.password))).hexdigest()
h2 = md5(utf8('%s:%s' % (self.request.method,
self.request.path))).hexdigest()
digest = md5(utf8('%s:%s:%s' % (h1, nonce, h2))).hexdigest()
Expand Down Expand Up @@ -88,7 +90,8 @@ def setUp(self):

def get_app(self):
return Application([
('/digest', DigestAuthHandler),
('/digest', DigestAuthHandler, {'username': 'foo', 'password': 'bar'}),
('/digest_non_ascii', DigestAuthHandler, {'username': 'foo', 'password': 'barユ£'}),
('/custom_reason', CustomReasonHandler),
('/custom_fail_reason', CustomFailReasonHandler),
])
Expand Down Expand Up @@ -143,3 +146,8 @@ def test_failed_setup(self):
# during the setup phase doesn't lead the request to
# be dropped on the floor.
response = self.fetch(u'/ユニコード', raise_error=True)

def test_digest_auth_non_ascii(self):
response = self.fetch('/digest_non_ascii', auth_mode='digest',
auth_username='foo', auth_password='barユ£')
self.assertEqual(response.body, b'ok')

0 comments on commit cc3ca85

Please sign in to comment.