From 739158b130bbc3fc3c5e3f7dce42ddcab4348da1 Mon Sep 17 00:00:00 2001 From: "Chang, Hui-Tang" Date: Wed, 6 Dec 2023 12:41:32 +0800 Subject: [PATCH] fix bug --- integration-test/grpc-public-user.js | 2 +- pkg/handler/publichandler.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/integration-test/grpc-public-user.js b/integration-test/grpc-public-user.js index 3d553ac..f03c263 100644 --- a/integration-test/grpc-public-user.js +++ b/integration-test/grpc-public-user.js @@ -127,7 +127,7 @@ export function CheckPublicPatchAuthenticatedUser(header) { user: userUpdate, update_mask: "role" }, header), { - 'core.mgmt.v1beta.MgmtPublicService/PatchAuthenticatedUser nonExistRole StatusInvalidArgument': (r) => {console.log(r); return r && r.status == grpc.StatusInvalidArgument}, + 'core.mgmt.v1beta.MgmtPublicService/PatchAuthenticatedUser nonExistRole StatusInvalidArgument': (r) => r.status == grpc.StatusInvalidArgument, }); }); diff --git a/pkg/handler/publichandler.go b/pkg/handler/publichandler.go index 75221b2..e3dc37e 100644 --- a/pkg/handler/publichandler.go +++ b/pkg/handler/publichandler.go @@ -206,6 +206,9 @@ func (h *PublicHandler) GetUser(ctx context.Context, req *mgmtPB.GetUserRequest) return nil, err } userID := strings.Split(req.Name, "/")[1] + if userID == "me" && ctxUserID == "" { + return nil, service.ErrUnauthenticated + } if userID == "me" { userID = ctxUserID } @@ -1252,6 +1255,9 @@ func (h *PublicHandler) ListUserMemberships(ctx context.Context, req *mgmtPB.Lis return nil, err } userID := strings.Split(req.Parent, "/")[1] + if userID == "me" && ctxUserID == "" { + return nil, service.ErrUnauthenticated + } if userID == "me" { userID = ctxUserID } @@ -1294,6 +1300,9 @@ func (h *PublicHandler) GetUserMembership(ctx context.Context, req *mgmtPB.GetUs span.SetStatus(1, err.Error()) return nil, err } + if userID == "me" && ctxUserID == "" { + return nil, service.ErrUnauthenticated + } if userID == "me" { userID = ctxUserID } @@ -1337,6 +1346,9 @@ func (h *PublicHandler) UpdateUserMembership(ctx context.Context, req *mgmtPB.Up span.SetStatus(1, err.Error()) return nil, err } + if userID == "me" && ctxUserID == "" { + return nil, service.ErrUnauthenticated + } if userID == "me" { userID = ctxUserID } @@ -1388,6 +1400,9 @@ func (h *PublicHandler) DeleteUserMembership(ctx context.Context, req *mgmtPB.De span.SetStatus(1, err.Error()) return nil, err } + if userID == "me" && ctxUserID == "" { + return nil, service.ErrUnauthenticated + } if userID == "me" { userID = ctxUserID }