From b44cca82f7bbfb79a3f818a8b90c2ee7d274d421 Mon Sep 17 00:00:00 2001 From: Venktesh Date: Wed, 31 Jul 2024 17:42:18 +0100 Subject: [PATCH] add agent test --- .github/data/matrix-smoke.json | 8 +++++ pyproject.toml | 1 + tests/suite/test_agent_app_protect.py | 50 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/suite/test_agent_app_protect.py diff --git a/.github/data/matrix-smoke.json b/.github/data/matrix-smoke.json index 6d7ab6ec4d..f327f7de32 100644 --- a/.github/data/matrix-smoke.json +++ b/.github/data/matrix-smoke.json @@ -173,6 +173,14 @@ "nap_modules": "dos", "marker": "dos_learning", "platforms": "linux/amd64" + }, + { + "label": "AGENT 1/1", + "image": "debian-plus-nap", + "type": "plus", + "nap_modules": "waf", + "marker": "agent", + "platforms": "linux/amd64" } ], "k8s": [] diff --git a/pyproject.toml b/pyproject.toml index 2888295493..e40704ea52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ pythonpath = [ addopts = "--tb=native -ra --disable-warnings -x -l --profile -v" log_cli = true markers =[ + "agent", "appprotect", "appprotect_integration", "appprotect_waf_policies", diff --git a/tests/suite/test_agent_app_protect.py b/tests/suite/test_agent_app_protect.py new file mode 100644 index 0000000000..ab881b90c2 --- /dev/null +++ b/tests/suite/test_agent_app_protect.py @@ -0,0 +1,50 @@ +import pytest +from kubernetes.stream import stream +from suite.utils.resources_utils import get_first_pod_name, wait_before_test + + +@pytest.mark.skip_for_nginx_oss +@pytest.mark.agent +@pytest.mark.parametrize( + "crd_ingress_controller_with_ap", + [ + { + "extra_args": [ + "-enable-app-protect", + "-agent=true", + "-agent-instance-group=test-ic", + ] + } + ], + indirect=["crd_ingress_controller_with_ap"], +) +class TestAppProtectAgent: + def test_ap_agent(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller_with_ap): + pod_name = get_first_pod_name(kube_apis.v1, "nginx-ingress") + log = kube_apis.v1.read_namespaced_pod_log(pod_name, ingress_controller_prerequisites.namespace) + + command = ["/usr/bin/nginx-agent", "-v"] + retries = 0 + while retries <= 3: + wait_before_test() + try: + resp = stream( + kube_apis.v1.connect_get_namespaced_pod_exec, + pod_name, + ingress_controller_prerequisites.namespace, + command=command, + stderr=True, + stdin=False, + stdout=True, + tty=False, + ) + break + except Exception as e: + print(f"Error: {e}") + retries += 1 + if retries == 3: + raise e + result_conf = str(resp) + + assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log + assert "nginx-agent version " in result_conf