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

fix: Use IncludeMetadata option on all gRPC requests #1586

Merged
merged 2 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (gc *grpcClient) CheckResourceSet(ctx context.Context, principal *Principal

if gc.opts != nil {
req.AuxData = gc.opts.auxData
req.IncludeMeta = gc.opts.includeMeta
}

result, err := gc.stub.CheckResourceSet(ctx, req)
Expand Down Expand Up @@ -407,6 +408,7 @@ func (gc *grpcClient) CheckResources(ctx context.Context, principal *Principal,

if gc.opts != nil {
req.AuxData = gc.opts.auxData
req.IncludeMeta = gc.opts.includeMeta
}

result, err := gc.stub.CheckResources(ctx, req)
Expand Down Expand Up @@ -441,6 +443,7 @@ func (gc *grpcClient) IsAllowed(ctx context.Context, principal *Principal, resou

if gc.opts != nil {
req.AuxData = gc.opts.auxData
req.IncludeMeta = gc.opts.includeMeta
}

result, err := gc.stub.CheckResources(ctx, req)
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestClient(t *testing.T) {
c, err := client.New(port.addr, tc.opts...)
require.NoError(t, err)

t.Run(port.name, client.TestGRPCClient(c.With(client.AuxDataJWT(jwt, ""))))
t.Run(port.name, client.TestGRPCClient(c))
}
})

Expand Down
10 changes: 9 additions & 1 deletion client/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func TestGRPCClient(c Client) func(*testing.T) {
//nolint:thelper
return func(t *testing.T) {
token := GenerateToken(t, time.Now().Add(5*time.Minute)) //nolint:gomnd
c := c.With(AuxDataJWT(token, ""))
c := c.With(
AuxDataJWT(token, ""),
IncludeMeta(true),
)
t.Run("CheckResourceSet", func(t *testing.T) {
ctx, cancelFunc := context.WithTimeout(context.Background(), timeout)
defer cancelFunc()
Expand Down Expand Up @@ -65,6 +68,7 @@ func TestGRPCClient(c Client) func(*testing.T) {
require.True(t, have.IsAllowed("XX125", "view:public"))
require.False(t, have.IsAllowed("XX125", "approve"))
require.True(t, have.IsAllowed("XX125", "defer"))
require.NotNil(t, have.Meta, "no metadata found")
})

t.Run("CheckResourceBatch", func(t *testing.T) {
Expand Down Expand Up @@ -184,6 +188,8 @@ func TestGRPCClient(c Client) func(*testing.T) {

have, err := c.CheckResources(ctx, principal, resources)
check(t, have, err)

require.NotNil(t, have.Results[0].Meta, "no metadata found in the result")
})

t.Run("WithPrincipal", func(t *testing.T) {
Expand All @@ -192,6 +198,8 @@ func TestGRPCClient(c Client) func(*testing.T) {

have, err := c.WithPrincipal(principal).CheckResources(ctx, resources)
check(t, have, err)

require.NotNil(t, have.Results[0].Meta, "no metadata found in the result")
})
})

Expand Down