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

fix: support multiple repositories with the same domain and different creds #5108

Closed
Closed
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/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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:
Expand Down
18 changes: 10 additions & 8 deletions tests/utils/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand Down