Skip to content

Commit

Permalink
Merge pull request #24 from ghostiam/fix_IsGranted_panic
Browse files Browse the repository at this point in the history
fix panic if permission is nil
  • Loading branch information
mikespook authored Jan 9, 2019
2 parents 9833b83 + 4c20fe6 commit a989d0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ func TestRbacPermission(t *testing.T) {
if rbac.IsGranted("role-c", pB, nil) {
t.Fatalf("role-c should not have %s because of the unbinding with role-b", pB)
}

if rbac.IsGranted("role-a", nil, nil) {
t.Fatal("role-a should not have nil permission")
}
}

func BenchmarkRbacGranted(b *testing.B) {
Expand Down
4 changes: 4 additions & 0 deletions role.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (role *StdRole) Assign(p Permission) error {

// Permit returns true if the role has specific permission.
func (role *StdRole) Permit(p Permission) (rslt bool) {
if p == nil {
return false
}

role.RLock()
for _, rp := range role.permissions {
if rp.Match(p) {
Expand Down

0 comments on commit a989d0e

Please sign in to comment.