Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Takumi Sue <u630868b@alumni.osaka-u.ac.jp>
  • Loading branch information
mikutas committed Jul 29, 2023
1 parent ac4a7db commit 7636ae1
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions policy-test/tests/admit_http_route_gateway.rs
Expand Up @@ -3,6 +3,7 @@ use k8s_gateway_api::CommonRouteSpec;
use k8s_gateway_api::HttpPathMatch;
use k8s_gateway_api::HttpPathModifier;
use k8s_gateway_api::HttpRequestMirrorFilter;
use k8s_gateway_api::HttpRequestRedirectFilter;
use k8s_gateway_api::HttpRoute;
use k8s_gateway_api::HttpRouteFilter;
use k8s_gateway_api::HttpRouteMatch;
Expand Down Expand Up @@ -136,6 +137,66 @@ async fn accepts_not_implemented_extensionref() {
.await;
}

#[tokio::test(flavor = "current_thread")]
async fn rejects_relative_path_match() {
admission::rejects(|ns| HttpRoute {
metadata: meta(&ns),
spec: HttpRouteSpec {
inner: CommonRouteSpec {
parent_refs: Some(vec![server_parent_ref(ns)]),
},
hostnames: None,
rules: Some(vec![HttpRouteRule {
matches: Some(vec![HttpRouteMatch {
path: Some(HttpPathMatch::Exact {
value: "foo/bar".to_string(),
}),
..HttpRouteMatch::default()
}]),
filters: None,
backend_refs: None,
}]),
},
status: None,
})
.await;
}

#[tokio::test(flavor = "current_thread")]
async fn rejects_relative_redirect_path() {
admission::rejects(|ns| HttpRoute {
metadata: meta(&ns),
spec: HttpRouteSpec {
inner: CommonRouteSpec {
parent_refs: Some(vec![server_parent_ref(ns)]),
},
hostnames: None,
rules: Some(vec![HttpRouteRule {
matches: Some(vec![HttpRouteMatch {
path: Some(HttpPathMatch::Exact {
value: "/foo".to_string(),
}),
..HttpRouteMatch::default()
}]),
filters: Some(vec![HttpRouteFilter::RequestRedirect {
request_redirect: HttpRequestRedirectFilter {
scheme: None,
hostname: None,
path: Some(HttpPathModifier::ReplaceFullPath {
replace_full_path: "foo/bar".to_string(),
}),
port: None,
status_code: None,
},
}]),
backend_refs: None,
}]),
},
status: None,
})
.await;
}

fn server_parent_ref(ns: impl ToString) -> ParentReference {
ParentReference {
group: Some("policy.linkerd.io".to_string()),
Expand Down

0 comments on commit 7636ae1

Please sign in to comment.