1import pytest
2
3from tests.utils import (
4 SUPPORTED_ENVOY_VERSIONS,
5 econf_compile,
6 econf_foreach_hcm,
7 module_and_mapping_manifests,
8)
9
10
11def _test_hcm(yaml, expectations={}):
12 for v in SUPPORTED_ENVOY_VERSIONS:
13 # Compile an envoy config
14 econf = econf_compile(yaml, envoy_version=v)
15
16 # Make sure expectations pass for each HCM in the compiled config
17 def check(typed_config):
18 for key, expected in expectations.items():
19 if expected is None:
20 assert key not in typed_config
21 else:
22 assert key in typed_config
23 assert typed_config[key] == expected
24 return True
25
26 econf_foreach_hcm(econf, check, envoy_version=v)
27
28
29@pytest.mark.compilertest
30def test_strip_matching_host_port_missing():
31 # If we do not set the config, it should be missing (noted in this test as None).
32 yaml = module_and_mapping_manifests(None, [])
33 _test_hcm(yaml, expectations={"strip_matching_host_port": None})
34
35
36@pytest.mark.compilertest
37def test_strip_matching_host_port_module_false():
38 # If we set the config to false, it should be missing (noted in this test as None).
39 yaml = module_and_mapping_manifests(["strip_matching_host_port: false"], [])
40 _test_hcm(yaml, expectations={"strip_matching_host_port": None})
41
42
43@pytest.mark.compilertest
44def test_strip_matching_host_port_module_true():
45 # If we set the config to true, it should show up as true.
46 yaml = module_and_mapping_manifests(["strip_matching_host_port: true"], [])
47 _test_hcm(yaml, expectations={"strip_matching_host_port": True})
48
49
50@pytest.mark.compilertest
51def test_merge_slashes_missing():
52 # If we do not set the config, it should be missing (noted in this test as None).
53 yaml = module_and_mapping_manifests(None, [])
54 _test_hcm(yaml, expectations={"merge_slashes": None})
55
56
57@pytest.mark.compilertest
58def test_merge_slashes_module_false():
59 # If we set the config to false, it should be missing (noted in this test as None).
60 yaml = module_and_mapping_manifests(["merge_slashes: false"], [])
61 _test_hcm(yaml, expectations={"merge_slashes": None})
62
63
64@pytest.mark.compilertest
65def test_merge_slashes_module_true():
66 # If we set the config to true, it should show up as true.
67 yaml = module_and_mapping_manifests(["merge_slashes: true"], [])
68 _test_hcm(yaml, expectations={"merge_slashes": True})
69
70
71@pytest.mark.compilertest
72def test_reject_requests_with_escaped_slashes_missing():
73 # If we set the config to false, the action should be missing.
74 yaml = module_and_mapping_manifests(None, [])
75 _test_hcm(yaml, expectations={"path_with_escaped_slashes_action": None})
76
77
78@pytest.mark.compilertest
79def test_reject_requests_with_escaped_slashes_false():
80 # If we set the config to false, the action should be missing.
81 yaml = module_and_mapping_manifests(["reject_requests_with_escaped_slashes: false"], [])
82 _test_hcm(yaml, expectations={"path_with_escaped_slashes_action": None})
83
84
85@pytest.mark.compilertest
86def test_reject_requests_with_escaped_slashes_true():
87 # If we set the config to true, the action should show up as "REJECT_REQUEST".
88 yaml = module_and_mapping_manifests(["reject_requests_with_escaped_slashes: true"], [])
89 _test_hcm(yaml, expectations={"path_with_escaped_slashes_action": "REJECT_REQUEST"})
90
91
92@pytest.mark.compilertest
93def test_preserve_external_request_id_missing():
94 # If we do not set the config, it should be false
95 yaml = module_and_mapping_manifests(None, [])
96 _test_hcm(yaml, expectations={"preserve_external_request_id": False})
97
98
99@pytest.mark.compilertest
100def test_preserve_external_request_id_module_false():
101 # If we set the config to false, it should be false
102 yaml = module_and_mapping_manifests(["preserve_external_request_id: false"], [])
103 _test_hcm(yaml, expectations={"preserve_external_request_id": False})
104
105
106@pytest.mark.compilertest
107def test_preserve_external_request_id_module_true():
108 # If we set the config to true, it should show up as true.
109 yaml = module_and_mapping_manifests(["preserve_external_request_id: true"], [])
110 _test_hcm(yaml, expectations={"preserve_external_request_id": True})
View as plain text