Skip to content

Commit

Permalink
fix(manager-react-component): fix IAM check for urn with / (#13394)
Browse files Browse the repository at this point in the history
ref: #13392

Signed-off-by: Nicolas Pierre-charles <[email protected]>
  • Loading branch information
chipp972 authored Oct 22, 2024
1 parent 22ff9d8 commit 619f7d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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',
);
});
});
13 changes: 7 additions & 6 deletions packages/manager-react-components/src/hooks/iam/useOvhIam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IamCheckResponse> => {
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(
Expand Down

0 comments on commit 619f7d8

Please sign in to comment.