Skip to content

Commit

Permalink
fix: Use IncludeMetadata option on all gRPC requests (#1586)
Browse files Browse the repository at this point in the history
* fix: Use IncludeMetadata option on all gRPC requests

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>

* Add tests

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>

---------

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>
  • Loading branch information
oguzhand95 committed May 16, 2023
1 parent 3b64da7 commit b49d27d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/client.go
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
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
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

0 comments on commit b49d27d

Please sign in to comment.