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 "disabled", keyring uses a "null" keyring and should be unavaila… #5251

Merged
merged 6 commits into from
Apr 12, 2022
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
4 changes: 2 additions & 2 deletions src/poetry/utils/password_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
)
Expand Down
25 changes: 23 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 26 additions & 2 deletions tests/utils/test_password_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down