Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(network/auth): Asks for password when it is None #8027

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/7998.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prompt the user for password if the keyring backend doesn't return one
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] is not None and auth[1] is not None:
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