Skip to content

Commit

Permalink
Fix how repository credentials are retrieved from env vars (#1909)
Browse files Browse the repository at this point in the history
# Conflicts:
#	poetry/utils/password_manager.py
  • Loading branch information
sdispater committed Jan 31, 2020
1 parent 4897a70 commit 4687ef8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 8 additions & 5 deletions poetry/utils/password_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions tests/utils/test_password_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from keyring.backend import KeyringBackend
Expand Down Expand Up @@ -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"]

0 comments on commit 4687ef8

Please sign in to comment.