Skip to content

Commit

Permalink
Improve tests for URL credential parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Aug 4, 2019
1 parent 9d7f3b8 commit 0a6c1c7
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions tests/unit/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 0a6c1c7

Please sign in to comment.