From 66f87e3cea498cf3eada4fdee768b181dd51672d Mon Sep 17 00:00:00 2001 From: Bernhard Suttner Date: Tue, 24 Sep 2024 19:07:22 +0200 Subject: [PATCH] Fix URL encoding issue in pulp_file closes #5686 --- CHANGES/5686.txt | 1 + pulp_file/app/tasks/synchronizing.py | 4 ++-- pulp_file/pytest_plugin.py | 10 ++++++++++ pulp_file/tests/functional/api/test_sync.py | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 CHANGES/5686.txt diff --git a/CHANGES/5686.txt b/CHANGES/5686.txt new file mode 100644 index 0000000000..79829e8747 --- /dev/null +++ b/CHANGES/5686.txt @@ -0,0 +1 @@ +Quote the URL path of pulp_file files. diff --git a/pulp_file/app/tasks/synchronizing.py b/pulp_file/app/tasks/synchronizing.py index e7eaca0a23..a6af0e6a7a 100644 --- a/pulp_file/app/tasks/synchronizing.py +++ b/pulp_file/app/tasks/synchronizing.py @@ -2,7 +2,7 @@ import os from gettext import gettext as _ -from urllib.parse import urlparse, urlunparse +from urllib.parse import quote, urlparse, urlunparse from django.core.files import File @@ -114,7 +114,7 @@ async def run(self): for entry in entries: path = os.path.join(root_dir, entry.relative_path) - url = urlunparse(parsed_url._replace(path=path)) + url = urlunparse(parsed_url._replace(path=quote(path, safe=":/"))) file = FileContent(relative_path=entry.relative_path, digest=entry.digest) artifact = Artifact(size=entry.size, sha256=entry.digest) da = DeclarativeArtifact( diff --git a/pulp_file/pytest_plugin.py b/pulp_file/pytest_plugin.py index 92f2c159e1..50a9428465 100644 --- a/pulp_file/pytest_plugin.py +++ b/pulp_file/pytest_plugin.py @@ -101,6 +101,16 @@ def basic_manifest_path(write_3_iso_file_fixture_data_factory): return write_3_iso_file_fixture_data_factory("basic") +@pytest.fixture +def encoded_manifest_path(file_fixtures_root): + file_fixtures_root.joinpath("encoded").mkdir() + file1 = generate_iso(file_fixtures_root.joinpath("encoded/long-name-%253a-encoded.iso")) + file2 = generate_iso(file_fixtures_root.joinpath("encoded/another-%25-encoded.iso")) + file3 = generate_iso(file_fixtures_root.joinpath("encoded/more-%3C-encoded.iso")) + generate_manifest(file_fixtures_root.joinpath("encoded/PULP_MANIFEST"), [file1, file2, file3]) + return "/encoded/PULP_MANIFEST" + + @pytest.fixture def copy_manifest_only_factory(file_fixtures_root): def _copy_manifest_only(name): diff --git a/pulp_file/tests/functional/api/test_sync.py b/pulp_file/tests/functional/api/test_sync.py index 37e255da68..aab0d0b285 100644 --- a/pulp_file/tests/functional/api/test_sync.py +++ b/pulp_file/tests/functional/api/test_sync.py @@ -123,6 +123,21 @@ def test_duplicate_file_sync( assert file_repo.latest_version_href.endswith("/2/") +@pytest.mark.parallel +def test_encoded_file_name( + file_repo, file_bindings, encoded_manifest_path, file_remote_factory, monitor_task +): + remote = file_remote_factory(manifest_path=encoded_manifest_path, policy="immediate") + body = RepositorySyncURL(remote=remote.pulp_href) + monitor_task(file_bindings.RepositoriesFileApi.sync(file_repo.pulp_href, body).task) + file_repo = file_bindings.RepositoriesFileApi.read(file_repo.pulp_href) + + version = file_bindings.RepositoriesFileVersionsApi.read(file_repo.latest_version_href) + assert version.content_summary.present["file.file"]["count"] == 3 + assert version.content_summary.added["file.file"]["count"] == 3 + assert file_repo.latest_version_href.endswith("/1/") + + @pytest.mark.parallel def test_filepath_includes_commas( file_bindings,