Commit 408b0fb8 by Arun Babu Neelicattu

authenticator: use configured repositories

This change ensures that we use configured repositories to detect
credentials instead of `http-basic.`

Resolves: #2799

Co-authored-by: Fredrik Bergroth <fbergroth@gmail.com>
parent c14a902f
...@@ -135,7 +135,8 @@ class Authenticator(object): ...@@ -135,7 +135,8 @@ class Authenticator(object):
self, netloc self, netloc
): # type: (str) -> Tuple[Optional[str], Optional[str]] ): # type: (str) -> Tuple[Optional[str], Optional[str]]
credentials = (None, None) credentials = (None, None)
for repository_name in self._config.get("http-basic", {}):
for repository_name in self._config.get("repositories", []):
repository_config = self._config.get( repository_config = self._config.get(
"repositories.{}".format(repository_name) "repositories.{}".format(repository_name)
) )
......
...@@ -180,3 +180,22 @@ def test_authenticator_request_retries_on_status_code( ...@@ -180,3 +180,22 @@ def test_authenticator_request_retries_on_status_code(
assert excinfo.value.response.text == content assert excinfo.value.response.text == content
assert sleep.call_count == attempts assert sleep.call_count == attempts
@pytest.fixture
def environment_repository_credentials(monkeypatch):
monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_USERNAME", "bar")
monkeypatch.setenv("POETRY_HTTP_BASIC_FOO_PASSWORD", "baz")
def test_authenticator_uses_env_provided_credentials(
config, environ, mock_remote, http, environment_repository_credentials
):
config.merge({"repositories": {"foo": {"url": "https://foo.bar/simple/"}}})
authenticator = Authenticator(config, NullIO())
authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz")
request = http.last_request()
assert "Basic YmFyOmJheg==" == request.headers["Authorization"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment