From e84ca427ce022dfa2fdad124bec623bc94469748 Mon Sep 17 00:00:00 2001 From: Michael Pleshakov Date: Mon, 6 Dec 2021 14:04:32 -0800 Subject: [PATCH] Extend rewrite URI tests for VS and VSRs - Combine the VS and VSR tests into a single one. - Extend the tests to cover the bug fix. --- tests/data/rewrites/hello.yaml | 32 +++++ .../data/rewrites/virtual-server-parent.yaml | 17 +++ .../data/rewrites/virtual-server-rewrite.yaml | 44 +++++++ .../virtual-server-route-prefixes.yaml | 34 +++++ .../rewrites/virtual-server-route-regex1.yaml | 16 +++ .../rewrites/virtual-server-route-regex2.yaml | 16 +++ .../standard/virtual-server.yaml | 20 --- .../virtual-server-rewrite-prefix.yaml | 25 ---- .../virtual-server-rewrite-regex.yaml | 24 ---- .../route-multiple-prefix-regex.yaml | 24 ---- .../route-single-prefix.yaml | 16 --- tests/suite/test_rewrites.py | 109 ++++++++++++++++ tests/suite/test_v_s_route_rewrites.py | 121 ------------------ tests/suite/test_virtual_server_rewrites.py | 95 -------------- 14 files changed, 268 insertions(+), 325 deletions(-) create mode 100644 tests/data/rewrites/hello.yaml create mode 100644 tests/data/rewrites/virtual-server-parent.yaml create mode 100644 tests/data/rewrites/virtual-server-rewrite.yaml create mode 100644 tests/data/rewrites/virtual-server-route-prefixes.yaml create mode 100644 tests/data/rewrites/virtual-server-route-regex1.yaml create mode 100644 tests/data/rewrites/virtual-server-route-regex2.yaml delete mode 100644 tests/data/virtual-server-rewrites/standard/virtual-server.yaml delete mode 100644 tests/data/virtual-server-rewrites/virtual-server-rewrite-prefix.yaml delete mode 100644 tests/data/virtual-server-rewrites/virtual-server-rewrite-regex.yaml delete mode 100644 tests/data/virtual-server-route-rewrites/route-multiple-prefix-regex.yaml delete mode 100644 tests/data/virtual-server-route-rewrites/route-single-prefix.yaml create mode 100644 tests/suite/test_rewrites.py delete mode 100644 tests/suite/test_v_s_route_rewrites.py delete mode 100644 tests/suite/test_virtual_server_rewrites.py diff --git a/tests/data/rewrites/hello.yaml b/tests/data/rewrites/hello.yaml new file mode 100644 index 0000000000..efe44af4b0 --- /dev/null +++ b/tests/data/rewrites/hello.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello +spec: + replicas: 1 + selector: + matchLabels: + app: hello + template: + metadata: + labels: + app: hello + spec: + containers: + - name: hello + image: nginxdemos/nginx-hello:plain-text + ports: + - containerPort: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: hello-svc +spec: + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + name: http + selector: + app: hello \ No newline at end of file diff --git a/tests/data/rewrites/virtual-server-parent.yaml b/tests/data/rewrites/virtual-server-parent.yaml new file mode 100644 index 0000000000..9f14fb971b --- /dev/null +++ b/tests/data/rewrites/virtual-server-parent.yaml @@ -0,0 +1,17 @@ +apiVersion: k8s.nginx.org/v1 +kind: VirtualServer +metadata: + name: rewrite-parent +spec: + host: vsr.example.com + upstreams: + - name: hello + service: hello-svc + port: 80 + routes: + - path: / + route: prefixes + - path: ~ /regex1/?(.*) + route: regex-1 + - path: ~ /regex2/?(.*) + route: regex-2 \ No newline at end of file diff --git a/tests/data/rewrites/virtual-server-rewrite.yaml b/tests/data/rewrites/virtual-server-rewrite.yaml new file mode 100644 index 0000000000..ea274c19f7 --- /dev/null +++ b/tests/data/rewrites/virtual-server-rewrite.yaml @@ -0,0 +1,44 @@ +apiVersion: k8s.nginx.org/v1 +kind: VirtualServer +metadata: + name: rewrite +spec: + host: vs.example.com + upstreams: + - name: hello + service: hello-svc + port: 80 + routes: + - path: /backend1/ + action: + proxy: + upstream: hello + rewritePath: / + - path: /backend2 + action: + proxy: + upstream: hello + rewritePath: /backend2_1 + - path: /match/ + matches: + - conditions: + - cookie: user + value: john + action: + proxy: + upstream: hello + rewritePath: /user/john/ + action: + proxy: + upstream: hello + rewritePath: / + - path: ~ /regex1/?(.*) + action: + proxy: + upstream: hello + rewritePath: /$1 + - path: ~ /regex2/?(.*) + action: + proxy: + upstream: hello + rewritePath: /$1 \ No newline at end of file diff --git a/tests/data/rewrites/virtual-server-route-prefixes.yaml b/tests/data/rewrites/virtual-server-route-prefixes.yaml new file mode 100644 index 0000000000..b545a73619 --- /dev/null +++ b/tests/data/rewrites/virtual-server-route-prefixes.yaml @@ -0,0 +1,34 @@ +apiVersion: k8s.nginx.org/v1 +kind: VirtualServerRoute +metadata: + name: prefixes +spec: + host: vsr.example.com + upstreams: + - name: hello + service: hello-svc + port: 80 + subroutes: + - path: /backend1/ + action: + proxy: + upstream: hello + rewritePath: / + - path: /backend2 + action: + proxy: + upstream: hello + rewritePath: /backend2_1 + - path: /match/ + matches: + - conditions: + - cookie: user + value: john + action: + proxy: + upstream: hello + rewritePath: /user/john/ + action: + proxy: + upstream: hello + rewritePath: / \ No newline at end of file diff --git a/tests/data/rewrites/virtual-server-route-regex1.yaml b/tests/data/rewrites/virtual-server-route-regex1.yaml new file mode 100644 index 0000000000..975f361f20 --- /dev/null +++ b/tests/data/rewrites/virtual-server-route-regex1.yaml @@ -0,0 +1,16 @@ +apiVersion: k8s.nginx.org/v1 +kind: VirtualServerRoute +metadata: + name: regex-1 +spec: + host: vsr.example.com + upstreams: + - name: hello + service: hello-svc + port: 80 + subroutes: + - path: ~ /regex1/?(.*) + action: + proxy: + upstream: hello + rewritePath: /$1 \ No newline at end of file diff --git a/tests/data/rewrites/virtual-server-route-regex2.yaml b/tests/data/rewrites/virtual-server-route-regex2.yaml new file mode 100644 index 0000000000..239402e0eb --- /dev/null +++ b/tests/data/rewrites/virtual-server-route-regex2.yaml @@ -0,0 +1,16 @@ +apiVersion: k8s.nginx.org/v1 +kind: VirtualServerRoute +metadata: + name: regex-2 +spec: + host: vsr.example.com + upstreams: + - name: hello + service: hello-svc + port: 80 + subroutes: + - path: ~ /regex2/?(.*) + action: + proxy: + upstream: hello + rewritePath: /$1 \ No newline at end of file diff --git a/tests/data/virtual-server-rewrites/standard/virtual-server.yaml b/tests/data/virtual-server-rewrites/standard/virtual-server.yaml deleted file mode 100644 index 971bac17b1..0000000000 --- a/tests/data/virtual-server-rewrites/standard/virtual-server.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: k8s.nginx.org/v1 -kind: VirtualServer -metadata: - name: virtual-server-status -spec: - host: virtual-server-status.example.com - upstreams: - - name: backend2 - service: backend2-svc - port: 80 - - name: backend1 - service: backend1-svc - port: 80 - routes: - - path: /backend1 - action: - pass: backend1 - - path: /backend2 - action: - pass: backend2 \ No newline at end of file diff --git a/tests/data/virtual-server-rewrites/virtual-server-rewrite-prefix.yaml b/tests/data/virtual-server-rewrites/virtual-server-rewrite-prefix.yaml deleted file mode 100644 index 47fbca0241..0000000000 --- a/tests/data/virtual-server-rewrites/virtual-server-rewrite-prefix.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: k8s.nginx.org/v1 -kind: VirtualServer -metadata: - name: virtual-server-status -spec: - host: virtual-server-status.example.com - upstreams: - - name: backend2 - service: backend2-svc - port: 80 - - name: backend1 - service: backend1-svc - port: 80 - routes: - - path: /backend1/ - action: - proxy: - upstream: backend1 - rewritePath: / - - path: /backend2 - action: - proxy: - upstream: backend2 - rewritePath: /backend2_1 - \ No newline at end of file diff --git a/tests/data/virtual-server-rewrites/virtual-server-rewrite-regex.yaml b/tests/data/virtual-server-rewrites/virtual-server-rewrite-regex.yaml deleted file mode 100644 index f634f3099a..0000000000 --- a/tests/data/virtual-server-rewrites/virtual-server-rewrite-regex.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: k8s.nginx.org/v1 -kind: VirtualServer -metadata: - name: virtual-server-status -spec: - host: virtual-server-status.example.com - upstreams: - - name: backend2 - service: backend2-svc - port: 80 - - name: backend1 - service: backend1-svc - port: 80 - routes: - - path: ~ /backend1/?(.*) - action: - proxy: - upstream: backend1 - rewritePath: /$1 - - path: ~ /backend2/?(.*) - action: - proxy: - upstream: backend2 - rewritePath: /$1 \ No newline at end of file diff --git a/tests/data/virtual-server-route-rewrites/route-multiple-prefix-regex.yaml b/tests/data/virtual-server-route-rewrites/route-multiple-prefix-regex.yaml deleted file mode 100644 index aa18f942e3..0000000000 --- a/tests/data/virtual-server-route-rewrites/route-multiple-prefix-regex.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: k8s.nginx.org/v1 -kind: VirtualServerRoute -metadata: - name: backends -spec: - host: virtual-server-route.example.com - upstreams: - - name: backend1 - service: backend1-svc - port: 80 - - name: backend3 - service: backend3-svc - port: 80 - subroutes: - - path: /backends/backend1/ - action: - proxy: - upstream: backend1 - rewritePath: / - - path: ~ /backends/backend3/?(.*) - action: - proxy: - upstream: backend3 - rewritePath: /$1 \ No newline at end of file diff --git a/tests/data/virtual-server-route-rewrites/route-single-prefix.yaml b/tests/data/virtual-server-route-rewrites/route-single-prefix.yaml deleted file mode 100644 index c6d337481e..0000000000 --- a/tests/data/virtual-server-route-rewrites/route-single-prefix.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: k8s.nginx.org/v1 -kind: VirtualServerRoute -metadata: - name: backend2 -spec: - host: virtual-server-route.example.com - upstreams: - - name: backend2 - service: backend2-svc - port: 80 - subroutes: - - path: /backend2 - action: - proxy: - upstream: backend2 - rewritePath: /backend2_1 \ No newline at end of file diff --git a/tests/suite/test_rewrites.py b/tests/suite/test_rewrites.py new file mode 100644 index 0000000000..0d7ea41e60 --- /dev/null +++ b/tests/suite/test_rewrites.py @@ -0,0 +1,109 @@ +import pytest +import requests + +from settings import TEST_DATA +from suite.resources_utils import create_items_from_yaml, wait_until_all_pods_are_ready, \ + delete_items_from_yaml, wait_before_test +from suite.vs_vsr_resources_utils import ( + create_virtual_server_from_yaml, delete_virtual_server, create_v_s_route_from_yaml, delete_v_s_route, +) + +hello_app_yaml = f"{TEST_DATA}/rewrites/hello.yaml" + + +@pytest.fixture(scope="class") +def hello_app(request, kube_apis, test_namespace): + create_items_from_yaml(kube_apis, hello_app_yaml, test_namespace) + wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) + + def fin(): + delete_items_from_yaml(kube_apis, hello_app_yaml, test_namespace) + + request.addfinalizer(fin) + + +class RewritesSetup: + def __init__(self, public_endpoint): + self.url_base = f"http://{public_endpoint.public_ip}:{public_endpoint.port}" + + +vs_yaml = f"{TEST_DATA}/rewrites/virtual-server-rewrite.yaml" + + +@pytest.fixture(scope="class") +def vs_rewrites_setup(request, kube_apis, test_namespace, hello_app, ingress_controller_endpoint, + crd_ingress_controller): + vs = create_virtual_server_from_yaml(kube_apis.custom_objects, vs_yaml, test_namespace) + wait_before_test() + + def fin(): + delete_virtual_server(kube_apis.custom_objects, vs, test_namespace) + + request.addfinalizer(fin) + + return RewritesSetup(ingress_controller_endpoint) + + +vs_parent_yaml = f"{TEST_DATA}/rewrites/virtual-server-parent.yaml" +vsr_prefixes_yaml = f"{TEST_DATA}/rewrites/virtual-server-route-prefixes.yaml" +vsr_regex1_yaml = f"{TEST_DATA}/rewrites/virtual-server-route-regex1.yaml" +vsr_regex2_yaml = f"{TEST_DATA}/rewrites/virtual-server-route-regex2.yaml" + + +@pytest.fixture(scope="class") +def vsr_rewrites_setup(request, kube_apis, test_namespace, hello_app, ingress_controller_endpoint, + crd_ingress_controller): + vs_parent = create_virtual_server_from_yaml(kube_apis.custom_objects, vs_parent_yaml, test_namespace) + vsr_prefixes = create_v_s_route_from_yaml(kube_apis.custom_objects, vsr_prefixes_yaml, test_namespace) + vsr_regex1 = create_v_s_route_from_yaml(kube_apis.custom_objects, vsr_regex1_yaml, test_namespace) + vsr_regex2 = create_v_s_route_from_yaml(kube_apis.custom_objects, vsr_regex2_yaml, test_namespace) + wait_before_test() + + def fin(): + delete_virtual_server(kube_apis.custom_objects, vs_parent, test_namespace) + delete_v_s_route(kube_apis.custom_objects, vsr_prefixes, test_namespace) + delete_v_s_route(kube_apis.custom_objects, vsr_regex1, test_namespace) + delete_v_s_route(kube_apis.custom_objects, vsr_regex2, test_namespace) + + request.addfinalizer(fin) + + return RewritesSetup(ingress_controller_endpoint) + + +test_data = [("/backend1/", {"arg": "value"}, {}, "/?arg=value"), + ("/backend1/abc", {"arg": "value"}, {}, "/abc?arg=value"), + ("/backend2", {"arg": "value"}, {}, "/backend2_1?arg=value"), + ("/backend2/", {"arg": "value"}, {}, "/backend2_1/?arg=value"), + ("/backend2/abc", {"arg": "value"}, {}, "/backend2_1/abc?arg=value"), + ("/match/", {"arg": "value"}, {}, "/?arg=value"), + ("/match/abc", {"arg": "value"}, {}, "/abc?arg=value"), + ("/match/", {"arg": "value"}, {"user": "john"}, "/user/john/?arg=value"), + ("/match/abc", {"arg": "value"}, {"user": "john"}, "/user/john/abc?arg=value"), + ("/regex1/", {"arg": "value"}, {}, "/?arg=value"), + ("/regex1//", {"arg": "value"}, {}, "/?arg=value"), + ("/regex2/abc", {"arg": "value"}, {}, "/abc?arg=value")] + + +@pytest.mark.parametrize('crd_ingress_controller', [({'type': 'complete'})], indirect=True) +class TestRewrites: + @pytest.mark.vs + @pytest.mark.parametrize("path,args,cookies,expected", test_data) + def test_vs_rewrite(self, vs_rewrites_setup, path, args, cookies, expected): + """ + Test VirtualServer URI rewrite + """ + url = vs_rewrites_setup.url_base + path + resp = requests.get(url, headers={"host": "vs.example.com"}, params=args, cookies=cookies) + + assert f"URI: {expected}\nRequest" in resp.text + + @pytest.mark.vsr + @pytest.mark.parametrize("path,args,cookies,expected", test_data) + def test_vsr_rewrite(self, vsr_rewrites_setup, path, args, cookies, expected): + """ + Test VirtualServerRoute URI rewrite + """ + url = vsr_rewrites_setup.url_base + path + resp = requests.get(url, headers={"host": "vsr.example.com"}, params=args, cookies=cookies) + + assert f"URI: {expected}\nRequest" in resp.text diff --git a/tests/suite/test_v_s_route_rewrites.py b/tests/suite/test_v_s_route_rewrites.py deleted file mode 100644 index 17f573e4a5..0000000000 --- a/tests/suite/test_v_s_route_rewrites.py +++ /dev/null @@ -1,121 +0,0 @@ -import pytest -import requests -from kubernetes.client.rest import ApiException -from suite.resources_utils import wait_before_test -from suite.custom_resources_utils import ( - read_custom_resource, -) -from suite.vs_vsr_resources_utils import ( - patch_virtual_server_from_yaml, - patch_v_s_route_from_yaml, - delete_virtual_server, - create_virtual_server_from_yaml, -) -from settings import TEST_DATA - -@pytest.mark.vsr -@pytest.mark.parametrize( - "crd_ingress_controller, v_s_route_setup", - [ - ( - {"type": "complete", "extra_args": [f"-enable-custom-resources"],}, - {"example": "virtual-server-route"}, - ) - ], - indirect=True, -) -@pytest.mark.rewrite -class TestVirtualServerRouteRewrite: - def patch_standard_vsr(self, kube_apis, v_s_route_setup) -> None: - """ - Function to revert vsr deployments to valid state - """ - patch_src_m = f"{TEST_DATA}/virtual-server-route/route-multiple.yaml" - patch_v_s_route_from_yaml( - kube_apis.custom_objects, - v_s_route_setup.route_m.name, - patch_src_m, - v_s_route_setup.route_m.namespace, - ) - wait_before_test() - patch_src_s = f"{TEST_DATA}/virtual-server-route/route-single.yaml" - patch_v_s_route_from_yaml( - kube_apis.custom_objects, - v_s_route_setup.route_s.name, - patch_src_s, - v_s_route_setup.route_s.namespace, - ) - wait_before_test() - - def test_prefix_rewrite( - self, kube_apis, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup - ): - """ - Test VirtualServerRoute URI rewrite using prefix - """ - req_url = f"http://{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}" - patch_src_m = f"{TEST_DATA}/virtual-server-route-rewrites/route-multiple-prefix-regex.yaml" - patch_v_s_route_from_yaml( - kube_apis.custom_objects, - v_s_route_setup.route_m.name, - patch_src_m, - v_s_route_setup.route_m.namespace, - ) - wait_before_test() - patch_src_s = f"{TEST_DATA}/virtual-server-route-rewrites/route-single-prefix.yaml" - patch_v_s_route_from_yaml( - kube_apis.custom_objects, - v_s_route_setup.route_s.name, - patch_src_s, - v_s_route_setup.route_s.namespace, - ) - wait_before_test() - resp1 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[0]}/", - headers={"host": v_s_route_setup.vs_host}) - resp2 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[0]}/abc", - headers={"host": v_s_route_setup.vs_host}) - resp3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", - headers={"host": v_s_route_setup.vs_host}) - resp4 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}/", - headers={"host": v_s_route_setup.vs_host}) - resp5 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}/abc", - headers={"host": v_s_route_setup.vs_host}) - self.patch_standard_vsr(kube_apis, v_s_route_setup) - - assert ( "URI: /\nRequest" in resp1.text - and "URI: /abc\nRequest" in resp2.text - and "URI: /backend2_1\nRequest" in resp3.text - and "URI: /backend2_1/\nRequest" in resp4.text - and "URI: /backend2_1/abc\nRequest" in resp5.text - ) - - def test_regex_rewrite( - self, kube_apis, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup - ): - """ - Test VirtualServerRoute URI rewrite using regex - """ - req_url = f"http://{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}" - patch_src_m = f"{TEST_DATA}/virtual-server-route-rewrites/route-multiple-prefix-regex.yaml" - patch_v_s_route_from_yaml( - kube_apis.custom_objects, - v_s_route_setup.route_m.name, - patch_src_m, - v_s_route_setup.route_m.namespace, - ) - - wait_before_test() - resp1 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[1]}", - headers={"host": v_s_route_setup.vs_host}) - resp2 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[1]}/", - headers={"host": v_s_route_setup.vs_host}) - resp3 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[1]}/abc", - headers={"host": v_s_route_setup.vs_host}) - - self.patch_standard_vsr(kube_apis, v_s_route_setup) - - assert ( "URI: /\nRequest" in resp1.text - and "URI: /\nRequest" in resp2.text - and "URI: /abc\nRequest" in resp3.text - ) - \ No newline at end of file diff --git a/tests/suite/test_virtual_server_rewrites.py b/tests/suite/test_virtual_server_rewrites.py deleted file mode 100644 index 320c7d5917..0000000000 --- a/tests/suite/test_virtual_server_rewrites.py +++ /dev/null @@ -1,95 +0,0 @@ -import pytest -import requests -from kubernetes.client.rest import ApiException -from suite.resources_utils import wait_before_test -from suite.vs_vsr_resources_utils import ( - patch_virtual_server_from_yaml, -) -from suite.custom_resources_utils import ( - read_custom_resource, -) -from settings import TEST_DATA - -@pytest.mark.vs -@pytest.mark.parametrize( - "crd_ingress_controller, virtual_server_setup", - [ - ( - {"type": "complete", "extra_args": [f"-enable-custom-resources"],}, - {"example": "virtual-server-status", "app_type": "simple",}, - ) - ], - indirect=True, -) -@pytest.mark.rewrite -class TestVirtualServerRewrites: - - def patch_standard_vs(self, kube_apis, virtual_server_setup) -> None: - """ - Deploy standard virtual-server - """ - patch_src = f"{TEST_DATA}/virtual-server-rewrites/standard/virtual-server.yaml" - patch_virtual_server_from_yaml( - kube_apis.custom_objects, - virtual_server_setup.vs_name, - patch_src, - virtual_server_setup.namespace, - ) - - def test_prefix_rewrite( - self, kube_apis, crd_ingress_controller, virtual_server_setup, - ): - """ - Test VirtualServer URI rewrite using prefix - """ - patch_src = f"{TEST_DATA}/virtual-server-rewrites/virtual-server-rewrite-prefix.yaml" - patch_virtual_server_from_yaml( - kube_apis.custom_objects, - virtual_server_setup.vs_name, - patch_src, - virtual_server_setup.namespace, - ) - wait_before_test() - resp1 = requests.get(virtual_server_setup.backend_1_url+"/", - headers={"host": virtual_server_setup.vs_host}) - resp2 = requests.get(virtual_server_setup.backend_1_url+"/abc", - headers={"host": virtual_server_setup.vs_host}) - resp3 = requests.get(virtual_server_setup.backend_2_url, - headers={"host": virtual_server_setup.vs_host}) - resp4 = requests.get(virtual_server_setup.backend_2_url+"/", - headers={"host": virtual_server_setup.vs_host}) - resp5 = requests.get(virtual_server_setup.backend_2_url+"/abc", - headers={"host": virtual_server_setup.vs_host}) - self.patch_standard_vs(kube_apis, virtual_server_setup) - - assert ("URI: /\nRequest" in resp1.text - and "URI: /abc\nRequest" in resp2.text - and "URI: /backend2_1\nRequest" in resp3.text - and "URI: /backend2_1/\nRequest" in resp4.text - and "URI: /backend2_1/abc\nRequest" in resp5.text) - - def test_regex_rewrite( - self, kube_apis, crd_ingress_controller, virtual_server_setup, - ): - """ - Test VirtualServer URI rewrite using regex - """ - patch_src = f"{TEST_DATA}/virtual-server-rewrites/virtual-server-rewrite-regex.yaml" - patch_virtual_server_from_yaml( - kube_apis.custom_objects, - virtual_server_setup.vs_name, - patch_src, - virtual_server_setup.namespace, - ) - wait_before_test() - resp1 = requests.get(virtual_server_setup.backend_1_url, - headers={"host": virtual_server_setup.vs_host}) - resp2 = requests.get(virtual_server_setup.backend_1_url+"/", - headers={"host": virtual_server_setup.vs_host}) - resp3 = requests.get(virtual_server_setup.backend_2_url+"/abc", - headers={"host": virtual_server_setup.vs_host}) - self.patch_standard_vs(kube_apis, virtual_server_setup) - - assert ("URI: /\nRequest" in resp1.text - and "URI: /\nRequest" in resp2.text - and "URI: /abc\nRequest" in resp3.text)