diff --git a/src/poetry/utils/password_manager.py b/src/poetry/utils/password_manager.py index fcef51d157e..f3e2d295fe8 100644 --- a/src/poetry/utils/password_manager.py +++ b/src/poetry/utils/password_manager.py @@ -94,7 +94,7 @@ def _check(self) -> None: backend = keyring.get_keyring() name = backend.name.split(" ")[0] - if name == "fail": + if name in ("fail", "null"): logger.debug("No suitable keyring backend found") self._is_available = False elif "plaintext" in backend.name.lower(): @@ -107,7 +107,7 @@ def _check(self) -> None: backends = keyring.backend.get_all_keyring() self._is_available = any( - b.name.split(" ")[0] not in ["chainer", "fail"] + b.name.split(" ")[0] not in ["chainer", "fail", "null"] and "plaintext" not in b.name.lower() for b in backends ) diff --git a/tests/conftest.py b/tests/conftest.py index f35ca1bfdc9..fe85fdbee83 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -116,10 +116,31 @@ def with_fail_keyring() -> None: @pytest.fixture() -def with_chained_keyring(mocker: MockerFixture) -> None: +def with_null_keyring() -> None: + import keyring + + from keyring.backends.null import Keyring + + keyring.set_keyring(Keyring()) + + +@pytest.fixture() +def with_chained_fail_keyring(mocker: MockerFixture) -> None: from keyring.backends.fail import Keyring - mocker.patch("keyring.backend.get_all_keyring", [Keyring()]) + mocker.patch("keyring.backend.get_all_keyring", lambda: [Keyring()]) + import keyring + + from keyring.backends.chainer import ChainerBackend + + keyring.set_keyring(ChainerBackend()) + + +@pytest.fixture() +def with_chained_null_keyring(mocker: MockerFixture) -> None: + from keyring.backends.null import Keyring + + mocker.patch("keyring.backend.get_all_keyring", lambda: [Keyring()]) import keyring from keyring.backends.chainer import ChainerBackend diff --git a/tests/utils/test_password_manager.py b/tests/utils/test_password_manager.py index 27747cfb484..062a0ec134e 100644 --- a/tests/utils/test_password_manager.py +++ b/tests/utils/test_password_manager.py @@ -187,8 +187,32 @@ def test_keyring_raises_errors_on_keyring_errors( key_ring.delete_password("foo", "bar") -def test_keyring_with_chainer_backend_and_not_compatible_only_should_be_unavailable( - with_chained_keyring: None, +def test_keyring_with_chainer_backend_and_fail_keyring_should_be_unavailable( + with_chained_fail_keyring: None, +): + key_ring = KeyRing("poetry") + + assert not key_ring.is_available() + + +def test_keyring_with_chainer_backend_and_null_keyring_should_be_unavailable( + with_chained_null_keyring: None, +): + key_ring = KeyRing("poetry") + + assert not key_ring.is_available() + + +def test_null_keyring_should_be_unavailable( + with_null_keyring: None, +): + key_ring = KeyRing("poetry") + + assert not key_ring.is_available() + + +def test_fail_keyring_should_be_unavailable( + with_fail_keyring: None, ): key_ring = KeyRing("poetry")