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(