From 619f7d89f00ee73e48b4f8b419a06403e65cd19b Mon Sep 17 00:00:00 2001 From: Nicode Date: Tue, 22 Oct 2024 11:34:32 +0200 Subject: [PATCH] fix(manager-react-component): fix IAM check for urn with / (#13394) ref: #13392 Signed-off-by: Nicolas Pierre-charles --- .../src/hooks/iam/useOvhIam.spec.ts | 9 +++++++++ .../src/hooks/iam/useOvhIam.tsx | 13 +++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 packages/manager-react-components/src/hooks/iam/useOvhIam.spec.ts diff --git a/packages/manager-react-components/src/hooks/iam/useOvhIam.spec.ts b/packages/manager-react-components/src/hooks/iam/useOvhIam.spec.ts new file mode 100644 index 000000000000..7a8b4f43e7fe --- /dev/null +++ b/packages/manager-react-components/src/hooks/iam/useOvhIam.spec.ts @@ -0,0 +1,9 @@ +import { getAuthorizationCheckUrl } from './useOvhIam'; + +describe('getAuthorizationCheckUrl', () => { + it('encodes the urn if it contains /', () => { + expect(getAuthorizationCheckUrl('test/urn')).toBe( + '/iam/resource/test%2Furn/authorization/check', + ); + }); +}); diff --git a/packages/manager-react-components/src/hooks/iam/useOvhIam.tsx b/packages/manager-react-components/src/hooks/iam/useOvhIam.tsx index 1e87ca390cbb..c03f58511aef 100644 --- a/packages/manager-react-components/src/hooks/iam/useOvhIam.tsx +++ b/packages/manager-react-components/src/hooks/iam/useOvhIam.tsx @@ -27,16 +27,17 @@ export function useAuthorizationsIam({ actions, urns }: IamInterface) { return data || []; } +export function getAuthorizationCheckUrl(urn: string) { + return `/iam/resource/${encodeURIComponent(urn)}/authorization/check`; +} + export const fetchAuthorizationCheck = async ( actions: string[], urn: string, ): Promise => { - const { data } = await apiClient.v2.post( - `/iam/resource/${encodeURIComponent(urn)}/authorization/check`, - { - actions, - }, - ); + const { data } = await apiClient.v2.post(getAuthorizationCheckUrl(urn), { + actions, + }); return data; }; export function useAuthorizationIam(