Skip to content

Commit 7636ae1

Browse files
committed
Add tests
Signed-off-by: Takumi Sue <[email protected]>
1 parent ac4a7db commit 7636ae1

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

policy-test/tests/admit_http_route_gateway.rs

+61
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use k8s_gateway_api::CommonRouteSpec;
33
use k8s_gateway_api::HttpPathMatch;
44
use k8s_gateway_api::HttpPathModifier;
55
use k8s_gateway_api::HttpRequestMirrorFilter;
6+
use k8s_gateway_api::HttpRequestRedirectFilter;
67
use k8s_gateway_api::HttpRoute;
78
use k8s_gateway_api::HttpRouteFilter;
89
use k8s_gateway_api::HttpRouteMatch;
@@ -136,6 +137,66 @@ async fn accepts_not_implemented_extensionref() {
136137
.await;
137138
}
138139

140+
#[tokio::test(flavor = "current_thread")]
141+
async fn rejects_relative_path_match() {
142+
admission::rejects(|ns| HttpRoute {
143+
metadata: meta(&ns),
144+
spec: HttpRouteSpec {
145+
inner: CommonRouteSpec {
146+
parent_refs: Some(vec![server_parent_ref(ns)]),
147+
},
148+
hostnames: None,
149+
rules: Some(vec![HttpRouteRule {
150+
matches: Some(vec![HttpRouteMatch {
151+
path: Some(HttpPathMatch::Exact {
152+
value: "foo/bar".to_string(),
153+
}),
154+
..HttpRouteMatch::default()
155+
}]),
156+
filters: None,
157+
backend_refs: None,
158+
}]),
159+
},
160+
status: None,
161+
})
162+
.await;
163+
}
164+
165+
#[tokio::test(flavor = "current_thread")]
166+
async fn rejects_relative_redirect_path() {
167+
admission::rejects(|ns| HttpRoute {
168+
metadata: meta(&ns),
169+
spec: HttpRouteSpec {
170+
inner: CommonRouteSpec {
171+
parent_refs: Some(vec![server_parent_ref(ns)]),
172+
},
173+
hostnames: None,
174+
rules: Some(vec![HttpRouteRule {
175+
matches: Some(vec![HttpRouteMatch {
176+
path: Some(HttpPathMatch::Exact {
177+
value: "/foo".to_string(),
178+
}),
179+
..HttpRouteMatch::default()
180+
}]),
181+
filters: Some(vec![HttpRouteFilter::RequestRedirect {
182+
request_redirect: HttpRequestRedirectFilter {
183+
scheme: None,
184+
hostname: None,
185+
path: Some(HttpPathModifier::ReplaceFullPath {
186+
replace_full_path: "foo/bar".to_string(),
187+
}),
188+
port: None,
189+
status_code: None,
190+
},
191+
}]),
192+
backend_refs: None,
193+
}]),
194+
},
195+
status: None,
196+
})
197+
.await;
198+
}
199+
139200
fn server_parent_ref(ns: impl ToString) -> ParentReference {
140201
ParentReference {
141202
group: Some("policy.linkerd.io".to_string()),

0 commit comments

Comments
 (0)