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

When one keyring attempt fails, don't bother with more #8744

Merged
merged 1 commit into from
Aug 11, 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
3 changes: 3 additions & 0 deletions news/8090.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Only attempt to use the keyring once and if it fails, don't try again.
This prevents spamming users with several keyring unlock prompts when they
cannot unlock or don't want to do so.
2 changes: 2 additions & 0 deletions src/pip/_internal/network/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
def get_keyring_auth(url, username):
# type: (str, str) -> Optional[AuthInfo]
"""Return the tuple auth for a given url from keyring."""
global keyring
if not url or not keyring:
return None

Expand All @@ -69,6 +70,7 @@ def get_keyring_auth(url, username):
logger.warning(
"Keyring is skipped due to an exception: %s", str(exc),
)
keyring = None
return None


Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_network_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,29 @@ def test_keyring_get_credential(monkeypatch, url, expect):
assert auth._get_new_credentials(
url, allow_netrc=False, allow_keyring=True
) == expect


class KeyringModuleBroken(object):
"""Represents the current supported API of keyring, but broken"""

def __init__(self):
self._call_count = 0

def get_credential(self, system, username):
self._call_count += 1
raise Exception("This keyring is broken!")


def test_broken_keyring_disables_keyring(monkeypatch):
keyring_broken = KeyringModuleBroken()
monkeypatch.setattr(pip._internal.network.auth, 'keyring', keyring_broken)

auth = MultiDomainBasicAuth(index_urls=["http://example.com/"])

assert keyring_broken._call_count == 0
for i in range(5):
url = "http://example.com/path" + str(i)
assert auth._get_new_credentials(
url, allow_netrc=False, allow_keyring=True
) == (None, None)
assert keyring_broken._call_count == 1