Skip to content

Commit

Permalink
auth: ensure RoleGrantPermission is compatible with older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcong committed Mar 22, 2020
1 parent 0eee733 commit bbe4750
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
10 changes: 0 additions & 10 deletions auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,16 +800,6 @@ func (as *authStore) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (
})

if idx < len(role.KeyPermission) && bytes.Equal(role.KeyPermission[idx].Key, r.Perm.Key) && bytes.Equal(role.KeyPermission[idx].RangeEnd, r.Perm.RangeEnd) {
if role.KeyPermission[idx].PermType == r.Perm.PermType {
as.lg.Warn(
"ignored grant permission request to a role, existing permission",
zap.String("role-name", r.Name),
zap.ByteString("key", r.Perm.Key),
zap.ByteString("range-end", r.Perm.RangeEnd),
zap.String("permission-type", authpb.Permission_Type_name[int32(r.Perm.PermType)]),
)
return &pb.AuthRoleGrantPermissionResponse{}, nil
}
// update existing permission
role.KeyPermission[idx].PermType = r.Perm.PermType
} else {
Expand Down
6 changes: 4 additions & 2 deletions auth/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,10 @@ func TestRoleGrantPermissionRevision(t *testing.T) {
}
newRevision := as.Revision()

if oldRevision != newRevision {
t.Errorf("expected revision diff is 0, got %d", newRevision-oldRevision)
diff := newRevision - oldRevision

if diff != 1 {
t.Errorf("expected revision diff is 1, got %d", diff)
}
}

Expand Down

0 comments on commit bbe4750

Please sign in to comment.