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

Improvements to OPA filter unit test cases #3259

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ func TestAuthorizeRequestFilter(t *testing.T) {
backendHeaders: make(http.Header),
removeHeaders: make(http.Header),
},
{
msg: "Allow Request based on http path",
filterName: "opaAuthorizeRequest",
bundleName: "somebundle.tar.gz",
regoQuery: "envoy/authz/allow_with_http_path",
requestPath: "/some/api/path?q1=v1&msg=help%20me",
requestMethod: "GET",
contextExtensions: "",
expectedStatus: http.StatusOK,
expectedBody: "Welcome!",
expectedHeaders: make(http.Header),
backendHeaders: make(http.Header),
removeHeaders: make(http.Header),
},
{
msg: "Allow Requests with query parameters",
filterName: "opaAuthorizeRequest",
Expand Down Expand Up @@ -120,10 +134,10 @@ func TestAuthorizeRequestFilter(t *testing.T) {
msg: "Allow Requests with an empty query string",
filterName: "opaAuthorizeRequest",
bundleName: "somebundle.tar.gz",
regoQuery: "envoy/authz/allow_context_extensions",
regoQuery: "envoy/authz/allow_with_path_having_empty_query",
requestPath: "/path-with-empty-query?",
requestMethod: "GET",
contextExtensions: "com.mycompany.myprop: myvalue",
contextExtensions: "",
expectedStatus: http.StatusOK,
expectedBody: "Welcome!",
expectedHeaders: make(http.Header),
Expand Down Expand Up @@ -398,12 +412,16 @@ func TestAuthorizeRequestFilter(t *testing.T) {
input.parsed_query = {}
}

allow_with_http_path {
input.attributes.request.http.path == "/some/api/path?q1=v1&msg=help%20me"
}

allow {
input.parsed_path = [ "my path" ]
}

allow {
input.parsed_path = [ "/path-with-empty-query" ]
allow_with_path_having_empty_query {
input.parsed_path = [ "path-with-empty-query" ]
input.parsed_query = {}
}

Expand Down
Loading