-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of tokens (single part credentials) in URLs (#6818)
- Loading branch information
Showing
3 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix handling of tokens (single part credentials) in URLs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -490,18 +490,53 @@ def test_insecure_host_cache_is_not_enabled(self, tmpdir): | |
assert not hasattr(session.adapters["https://example.com/"], "cache") | ||
|
||
|
||
def test_get_credentials(): | ||
@pytest.mark.parametrize(["input_url", "url", "username", "password"], [ | ||
( | ||
"http://user%40email.com:[email protected]/path", | ||
"http://example.com/path", | ||
"[email protected]", | ||
"password", | ||
), | ||
( | ||
"http://username:[email protected]/path", | ||
"http://example.com/path", | ||
"username", | ||
"password", | ||
), | ||
( | ||
"http://[email protected]/path", | ||
"http://example.com/path", | ||
"token", | ||
"", | ||
), | ||
( | ||
"http://example.com/path", | ||
"http://example.com/path", | ||
None, | ||
None, | ||
), | ||
]) | ||
def test_get_credentials_parses_correctly(input_url, url, username, password): | ||
auth = MultiDomainBasicAuth() | ||
get = auth._get_url_and_credentials | ||
|
||
# Check URL parsing | ||
assert get("http://foo:[email protected]/path") \ | ||
== ('http://example.com/path', 'foo', 'bar') | ||
assert auth.passwords['example.com'] == ('foo', 'bar') | ||
assert get(input_url) == (url, username, password) | ||
assert ( | ||
# There are no credentials in the URL | ||
(username is None and password is None) or | ||
# Credentials were found and "cached" appropriately | ||
auth.passwords['example.com'] == (username, password) | ||
) | ||
|
||
|
||
def test_get_credentials_uses_cached_credentials(): | ||
auth = MultiDomainBasicAuth() | ||
auth.passwords['example.com'] = ('user', 'pass') | ||
assert get("http://foo:[email protected]/path") \ | ||
== ('http://example.com/path', 'user', 'pass') | ||
|
||
got = auth._get_url_and_credentials("http://foo:[email protected]/path") | ||
expected = ('http://example.com/path', 'user', 'pass') | ||
assert got == expected | ||
|
||
|
||
def test_get_index_url_credentials(): | ||
|