-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
14 changed files
with
268 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
20 changes: 0 additions & 20 deletions
20
tests/data/virtual-server-rewrites/standard/virtual-server.yaml
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
tests/data/virtual-server-rewrites/virtual-server-rewrite-prefix.yaml
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
tests/data/virtual-server-rewrites/virtual-server-rewrite-regex.yaml
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
tests/data/virtual-server-route-rewrites/route-multiple-prefix-regex.yaml
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
tests/data/virtual-server-route-rewrites/route-single-prefix.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.