Skip to content

Commit

Permalink
Merge pull request #25 from permitio/raz/per-8255-salt-security-list-…
Browse files Browse the repository at this point in the history
…detailed-role-assignment-panic-in-go-sdk

add error check in get users roles
  • Loading branch information
RazcoDev authored Nov 7, 2023
2 parents 015a81d + f92dd56 commit 5510071
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ func (u *Users) GetAssignedRoles(ctx context.Context, userKey string, tenantKey
u.logger.Error("error listing roles for user:"+userKey, zap.Error(err))
return nil, err
}
if roleAssignments == nil || roleAssignments.RoleAssignmentRead == nil {
if roleAssignments.RoleAssignmentRead == nil {
emptyRoleAssignments := make([]models.RoleAssignmentRead, 0)
return emptyRoleAssignments, nil
}
}
return *roleAssignments.RoleAssignmentRead, nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ func TestIntegration(t *testing.T) {
userCreate.SetEmail("[email protected]")
_, err := permitClient.Api.Users.Create(ctx, userCreate)
assert.NoError(t, err)

res, err := permitClient.Api.Users.GetAssignedRoles(ctx, userKey, tenantKey, 1, 100)
assert.NoError(t, err)
assert.Len(t, res, 0)
// Check error codes when creating a user with existing name
_, err = permitClient.Api.Users.Create(ctx, userCreate)
assert.Error(t, err)
Expand Down

0 comments on commit 5510071

Please sign in to comment.