From 29b7d3393f45e0fce6c8d3d5ac3f278e4822e32e Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Thu, 27 Jan 2022 12:53:34 +0000 Subject: [PATCH] Adding proxy tests [noissue] (cherry picked from commit 750e8b019ebf0be1400822a26ac9dab178654b60) --- .github/workflows/scripts/install.sh | 3 ++ .github/workflows/scripts/script.sh | 3 ++ .../functional/api/collection/v3/test_sync.py | 48 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/.github/workflows/scripts/install.sh b/.github/workflows/scripts/install.sh index 9985ee57e..9fece8bd1 100755 --- a/.github/workflows/scripts/install.sh +++ b/.github/workflows/scripts/install.sh @@ -75,6 +75,9 @@ services: image: "pulp:${TAG}" volumes: - ./settings:/etc/pulp + - name: ciproxy + image: ghcr.io/abhinavsingh/proxy.py:latest + command: "--basic-auth foo:bar --hostname 0.0.0.0" VARSYAML fi diff --git a/.github/workflows/scripts/script.sh b/.github/workflows/scripts/script.sh index 7bc816f00..669502667 100755 --- a/.github/workflows/scripts/script.sh +++ b/.github/workflows/scripts/script.sh @@ -160,6 +160,9 @@ if [[ "$TEST" == "performance" ]]; then exit fi +# Enable proxy.py +export PULP_PROXY_TEST=enabled + if [ -f $FUNC_TEST_SCRIPT ]; then source $FUNC_TEST_SCRIPT else diff --git a/pulp_ansible/tests/functional/api/collection/v3/test_sync.py b/pulp_ansible/tests/functional/api/collection/v3/test_sync.py index b61b32402..6f8b12b17 100644 --- a/pulp_ansible/tests/functional/api/collection/v3/test_sync.py +++ b/pulp_ansible/tests/functional/api/collection/v3/test_sync.py @@ -203,6 +203,54 @@ def test_sync_with_missing_collection(self): msg = "absent.not_present does not exist" self.assertIn(msg, task_result["error"]["description"], task_result["error"]["description"]) + def test_sync_with_proxy_auth(self): + """Test sync collections from pulp server.""" + if not os.getenv("PULP_PROXY_TEST"): + self.skipTest("Proxy isn't set.") + + second_body = gen_ansible_remote( + url=self.distribution.client_url, + requirements_file=self.requirements_file, + sync_dependencies=False, + proxy_url="http://ciproxy:8899", + proxy_username="foo", + proxy_password="bar", + ) + second_remote = self.remote_collection_api.create(second_body) + self.addCleanup(self.remote_collection_api.delete, second_remote.pulp_href) + + second_repo = self._create_repo_and_sync_with_remote(second_remote) + + first_content = self.cv_api.list( + repository_version=f"{self.first_repo.pulp_href}versions/1/" + ) + self.assertGreaterEqual(len(first_content.results), 1) + second_content = self.cv_api.list(repository_version=f"{second_repo.pulp_href}versions/1/") + self.assertGreaterEqual(len(second_content.results), 1) + + def test_sync_with_proxy_auth_without_credentials(self): + """Test sync collections from pulp server.""" + if not os.getenv("PULP_PROXY_TEST"): + self.skipTest("Proxy isn't set.") + + second_body = gen_ansible_remote( + url=self.distribution.client_url, + requirements_file=self.requirements_file, + sync_dependencies=False, + proxy_url="http://ciproxy:8899", + ) + second_remote = self.remote_collection_api.create(second_body) + self.addCleanup(self.remote_collection_api.delete, second_remote.pulp_href) + + with self.assertRaises(PulpTaskError) as ctx: + self._create_repo_and_sync_with_remote(second_remote) + + task_result = ctx.exception.task.to_dict() + msg = "407, message='Proxy Authentication Required', url=URL(" "'http://ciproxy:8899')" + self.assertEqual( + msg, task_result["error"]["description"], task_result["error"]["description"] + ) + @unittest.skipUnless( "AUTOMATION_HUB_TOKEN_AUTH" in os.environ,