From 1ad00b345d4fb9f628d8a474cbd42373bb57f103 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Thu, 7 Mar 2024 15:48:59 +0800 Subject: [PATCH 1/2] fix: authInfo destructure Signed-off-by: SuZhou-Joe --- src/plugins/workspace/server/utils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/workspace/server/utils.ts b/src/plugins/workspace/server/utils.ts index e51637cd49c3..740dd63ee69f 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; } From a767225606a5f994d7ddd1a2259912b0db6350fa Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Thu, 7 Mar 2024 15:53:28 +0800 Subject: [PATCH 2/2] fix: unit test error Signed-off-by: SuZhou-Joe --- src/plugins/workspace/server/utils.test.ts | 12 ++++++++---- src/plugins/workspace/server/utils.ts | 4 ++-- 2 files changed, 10 insertions(+), 6 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 740dd63ee69f..1c8d73953afa 100644 --- a/src/plugins/workspace/server/utils.ts +++ b/src/plugins/workspace/server/utils.ts @@ -35,10 +35,10 @@ export const getPrincipalsFromRequest = ( if (authInfoResp?.status === AuthStatus.authenticated) { const authInfo = authInfoResp?.state as { authInfo: AuthInfo } | null; - if (authInfo?.authInfo.backend_roles) { + if (authInfo?.authInfo?.backend_roles) { payload[PrincipalType.Groups] = authInfo.authInfo.backend_roles; } - if (authInfo?.authInfo.user_name) { + if (authInfo?.authInfo?.user_name) { payload[PrincipalType.Users] = [authInfo.authInfo.user_name]; } return payload;