Skip to content

Commit

Permalink
fix(rbac) include Negative when marshaling RBAC
Browse files Browse the repository at this point in the history
Include the Negative field when marshaling RBAC types to JSON.

The RBAC entity and endpoint permissions types have custom JSON
marshalers to account for differences between Kong's GET output and the
expected inputs to PUT/PATCH/POST:
https://github.com/Kong/go-kong/pull/5/files#r495600736

Previously, these marshalers omitted the Negative fields, so requests
outbound from go-kong would never set Negative, and it would always be
the default (false).

Fix FTI-2405
  • Loading branch information
Travis Raines committed Mar 30, 2021
1 parent 1b573f2 commit 146b85d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kong/endpoint_permission_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ func TestRBACEndpointPermissionservice(T *testing.T) {
assert.Nil(err)
assert.NotNil(ep)

negative := true
ep.Comment = String("new comment")
ep.Negative = &negative
ep, err = client.RBACEndpointPermissions.Update(defaultCtx, ep)
assert.Nil(err)
assert.NotNil(ep)
assert.Equal("new comment", *ep.Comment)
assert.Equal(negative, *ep.Negative)

err = client.RBACEndpointPermissions.Delete(
defaultCtx, createdRole.ID, createdWorkspace.ID, createdEndpointPermission.Endpoint)
Expand Down
3 changes: 3 additions & 0 deletions kong/entity_permission_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ func TestRBACEntityPermissionservice(T *testing.T) {
assert.Nil(err)
assert.NotNil(ep)

negative := true
ep.Comment = String("new comment")
ep.Negative = &negative
ep, err = workspaceClient.RBACEntityPermissions.Update(defaultCtx, ep)
assert.Nil(err)
assert.NotNil(ep)
assert.Equal("new comment", *ep.Comment)
assert.Equal(negative, *ep.Negative)

err = workspaceClient.RBACEntityPermissions.Delete(defaultCtx, createdRole.ID, createdEntityPermission.EntityID)
assert.Nil(err)
Expand Down
2 changes: 2 additions & 0 deletions kong/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func (e *RBACEndpointPermission) MarshalJSON() ([]byte, error) {
Workspace: e.Workspace,
Endpoint: e.Endpoint,
Actions: String(strings.Join(actions, ",")),
Negative: e.Negative,
Comment: e.Comment,
})
}
Expand Down Expand Up @@ -399,6 +400,7 @@ func (e *RBACEntityPermission) MarshalJSON() ([]byte, error) {
EntityID: e.EntityID,
EntityType: e.EntityType,
Actions: String(strings.Join(actions, ",")),
Negative: e.Negative,
Comment: e.Comment,
})
}
Expand Down

0 comments on commit 146b85d

Please sign in to comment.