From 41b361544fed4faa89d149885df955e73a4ed5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 21 Jan 2020 20:05:04 +0100 Subject: [PATCH] Fix how repository credentials are retrieved from env vars # Conflicts: # poetry/utils/password_manager.py --- poetry/utils/password_manager.py | 13 ++++++++----- tests/utils/test_password_manager.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/poetry/utils/password_manager.py b/poetry/utils/password_manager.py index 9038d739b10..24a615a46bf 100644 --- a/poetry/utils/password_manager.py +++ b/poetry/utils/password_manager.py @@ -155,11 +155,14 @@ def delete_pypi_token(self, name): def get_http_auth(self, name): auth = self._config.get("http-basic.{}".format(name)) if not auth: - return None - - username, password = auth["username"], auth.get("password") - if password is None: - password = self.keyring.get_password(name, username) + username = self._config.get("http-basic.{}.username".format(name)) + password = self._config.get("http-basic.{}.password".format(name)) + if not username and not password: + return None + else: + username, password = auth["username"], auth.get("password") + if password is None: + password = self.keyring.get_password(name, username) return { "username": username, diff --git a/tests/utils/test_password_manager.py b/tests/utils/test_password_manager.py index a5f89eb028e..675d38b7bbc 100644 --- a/tests/utils/test_password_manager.py +++ b/tests/utils/test_password_manager.py @@ -1,3 +1,5 @@ +import os + import pytest from keyring.backend import KeyringBackend @@ -208,3 +210,17 @@ def test_keyring_with_chainer_backend_and_not_compatible_only_should_be_unavaila key_ring = KeyRing("poetry") assert not key_ring.is_available() + + +def test_get_http_auth_from_environment_variables( + environ, config, mock_available_backend +): + os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar" + os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz" + + manager = PasswordManager(config) + + auth = manager.get_http_auth("foo") + + assert "bar" == auth["username"] + assert "baz" == auth["password"]