diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index 9c01461e9fa..cd6e5cb2101 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -103,7 +103,7 @@ def request(self, method: str, url: str, **kwargs: Any) -> requests.Response: def get_credentials_for_url(self, url: str) -> Tuple[Optional[str], Optional[str]]: parsed_url = urllib.parse.urlsplit(url) - netloc = parsed_url.netloc + netloc = parsed_url.netloc + parsed_url.path credentials = self._credentials.get(netloc, (None, None)) @@ -148,7 +148,7 @@ def _get_http_auth( parsed_url = urllib.parse.urlsplit(url) - if netloc is None or netloc == parsed_url.netloc: + if netloc is None or netloc.startswith(parsed_url.netloc + parsed_url.path): auth = self._password_manager.get_http_auth(name) if auth is None or auth["password"] is None: diff --git a/tests/utils/test_authenticator.py b/tests/utils/test_authenticator.py index cf41f4f6a87..63cab167ac1 100644 --- a/tests/utils/test_authenticator.py +++ b/tests/utils/test_authenticator.py @@ -69,7 +69,7 @@ def test_authenticator_uses_credentials_from_config_if_not_provided( ) authenticator = Authenticator(config, NullIO()) - authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz") + authenticator.request("get", "https://foo.bar/simple/files/foo-0.1.0.tar.gz") request = http.last_request() @@ -90,7 +90,7 @@ def test_authenticator_uses_username_only_credentials( ) authenticator = Authenticator(config, NullIO()) - authenticator.request("get", "https://foo001@foo.bar/files/foo-0.1.0.tar.gz") + authenticator.request("get", "https://foo001@foo.bar/simple/files/foo-0.1.0.tar.gz") request = http.last_request() @@ -108,7 +108,9 @@ def test_authenticator_uses_password_only_credentials( ) authenticator = Authenticator(config, NullIO()) - authenticator.request("get", "https://:bar002@foo.bar/files/foo-0.1.0.tar.gz") + authenticator.request( + "get", "https://:bar002@foo.bar/simple/files/foo-0.1.0.tar.gz" + ) request = http.last_request() @@ -129,7 +131,7 @@ def test_authenticator_uses_empty_strings_as_default_password( ) authenticator = Authenticator(config, NullIO()) - authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz") + authenticator.request("get", "https://foo.bar/simple/files/foo-0.1.0.tar.gz") request = http.last_request() @@ -147,7 +149,7 @@ def test_authenticator_uses_empty_strings_as_default_username( ) authenticator = Authenticator(config, NullIO()) - authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz") + authenticator.request("get", "https://foo.bar/simple/files/foo-0.1.0.tar.gz") request = http.last_request() @@ -172,7 +174,7 @@ def test_authenticator_falls_back_to_keyring_url( ) authenticator = Authenticator(config, NullIO()) - authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz") + authenticator.request("get", "https://foo.bar/simple/files/foo-0.1.0.tar.gz") request = http.last_request() @@ -195,7 +197,7 @@ def test_authenticator_falls_back_to_keyring_netloc( dummy_keyring.set_password("foo.bar", None, SimpleCredential(None, "bar")) authenticator = Authenticator(config, NullIO()) - authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz") + authenticator.request("get", "https://foo.bar/simple/files/foo-0.1.0.tar.gz") request = http.last_request() @@ -303,7 +305,7 @@ def test_authenticator_uses_env_provided_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") + authenticator.request("get", "https://foo.bar/simple/files/foo-0.1.0.tar.gz") request = http.last_request()