Skip to content

Commit

Permalink
Fix creating system admin rolebinding with no resource is not allowed (
Browse files Browse the repository at this point in the history
  • Loading branch information
HaniAlshikh committed Sep 21, 2022
1 parent 16b0397 commit 77314fc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion api/domain/commanddata/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ message CreateUserRoleBindingCommandData {
// Unique identifier of the affected resource within scope (UUID 128-bit
// number)
google.protobuf.StringValue resource = 4
[ (validate.rules).string.uuid = true ];
[ (validate.rules).string = {ignore_empty: true, uuid: true} ];
}

// Command data to update a user
Expand Down
3 changes: 3 additions & 0 deletions go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ endif
ifeq ($(PROTO_ARCH),arm64)
PROTO_ARCH = aarch_64
endif
ifeq ($(PROTO_ARCH),amd64)
PROTO_ARCH = x86_64
endif
PROTO_ARCH_OS := $(PROTO_OS)-$(PROTO_ARCH)

## Tool Config
Expand Down
32 changes: 16 additions & 16 deletions pkg/api/domain/commanddata/user.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions pkg/api/domain/commanddata/user.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/grpc/middleware/validator/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ var _ = Describe("Test validation rules for user messages", func() {
Expect(err).NotTo(HaveOccurred())
})

It("should allow empty resource id for cases like system admin", func() {
cd.Resource = wrapperspb.String("")
err := cd.Validate()
Expect(err).NotTo(HaveOccurred())
})

It("should check for a valid UserId", func() {
cd.UserId = invalidUUID
ValidateErrorExpected()
Expand Down

0 comments on commit 77314fc

Please sign in to comment.