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: remove credentials from response URLs #600

Merged
merged 1 commit into from
Feb 10, 2024
Merged
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
2 changes: 2 additions & 0 deletions conda_lock/pypi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ def get_requirements(
# https://github.com/conda/conda-lock/blob/ac31f5ddf2951ed4819295238ccf062fb2beb33c/conda_lock/_vendor/poetry/installation/executor.py#L557
else:
link = chooser.choose_for(op.package)
parsed_url = urlsplit(link.url)
link.url = link.url.replace(parsed_url.netloc, str(parsed_url.hostname))
url = link.url_without_fragment
hashes: Dict[str, str] = {}
if link.hash_name is not None and link.hash is not None:
Expand Down
13 changes: 10 additions & 3 deletions tests/test_pip_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ def private_package_tar():
os.remove(tar_path)


@pytest.fixture(autouse=True)
def mock_private_pypi(private_package_tar: Path):
@pytest.fixture(
autouse=True,
params=["response_url_without_credentials", "response_url_with_credentials"],
)
def mock_private_pypi(private_package_tar: Path, request: pytest.FixtureRequest):
with requests_mock.Mocker(real_http=True) as mocker:
fixture_request = request

def _make_response(
request: requests.Request,
Expand Down Expand Up @@ -84,7 +88,10 @@ def _make_response(
response.raw.seek(0)

url = urlparse(request.url)
response.url = request.url.replace(url.netloc, url.hostname)
if fixture_request.param == "response_url_with_credentials":
response.url = request.url
else:
response.url = request.url.replace(url.netloc, url.hostname)
response.reason = reason
return response

Expand Down
Loading