Skip to content

Commit

Permalink
added another test
Browse files Browse the repository at this point in the history
Signed-off-by: tjons <tyler.schade@solo.io>
  • Loading branch information
tjons committed Nov 6, 2023
1 parent 4e7102a commit 968acb2
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,60 @@ func TestConfigWithProtoDescriptor(t *testing.T) {
}
}

func TestCheckAllowObjectDecisionDynamicMetadata(t *testing.T) {
var req ext_authz.CheckRequest
if err := util.Unmarshal([]byte(exampleAllowedRequestParsedPath), &req); err != nil {
panic(err)
}

module := `
package envoy.authz
default allow = false
allow {
input.parsed_path = ["my", "test", "path"]
}
dynamic_metadata["foo"] = "bar"
dynamic_metadata["bar"] = "baz"
result["allowed"] = allow
result["dynamic_metadata"] = dynamic_metadata
`

server := testAuthzServerWithModule(module, "envoy/authz/result", nil, withCustomLogger(&testPlugin{}))
ctx := context.Background()
output, err := server.Check(ctx, &req)
if err != nil {
t.Fatal(err)
}

if output.Status.Code != int32(code.Code_OK) {
t.Fatalf("Expected request to be allowed but got: %v", output)
}

response := output.GetOkResponse()
if response == nil {
t.Fatal("Expected OkHttpResponse struct but got nil")
}

assertDynamicMetadata(t, &_structpb.Struct{
Fields: map[string]*_structpb.Value{
"foo": {
Kind: &_structpb.Value_StringValue{
StringValue: "bar",
},
},
"bar": {
Kind: &_structpb.Value_StringValue{
StringValue: "baz",
},
},
},
}, output.GetDynamicMetadata())
}

func TestCheckAllowObjectDecisionReqHeadersToRemove(t *testing.T) {
var req ext_authz.CheckRequest
if err := util.Unmarshal([]byte(exampleAllowedRequestParsedPath), &req); err != nil {
Expand Down

0 comments on commit 968acb2

Please sign in to comment.