diff --git a/test_env_vars.yaml b/test_env_vars.yaml index 8e95aba99..e0d911345 100755 --- a/test_env_vars.yaml +++ b/test_env_vars.yaml @@ -248,3 +248,7 @@ various_packages: repo: https://github.com/cachito-testing/cachito-gomod-test ref: 1827221d787cbd1e979b339cfbbf59728eddf0d4 dependencies_count: 49 +# test repo user +git_user: "Arthur Dent" +# test repo user email +git_email: "dent42@cachito.rocks" diff --git a/tests/integration/test_data/private_repo_packages.yaml b/tests/integration/test_data/private_repo_packages.yaml index 272023850..a50b202c9 100644 --- a/tests/integration/test_data/private_repo_packages.yaml +++ b/tests/integration/test_data/private_repo_packages.yaml @@ -1,11 +1,10 @@ # Test data for the private repos test # The test will only be performed if $JOB_NAME includes one of the following + private_repo_test_envs: - cachito-prod - cachito-stage private_repo_https: repo: https://github.com/cachito-testing/cachito-no-package-manager-private.git - ref: 31e242befe367f940f878f27158d9cd036ba3b23 private_repo_ssh: repo: git@github.com:cachito-testing/cachito-no-package-manager-private.git - ref: 31e242befe367f940f878f27158d9cd036ba3b23 diff --git a/tests/integration/test_private_repos.py b/tests/integration/test_private_repos.py index 0286f9e24..e2f4dfb0e 100644 --- a/tests/integration/test_private_repos.py +++ b/tests/integration/test_private_repos.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later import os +import random +import string from pathlib import Path from typing import Any @@ -16,6 +18,9 @@ def test_private_repos(env_package: str, test_env: dict[str, Any], tmp_path: Pat Validate a cachito request with no package managers to a private repo. Process: + Create new commit at "cachito-no-package-manager-private" repo + (To prevent cachito from caching private source code and serving + it without trying to access the repository, more info: STONEBLD-661) Send new request to the Cachito API Send request to check status of existing request @@ -31,7 +36,8 @@ def test_private_repos(env_package: str, test_env: dict[str, Any], tmp_path: Pat test_data = utils.load_test_data("private_repo_packages.yaml") private_repo_test_envs = test_data["private_repo_test_envs"] env_data = test_data[env_package] - is_supported_env = any(x in str(os.environ.get("JOB_NAME")) for x in private_repo_test_envs) + job_name = str(os.environ.get("JOB_NAME")) + is_supported_env = any(x in job_name for x in private_repo_test_envs) if not is_supported_env: pytest.skip( ( @@ -41,26 +47,50 @@ def test_private_repos(env_package: str, test_env: dict[str, Any], tmp_path: Pat ) ) - client = utils.Client(test_env["api_url"], test_env["api_auth_type"], test_env.get("timeout")) - payload = { - "repo": env_data["repo"], - "ref": env_data["ref"], - "pkg_managers": [], - "flags": ["include-git-dir"], - } - - initial_response = client.create_new_request(payload=payload) - completed_response = client.wait_for_complete_request(initial_response) - - utils.assert_properly_completed_response(completed_response) - assert completed_response.data["packages"] == [] - assert completed_response.data["dependencies"] == [] - - client.download_and_extract_archive(completed_response.id, tmp_path) - source_path = tmp_path / f"download_{str(completed_response.id)}" - repo = Repo(source_path / "app") - assert repo.head.commit.hexsha == env_data["ref"] - assert not repo.git.diff() - assert not os.listdir(source_path / "deps") - - utils.assert_content_manifest(client, completed_response.id, []) + repo = Repo.clone_from(test_data["private_repo_ssh"]["repo"], tmp_path) + + repo.config_writer().set_value("user", "name", test_env["git_user"]).release() + repo.config_writer().set_value("user", "email", test_env["git_email"]).release() + + generated_suffix = "".join( + random.choice(string.ascii_letters + string.digits) for x in range(10) + ) + branch_name = f"tmp-branch-{generated_suffix}" + + try: + repo.create_head(branch_name).checkout() + + message = "Committed by Cachito integration test (test_private_repos)" + repo.git.commit("--allow-empty", m=message) + repo.git.push("-u", "origin", branch_name) + + ref = repo.head.commit.hexsha + + client = utils.Client( + test_env["api_url"], test_env["api_auth_type"], test_env.get("timeout") + ) + payload = { + "repo": env_data["repo"], + "ref": ref, + "pkg_managers": [], + "flags": ["include-git-dir"], + } + + initial_response = client.create_new_request(payload=payload) + completed_response = client.wait_for_complete_request(initial_response) + + utils.assert_properly_completed_response(completed_response) + assert completed_response.data["packages"] == [] + assert completed_response.data["dependencies"] == [] + + client.download_and_extract_archive(completed_response.id, tmp_path) + source_path = tmp_path / f"download_{str(completed_response.id)}" + downloaded_repo = Repo(source_path / "app") + assert downloaded_repo.head.commit.hexsha == ref + assert not downloaded_repo.git.diff() + assert not os.listdir(source_path / "deps") + + utils.assert_content_manifest(client, completed_response.id, []) + + finally: + repo.git.push("--delete", "origin", branch_name)