mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
fix(network/auth): Asks for password when it is None
When `get_keyring_auth` provides the password as None, the user should be prompt to ask password.
This commit is contained in:
parent
adfb70a309
commit
2276f9528c
1
news/7998.bugfix
Normal file
1
news/7998.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Prompt the user for password if the keyring backend doesn't return one
|
|
@ -219,7 +219,7 @@ class MultiDomainBasicAuth(AuthBase):
|
|||
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
|
||||
|
|
|
@ -123,6 +123,26 @@ def test_keyring_get_password_after_prompt(monkeypatch):
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue