Skip to content

Commit 8913da1

Browse files
authored
Merge pull request #1984 from gauravkghildiyal/httproute-match-combinations
Add conformance test for combination of extended match types with core types
2 parents 34466a8 + 9d470b4 commit 8913da1

File tree

5 files changed

+270
-0
lines changed

5 files changed

+270
-0
lines changed

conformance/tests/httproute-method-matching.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,68 @@ var HTTPRouteMethodMatching = suite.ConformanceTest{
6161
},
6262
}
6363

64+
// Combinations of method matching with other core matches.
65+
testCases = append(testCases, []http.ExpectedResponse{
66+
{
67+
Request: http.Request{Path: "/path1", Method: "GET"},
68+
Backend: "infra-backend-v1",
69+
Namespace: ns,
70+
},
71+
{
72+
Request: http.Request{Headers: map[string]string{"version": "one"}, Path: "/", Method: "PUT"},
73+
Backend: "infra-backend-v2",
74+
Namespace: ns,
75+
},
76+
{
77+
Request: http.Request{Headers: map[string]string{"version": "two"}, Path: "/path2", Method: "POST"},
78+
Backend: "infra-backend-v3",
79+
Namespace: ns,
80+
},
81+
}...)
82+
83+
// Ensure that combinations of matches which are OR'd together match
84+
// even if only one of them is used in the request.
85+
testCases = append(testCases, []http.ExpectedResponse{
86+
{
87+
Request: http.Request{Path: "/path3", Method: "PATCH"},
88+
Backend: "infra-backend-v1",
89+
Namespace: ns,
90+
},
91+
{
92+
Request: http.Request{Headers: map[string]string{"version": "three"}, Path: "/path4", Method: "DELETE"},
93+
Backend: "infra-backend-v1",
94+
Namespace: ns,
95+
},
96+
}...)
97+
98+
// Ensure that combinations of match types which are ANDed together do not match
99+
// when only a subset of match types is used in the request.
100+
testCases = append(testCases, []http.ExpectedResponse{
101+
{
102+
Request: http.Request{Path: "/", Method: "PUT"},
103+
Response: http.Response{StatusCode: 404},
104+
},
105+
{
106+
Request: http.Request{Path: "/path4", Method: "DELETE"},
107+
Response: http.Response{StatusCode: 404},
108+
},
109+
}...)
110+
111+
// For requests that satisfy multiple matches, ensure precedence order
112+
// defined by the Gateway API spec is maintained.
113+
testCases = append(testCases, []http.ExpectedResponse{
114+
{
115+
Request: http.Request{Path: "/path5", Method: "PATCH"},
116+
Backend: "infra-backend-v1",
117+
Namespace: ns,
118+
},
119+
{
120+
Request: http.Request{Headers: map[string]string{"version": "four"}, Path: "/", Method: "PATCH"},
121+
Backend: "infra-backend-v3",
122+
Namespace: ns,
123+
},
124+
}...)
125+
64126
for i := range testCases {
65127
// Declare tc here to avoid loop variable
66128
// reuse issues across parallel tests.

conformance/tests/httproute-method-matching.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,70 @@ spec:
1717
backendRefs:
1818
- name: infra-backend-v2
1919
port: 8080
20+
21+
# Combinations with core match types.
22+
- matches:
23+
- path:
24+
type: PathPrefix
25+
value: /path1
26+
method: GET
27+
backendRefs:
28+
- name: infra-backend-v1
29+
port: 8080
30+
- matches:
31+
- headers:
32+
- name: version
33+
value: one
34+
method: PUT
35+
backendRefs:
36+
- name: infra-backend-v2
37+
port: 8080
38+
- matches:
39+
- path:
40+
type: PathPrefix
41+
value: /path2
42+
headers:
43+
- name: version
44+
value: two
45+
method: POST
46+
backendRefs:
47+
- name: infra-backend-v3
48+
port: 8080
49+
50+
# Match of the form (cond1 AND cond2) OR (cond3 AND cond4 AND cond5)
51+
- matches:
52+
- path:
53+
type: PathPrefix
54+
value: /path3
55+
method: PATCH
56+
- path:
57+
type: PathPrefix
58+
value: /path4
59+
headers:
60+
- name: version
61+
value: three
62+
method: DELETE
63+
backendRefs:
64+
- name: infra-backend-v1
65+
port: 8080
66+
67+
# Matches for checking precedence.
68+
- matches:
69+
- path:
70+
type: PathPrefix
71+
value: /path5
72+
backendRefs:
73+
- name: infra-backend-v1
74+
port: 8080
75+
- matches:
76+
- method: PATCH
77+
backendRefs:
78+
- name: infra-backend-v2
79+
port: 8080
80+
- matches:
81+
- headers:
82+
- name: version
83+
value: four
84+
backendRefs:
85+
- name: infra-backend-v3
86+
port: 8080

conformance/tests/httproute-query-param-matching.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,68 @@ var HTTPRouteQueryParamMatching = suite.ConformanceTest{
8484
Response: http.Response{StatusCode: 404},
8585
}}
8686

