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

Add test for wrong on_demand serving #3715

Closed
wants to merge 1 commit into from
Closed
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
85 changes: 85 additions & 0 deletions pulp_rpm/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import pytest
from random import choice
import createrepo_c as cr
from urllib.parse import urljoin
import os
import shutil
import hashlib

import dictdiffer
import requests
Expand Down Expand Up @@ -1145,3 +1150,83 @@ def test_config_repo_mirror_sync(
assert bytes(f"baseurl={distribution.base_url}\n", "utf-8") in content
assert bytes("gpgcheck=1\n", "utf-8") in content
assert bytes("repo_gpgcheck=0", "utf-8") in content


@pytest.mark.parametrize("repeat", range(5))
def test_remote_content_change(
tmpdir,
rpm_repository_api,
monitor_task,
init_and_sync,
rpm_repository_factory,
delete_orphans_pre,
rpm_distribution_factory,
repeat,
):
assert rpm_repository_api.list().count == 0
policy = "on_demand"
sync_policy = "mirror_content_only"

pkg_name = "giraffe-0.67-2.noarch.rpm"
ext_repo_foo = f"{tmpdir}/repo_foo"
ext_repo_bar = f"{tmpdir}/repo_bar"
download_dir = f"{tmpdir}/download_dir"
os.mkdir(ext_repo_foo)
os.mkdir(ext_repo_bar)
os.mkdir(download_dir)

signed_url = urljoin(RPM_SIGNED_FIXTURE_URL, pkg_name)
unsigned_url = urljoin(RPM_UNSIGNED_FIXTURE_URL, pkg_name)
wget_download_on_host(signed_url, download_dir) # to download_dir/rpm-signed/{pkg-name}
wget_download_on_host(unsigned_url, download_dir) # to download_dir/rpm-unsigned/{pkg-name}

# Create initial external repositories and sync with Pulp
# - Both contain the signed version of the package
for repo in (ext_repo_foo, ext_repo_bar):
shutil.copy(f"{download_dir}/rpm-signed/{pkg_name}", repo)
with cr.RepositoryWriter(repo) as writer:
writer.set_num_of_pkgs(1)
writer.add_pkg_from_file(f"{repo}/{pkg_name}")

repo_foo = rpm_repository_factory(autopublish=True)
repo_bar = rpm_repository_factory(autopublish=True)
dist_foo = rpm_distribution_factory(repository=repo_foo.pulp_href)
dist_bar = rpm_distribution_factory(repository=repo_bar.pulp_href)
_, remote_foo = init_and_sync(
url=f"file://{ext_repo_foo}/", repository=repo_foo, policy=policy, sync_policy=sync_policy
)
_, remote_bar = init_and_sync(
url=f"file://{ext_repo_bar}/", repository=repo_bar, policy=policy, sync_policy=sync_policy
)

# Modify external repository content (ext_repo_bar)
# - Replace signed with unsigned
# - Regenerate repository with createrepo
# - Resync repo_bar
shutil.rmtree(ext_repo_bar)
os.mkdir(ext_repo_bar)
shutil.copy(f"{download_dir}/rpm-unsigned/{pkg_name}", ext_repo_bar)
with cr.RepositoryWriter(ext_repo_bar) as writer:
writer.set_num_of_pkgs(1)
writer.add_pkg_from_file(f"{ext_repo_bar}/{pkg_name}")
repository_sync_data = RpmRepositorySyncURL(
remote=remote_bar.pulp_href,
sync_policy=sync_policy,
)
sync_response = rpm_repository_api.sync(repo_bar.pulp_href, repository_sync_data)
monitor_task(sync_response.task)

# Verify we get the expected package checksums
with open(f"{download_dir}/rpm-signed/{pkg_name}", "rb") as fd:
signed_sha256 = hashlib.sha256(fd.read()).hexdigest()
with open(f"{download_dir}/rpm-unsigned/{pkg_name}", "rb") as fd:
unsigned_sha256 = hashlib.sha256(fd.read()).hexdigest()
pkg_digest_from_foo = hashlib.sha256(
requests.get(dist_foo.base_url + f"/Packages/g/{pkg_name}").content
).hexdigest()
pkg_digest_from_bar = hashlib.sha256(
requests.get(dist_bar.base_url + f"/Packages/g/{pkg_name}").content
).hexdigest()

assert pkg_digest_from_foo == signed_sha256
assert pkg_digest_from_bar == unsigned_sha256
Loading