Skip to content

Commit

Permalink
fix(network/auth): Asks for password when it is None
Browse files Browse the repository at this point in the history
When `get_keyring_auth` provides the password as None, the
user should be prompt to ask password.
  • Loading branch information
gutsytechster committed Apr 12, 2020
1 parent 4416e88 commit 179f9b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/7998.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ask for password when either the password is None.
2 changes: 1 addition & 1 deletion src/pip/_internal/network/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _prompt_for_password(self, netloc):
if not username:
return None, None
auth = get_keyring_auth(netloc, username)
if auth:
if auth and auth[0] and auth[1]:
return auth[0], auth[1], False
password = ask_password("Password: ")
return username, password, True
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_network_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ def ask_input(prompt):
assert actual == ("user", "user!netloc", False)


def test_keyring_get_password_after_prompt_when_none(monkeypatch):
keyring = KeyringModuleV1()
monkeypatch.setattr('pip._internal.network.auth.keyring', keyring)
auth = MultiDomainBasicAuth()

def ask_input(prompt):
assert prompt == "User for unknown.com: "
return "user"

def ask_password(prompt):
assert prompt == "Password: "
return "fake_password"

monkeypatch.setattr('pip._internal.network.auth.ask_input', ask_input)
monkeypatch.setattr(
'pip._internal.network.auth.ask_password', ask_password)
actual = auth._prompt_for_password("unknown.com")
assert actual == ("user", "fake_password", True)


def test_keyring_get_password_username_in_index(monkeypatch):
keyring = KeyringModuleV1()
monkeypatch.setattr('pip._internal.network.auth.keyring', keyring)
Expand Down

0 comments on commit 179f9b0

Please sign in to comment.