87+
// Combinations of query param matching with other core matches.
88+
testCases = append(testCases, []http.ExpectedResponse{
89+
{
90+
Request: http.Request{Path: "/path1?animal=whale"},
91+
Backend: "infra-backend-v1",
92+
Namespace: ns,
93+
},
94+
{
95+
Request: http.Request{Headers: map[string]string{"version": "one"}, Path: "/?animal=whale"},
96+
Backend: "infra-backend-v2",
97+
Namespace: ns,
98+
},
99+
{
100+
Request: http.Request{Headers: map[string]string{"version": "two"}, Path: "/path2?animal=whale"},
101+
Backend: "infra-backend-v3",
102+
Namespace: ns,
103+
},
104+
}...)
105+
106+
// Ensure that combinations of matches which are OR'd together match
107+
// even if only one of them is used in the request.
108+
testCases = append(testCases, []http.ExpectedResponse{
109+
{
110+
Request: http.Request{Path: "/path3?animal=shark"},
111+
Backend: "infra-backend-v1",
112+
Namespace: ns,
113+
},
114+
{
115+
Request: http.Request{Headers: map[string]string{"version": "three"}, Path: "/path4?animal=kraken"},
116+
Backend: "infra-backend-v1",
117+
Namespace: ns,
118+
},
119+
}...)
120+
121+
// Ensure that combinations of match types which are ANDed together do not match
122+
// when only a subset of match types is used in the request.
123+
testCases = append(testCases, []http.ExpectedResponse{
124+
{
125+
Request: http.Request{Path: "/?animal=shark"},
126+
Response: http.Response{StatusCode: 404},
127+
},
128+
{
129+
Request: http.Request{Path: "/path4?animal=kraken"},
130+
Response: http.Response{StatusCode: 404},
131+
},
132+
}...)
133+
134+
// For requests that satisfy multiple matches, ensure precedence order
135+
// defined by the Gateway API spec is maintained.
136+
testCases = append(testCases, []http.ExpectedResponse{
137+
{
138+
Request: http.Request{Path: "/path5?animal=hydra"},
139+
Backend: "infra-backend-v1",
140+
Namespace: ns,
141+
},
142+
{
143+
Request: http.Request{Headers: map[string]string{"version": "four"}, Path: "/?animal=hydra"},
144+
Backend: "infra-backend-v3",
145+
Namespace: ns,
146+
},
147+
}...)
148+
87149
for i := range testCases {
88150
tc := testCases[i]
89151
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {

conformance/tests/httproute-query-param-matching.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,82 @@ spec:
3333
backendRefs:
3434
- name: infra-backend-v3
3535
port: 8080
36+
37+
# Combinations with core match types.
38+
- matches:
39+
- path:
40+
type: PathPrefix
41+
value: /path1
42+
queryParams:
43+
- name: animal
44+
value: whale
45+
backendRefs:
46+
- name: infra-backend-v1
47+
port: 8080
48+
- matches:
49+
- headers:
50+
- name: version
51+
value: one
52+
queryParams:
53+
- name: animal
54+
value: whale
55+
backendRefs:
56+
- name: infra-backend-v2
57+
port: 8080
58+
- matches:
59+
- path:
60+
type: PathPrefix
61+
value: /path2
62+
headers:
63+
- name: version
64+
value: two
65+
queryParams:
66+
- name: animal
67+
value: whale
68+
backendRefs:
69+
- name: infra-backend-v3
70+
port: 8080
71+
72+
# Match of the form (cond1 AND cond2) OR (cond3 AND cond4 AND cond5)
73+
- matches:
74+
- path:
75+
type: PathPrefix
76+
value: /path3
77+
queryParams:
78+
- name: animal
79+
value: shark
80+
- path:
81+
type: PathPrefix
82+
value: /path4
83+
headers:
84+
- name: version
85+
value: three
86+
queryParams:
87+
- name: animal
88+
value: kraken
89+
backendRefs:
90+
- name: infra-backend-v1
91+
port: 8080
92+
93+
# Matches for checking precedence.
94+
- matches:
95+
- path:
96+
type: PathPrefix
97+
value: /path5
98+
backendRefs:
99+
- name: infra-backend-v1
100+
port: 8080
101+
- matches:
102+
- queryParams:
103+
- name: animal
104+
value: hydra
105+
backendRefs:
106+
- name: infra-backend-v2
107+
port: 8080
108+
- matches:
109+
- headers:
110+
- name: version
111+
value: four
112+
backendRefs:
113+
- name: infra-backend-v3
114+
port: 8080

hack/verify-yamllint.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)