Skip to content

Commit

Permalink
fix: add permissions field to binding
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovannaMonti committed Apr 21, 2023
1 parent fa044ae commit 18815c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Fixed

- correctly manage binding permissions in grant api

## 1.5.0 - 19-10-2022

## 1.4.3 - 12-10-2022
Expand Down
9 changes: 5 additions & 4 deletions service/standalone_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ func grantHandler(w http.ResponseWriter, r *http.Request) {
}

bindingToCreate := types.Binding{
BindingID: uuid.New().String(),
Groups: reqBody.Groups,
Roles: reqBody.Roles,
Subjects: reqBody.Subjects,
BindingID: uuid.New().String(),
Groups: reqBody.Groups,
Permissions: reqBody.Permissions,
Roles: reqBody.Roles,
Subjects: reqBody.Subjects,
}

if resourceType != "" {
Expand Down
21 changes: 10 additions & 11 deletions service/standalone_apis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,11 @@ func TestGrantHandler(t *testing.T) {
defer gock.Flush()

reqBody := setupGrantRequestBody(t, GrantRequestBody{
Subjects: []string{"piero"},
ResourceID: "projectID",
Roles: []string{"editor"},
Groups: []string{"test-group"},
Subjects: []string{"piero"},
ResourceID: "projectID",
Roles: []string{"editor"},
Permissions: []string{"test-permission"},
Groups: []string{"test-group"},
})

gock.DisableNetworking()
Expand All @@ -569,9 +570,6 @@ func TestGrantHandler(t *testing.T) {
bodyBytes, err := io.ReadAll(req.Body)
require.Nil(t, err, "unxpected error reading body in matcher")

containsNull := strings.Contains(string(bodyBytes), `"permissions":null`)
require.False(t, containsNull, "unexpected null found")

err = json.Unmarshal(bodyBytes, &body)
require.Nil(t, err, "unxpected error parsing body in matcher")

Expand All @@ -580,10 +578,11 @@ func TestGrantHandler(t *testing.T) {

body.BindingID = "REDACTED"
require.Equal(t, types.Binding{
BindingID: "REDACTED",
Groups: []string{"test-group"},
Roles: []string{"editor"},
Subjects: []string{"piero"},
BindingID: "REDACTED",
Groups: []string{"test-group"},
Permissions: []string{"test-permission"},
Roles: []string{"editor"},
Subjects: []string{"piero"},
Resource: &types.Resource{
ResourceType: "my-resource",
ResourceID: "projectID",
Expand Down

0 comments on commit 18815c2

Please sign in to comment.