Skip to content

Commit

Permalink
Quote-encode backfill URLs (#15503)
Browse files Browse the repository at this point in the history
  • Loading branch information
di authored Feb 28, 2024
1 parent 6c84303 commit f87e97d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 23 additions & 3 deletions tests/unit/packaging/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,24 @@ def test_metadata_backfill(db_request, monkeypatch, metrics):
]


def test_metadata_backfill_individual(db_request, monkeypatch, metrics):
@pytest.mark.parametrize(
"path, requested_path",
[
# Regular path
(
"8a/6a/19...3b/pip-24.0-py3-none-any.whl",
"8a/6a/19...3b/pip-24.0-py3-none-any.whl",
),
# Path with characters that need quoted
(
"da/5d/cc...0d/scalg-0.1.1#-py3-none-any.whl",
"da/5d/cc...0d/scalg-0.1.1%23-py3-none-any.whl",
),
],
)
def test_metadata_backfill_individual(
db_request, monkeypatch, metrics, path, requested_path
):
project = ProjectFactory()
release1 = ReleaseFactory(project=project)
release2 = ReleaseFactory(project=project)
Expand All @@ -942,7 +959,10 @@ def test_metadata_backfill_individual(db_request, monkeypatch, metrics):
)
FileFactory(release=release2, packagetype="sdist")
backfillable_file = FileFactory(
release=release2, packagetype="bdist_wheel", metadata_file_sha256_digest=None
release=release2,
packagetype="bdist_wheel",
metadata_file_sha256_digest=None,
path=path,
)

metadata_contents = b"some\nmetadata\ncontents"
Expand Down Expand Up @@ -996,7 +1016,7 @@ def mock_open(filename, perms):
assert dist_from_wheel_url.calls == [
pretend.call(
project.normalized_name,
f"https://files.example.com/packages/{backfillable_file.path}",
f"https://files.example.com/packages/{requested_path}",
stub_session,
)
]
Expand Down
3 changes: 2 additions & 1 deletion warehouse/packaging/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
import os
import tempfile
import urllib.parse

from collections import namedtuple
from itertools import product
Expand Down Expand Up @@ -95,7 +96,7 @@ def metadata_backfill_individual(request, file_id):
return

base_url = request.registry.settings.get("files.url")
file_url = base_url.format(path=file_.path)
file_url = urllib.parse.quote(base_url.format(path=file_.path), safe=":/")
metrics = request.find_service(IMetricsService, context=None)
cache_storage = request.find_service(IFileStorage, name="cache")
archive_storage = request.find_service(IFileStorage, name="archive")
Expand Down

0 comments on commit f87e97d

Please sign in to comment.