Skip to content

Commit

Permalink
fix: authInfo destructure (#7) (opensearch-project#296)
Browse files Browse the repository at this point in the history
* fix: authInfo destructure



* fix: unit test error



---------

Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Mar 18, 2024
1 parent d287778 commit 93a6585
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/plugins/workspace/server/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/workspace/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 93a6585

Please sign in to comment.