mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
intersphinx: _strip_basic_auth() only removes credentials from URL
This commit is contained in:
parent
35232a3dd6
commit
e7ff996d13
@ -135,27 +135,14 @@ def _strip_basic_auth(url):
|
||||
:param url: url which may or may not contain basic auth credentials
|
||||
:type url: ``str``
|
||||
|
||||
:return: 3-``tuple`` of:
|
||||
|
||||
* (``str``) -- *url* with any basic auth creds removed
|
||||
* (``str`` or ``NoneType``) -- basic auth username or ``None`` if basic
|
||||
auth username not given
|
||||
* (``str`` or ``NoneType``) -- basic auth password or ``None`` if basic
|
||||
auth password not given
|
||||
|
||||
:rtype: ``tuple``
|
||||
:return: *url* with any basic auth creds removed
|
||||
:rtype: ``str``
|
||||
"""
|
||||
url_parts = urlsplit(url)
|
||||
username = url_parts.username
|
||||
password = url_parts.password
|
||||
frags = list(url_parts)
|
||||
frags = list(urlsplit(url))
|
||||
# swap out "user[:pass]@hostname" for "hostname"
|
||||
if url_parts.port:
|
||||
frags[1] = "%s:%s" % (url_parts.hostname, url_parts.port)
|
||||
else:
|
||||
frags[1] = url_parts.hostname
|
||||
url = urlunsplit(frags)
|
||||
return (url, username, password)
|
||||
if '@' in frags[1]:
|
||||
frags[1] = frags[1].split('@')[1]
|
||||
return urlunsplit(frags)
|
||||
|
||||
|
||||
def _read_from_url(url):
|
||||
@ -212,7 +199,7 @@ def fetch_inventory(app, uri, inv):
|
||||
localuri = '://' not in uri
|
||||
if not localuri:
|
||||
# case: inv URI points to remote resource; strip any existing auth
|
||||
uri, _, _ = _strip_basic_auth(uri)
|
||||
uri = _strip_basic_auth(uri)
|
||||
try:
|
||||
if '://' in inv:
|
||||
f = _read_from_url(inv)
|
||||
|
@ -230,29 +230,23 @@ class TestStripBasicAuth(unittest.TestCase):
|
||||
"""basic auth creds stripped from URL containing creds"""
|
||||
url = 'https://user:12345@domain.com/project/objects.inv'
|
||||
expected = 'https://domain.com/project/objects.inv'
|
||||
actual_url, actual_username, actual_password = _strip_basic_auth(url)
|
||||
self.assertEqual(expected, actual_url)
|
||||
self.assertEqual('user', actual_username)
|
||||
self.assertEqual('12345', actual_password)
|
||||
actual = _strip_basic_auth(url)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_no_auth(self):
|
||||
"""url unchanged if param doesn't contain basic auth creds"""
|
||||
url = 'https://domain.com/project/objects.inv'
|
||||
expected = 'https://domain.com/project/objects.inv'
|
||||
actual_url, actual_username, actual_password = _strip_basic_auth(url)
|
||||
self.assertEqual(expected, actual_url)
|
||||
self.assertEqual(None, actual_username)
|
||||
self.assertEqual(None, actual_password)
|
||||
actual = _strip_basic_auth(url)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_having_port(self):
|
||||
"""basic auth creds correctly stripped from URL containing creds even if URL
|
||||
contains port"""
|
||||
url = 'https://user:12345@domain.com:8080/project/objects.inv'
|
||||
expected = 'https://domain.com:8080/project/objects.inv'
|
||||
actual_url, actual_username, actual_password = _strip_basic_auth(url)
|
||||
self.assertEqual(expected, actual_url)
|
||||
self.assertEqual('user', actual_username)
|
||||
self.assertEqual('12345', actual_password)
|
||||
actual = _strip_basic_auth(url)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
def test_getsafeurl_authed():
|
||||
|
Loading…
Reference in New Issue
Block a user