Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate httproutes.gateway.networking.k8s.io #11150

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
Signed-off-by: Takumi Sue <[email protected]>
mikutas committed Jul 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 7636ae1f3a2eb012af503a76b8b9706deaa9327b
61 changes: 61 additions & 0 deletions policy-test/tests/admit_http_route_gateway.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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()),