Skip to content

Commit 3046d7e

Browse files
add integration test to App Protect agent file (#8116)
1 parent 216dbb0 commit 3046d7e

File tree

4 files changed

+102
-32
lines changed

4 files changed

+102
-32
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# /etc/nginx-agent/nginx-agent.conf
3+
#
4+
# Configuration file for NGINX Agent.
5+
#
6+
# This file is to track NGINX Agent configuration values that are meant to be statically set. There
7+
# are additional NGINX Agent configuration values that are set via the API and NGINX Agent install script
8+
# which can be found in /var/lib/nginx-agent/agent-dynamic.conf.
9+
10+
log:
11+
# set log level (panic, fatal, error, info, debug, trace; default "info")
12+
level: info
13+
# set log path. if empty, don't log to file.
14+
path: /var/log/nginx-agent/
15+
# data plane status message / 'heartbeat'
16+
nginx:
17+
# path of NGINX logs to exclude
18+
exclude_logs: ""
19+
socket: "unix:/var/run/nginx-agent/nginx.sock"
20+
21+
dataplane:
22+
status:
23+
# poll interval for data plane status - the frequency the NGINX Agent will query the dataplane for changes
24+
poll_interval: 30s
25+
# report interval for data plane status - the maximum duration to wait before syncing dataplane information if no updates have being observed
26+
report_interval: 24h
27+
28+
metrics:
29+
# specify the size of a buffer to build before sending metrics
30+
bulk_size: 20
31+
# specify metrics poll interval
32+
report_interval: 1m
33+
collection_interval: 15s
34+
mode: aggregated
35+
36+
# OSS NGINX default config path
37+
# path to aux file dirs can also be added
38+
config_dirs: "/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules:/etc/nms"
39+
40+
# api:
41+
# The port at which NGINX Agent accepts remote connections
42+
# The API address and port allow for remote management of NGINX and NGINX Agent
43+
#
44+
# ~~~ WARNING ~~~
45+
# Set API address to allow remote management
46+
# host: 127.0.0.1
47+
#
48+
# Set this value to a secure port number to prevent information leaks.
49+
# port: 8038

tests/data/agent/agent-v3.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# /etc/nginx-agent/nginx-agent.conf
3+
#
4+
# Configuration file for NGINX Agent.
5+
#
6+
7+
log:
8+
# set log level (error, warn, info, debug; default "info")
9+
level: info
10+
# set log path. if empty, don't log to file.
11+
path: /var/log/nginx-agent/
12+
13+
allowed_directories:
14+
- /etc/nginx
15+
- /usr/local/etc/nginx
16+
- /usr/share/nginx/modules
17+
- /var/run/nginx
18+
- /var/log/nginx
19+
#
20+
# Command server settings to connect to a management plane server
21+
#
22+
#command:
23+
# server:
24+
# host: "agent.connect.nginx.com"
25+
# port: 443
26+
# auth:
27+
# token: ""
28+
# tls:
29+
# skip_verify: false

tests/suite/test_agent.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from kubernetes.stream import stream
3+
from settings import TEST_DATA
34
from suite.utils.resources_utils import get_file_contents, get_first_pod_name, wait_before_test
45

56

@@ -47,37 +48,9 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro
4748
assert "nginx-agent version v3" in result_conf
4849

4950
# Test for agent.config file - verify the agent config exists inside the NIC pod
50-
# The expected config that will be asserted against later
51-
expected_config = """#
52-
# /etc/nginx-agent/nginx-agent.conf
53-
#
54-
# Configuration file for NGINX Agent.
55-
#
56-
57-
log:
58-
# set log level (error, warn, info, debug; default "info")
59-
level: info
60-
# set log path. if empty, don't log to file.
61-
path: /var/log/nginx-agent/
62-
63-
allowed_directories:
64-
- /etc/nginx
65-
- /usr/local/etc/nginx
66-
- /usr/share/nginx/modules
67-
- /var/run/nginx
68-
- /var/log/nginx
69-
#
70-
# Command server settings to connect to a management plane server
71-
#
72-
#command:
73-
# server:
74-
# host: "agent.connect.nginx.com"
75-
# port: 443
76-
# auth:
77-
# token: ""
78-
# tls:
79-
# skip_verify: false"""
80-
expected_config = expected_config.strip()
51+
# Read expected config from test data file (agentv3 configuration)
52+
with open(f"{TEST_DATA}/agent/agent-v3.conf") as f:
53+
expected_config = f.read().strip()
8154

8255
# Get the actual config file content from the pod
8356
config_contents = get_file_contents(

tests/suite/test_app_protect_agent.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from kubernetes.stream import stream
3-
from suite.utils.resources_utils import get_first_pod_name, wait_before_test
3+
from settings import TEST_DATA
4+
from suite.utils.resources_utils import get_file_contents, get_first_pod_name, wait_before_test
45

56

67
@pytest.mark.skip_for_nginx_oss
@@ -48,3 +49,21 @@ def test_ap_agent(self, kube_apis, ingress_controller_prerequisites, crd_ingress
4849

4950
assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log
5051
assert "nginx-agent version v2" in result_conf
52+
53+
# Integration test for agent config file - verify the agent config exists inside the NIC pod
54+
# Read expected config from test data file (agentv2 with AppProtect configuration)
55+
with open(f"{TEST_DATA}/agent/agent-v2-appprotect.conf") as f:
56+
expected_config = f.read().strip()
57+
58+
# Get the actual config file content from the pod
59+
config_contents = get_file_contents(
60+
kube_apis.v1, "/etc/nginx-agent/nginx-agent.conf", pod_name, ingress_controller_prerequisites.namespace
61+
)
62+
63+
# Normalize whitespace for comparison - remove trailing spaces from each line
64+
def normalize_config(config_text):
65+
return "\n".join(line.rstrip() for line in config_text.strip().split("\n"))
66+
67+
config_contents_normalized = normalize_config(config_contents)
68+
expected_config_normalized = normalize_config(expected_config)
69+
assert config_contents_normalized == expected_config_normalized

0 commit comments

Comments
 (0)