Skip to content

Commit

Permalink
Improvements to OPA filter unit test cases (#3259)
Browse files Browse the repository at this point in the history
- Fix test case that uses an invalid rego query in the test case
- Include a test case to validate policy evaluation based on `input.attributes.request.http.path` (http path set in the envoy check request)

Signed-off-by: Farasath Ahamed <farasath.ahamed@zalando.de>
  • Loading branch information
mefarazath authored Oct 1, 2024
1 parent 8f93ccd commit e6f8a93
Showing 1 changed file with 22 additions and 4 deletions.
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

0 comments on commit e6f8a93

Please sign in to comment.