From f7009e6c081831156579e0f7be2f12d34f135d9a Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 15 Mar 2024 10:05:47 +0800 Subject: [PATCH] fix: authInfo destructure (#7) (#296) * fix: authInfo destructure * fix: unit test error --------- Signed-off-by: SuZhou-Joe --- src/plugins/workspace/server/utils.test.ts | 12 ++++++++---- src/plugins/workspace/server/utils.ts | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/plugins/workspace/server/utils.test.ts b/src/plugins/workspace/server/utils.test.ts index 5af40eea9b06..1f6c3e58f122 100644 --- a/src/plugins/workspace/server/utils.test.ts +++ b/src/plugins/workspace/server/utils.test.ts @@ -27,8 +27,10 @@ describe('workspace utils', () => { mockAuth.get.mockReturnValueOnce({ status: AuthStatus.unknown, state: { - user_name: 'bar', - backend_roles: ['foo'], + authInfo: { + user_name: 'bar', + backend_roles: ['foo'], + }, }, }); const result = getPrincipalsFromRequest(mockRequest, mockAuth); @@ -40,8 +42,10 @@ describe('workspace utils', () => { mockAuth.get.mockReturnValueOnce({ status: AuthStatus.authenticated, state: { - user_name: 'bar', - backend_roles: ['foo'], + authInfo: { + user_name: 'bar', + backend_roles: ['foo'], + }, }, }); const result = getPrincipalsFromRequest(mockRequest, mockAuth); diff --git a/src/plugins/workspace/server/utils.ts b/src/plugins/workspace/server/utils.ts index e51637cd49c3..1c8d73953afa 100644 --- a/src/plugins/workspace/server/utils.ts +++ b/src/plugins/workspace/server/utils.ts @@ -34,12 +34,12 @@ export const getPrincipalsFromRequest = ( } if (authInfoResp?.status === AuthStatus.authenticated) { - const authInfo = authInfoResp?.state as AuthInfo | null; - if (authInfo?.backend_roles) { - payload[PrincipalType.Groups] = authInfo.backend_roles; + const authInfo = authInfoResp?.state as { authInfo: AuthInfo } | null; + if (authInfo?.authInfo?.backend_roles) { + payload[PrincipalType.Groups] = authInfo.authInfo.backend_roles; } - if (authInfo?.user_name) { - payload[PrincipalType.Users] = [authInfo.user_name]; + if (authInfo?.authInfo?.user_name) { + payload[PrincipalType.Users] = [authInfo.authInfo.user_name]; } return payload; }