Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/manager/apps/okms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"build": "tsc && vite build",
"lint:check": "eslint --ext .ts,.tsx . && tsc --noEmit",
"start": "tsc && vite",
"test": "vitest run --reporter=verbose",
"test:coverage": "vitest run --coverage"
"test": "manager-test run --reporter=verbose",
"test:coverage": "manager-test run --coverage"
},
"dependencies": {
"@hookform/resolvers": "5.2.1",
Expand Down Expand Up @@ -49,18 +49,14 @@
},
"devDependencies": {
"@ovh-ux/manager-core-test-utils": "^0.7.7",
"@ovh-ux/manager-tests-setup": "latest",
"@ovh-ux/manager-vite-config": "^0.13.4",
"@tanstack/react-query-devtools": "^5.51.21",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/file-saver": "^2.0.7",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/coverage-v8": "^2.1.9",
"element-internals-polyfill": "^3.0.2",
"msw": "2.1.7",
"typescript": "^5.1.6",
"vitest": "^2.1.9"
"typescript": "^5.1.6"
},
"regions": [
"CA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@
"delete_secret_success": "Votre secret a été supprimé avec succès",
"delete_version_modal_description": "Êtes-vous sûr de vouloir supprimer cette version ? Cette action est irréversible.",
"delete_version_modal_title": "Supprimer la version {{versionId}}",
"edit_metadata": "Modifier les paramètres",
"okms_activation_in_progress": "Veuillez patienter, création en cours.",
"okms_list": "Liste de domaines OKMS",
"editor": "Éditeur JSON",
"error_invalid_json": "JSON non valide",
"error_path_allowed_characters": "Le path ne peut contenir que les caractères suivants: A-Z a-z 0-9 . _ : / = @ et -",
"error_path_structure": "Le path ne peut commencer ou finir par '/', ni contenir deux '/' à la suite.",
"error_invalid_duration": "La durée d'expiration doit être une durée (ex: 30s, 5m, 2h, 7d, 7d1h30m10s)",
"error_update_settings": "Une erreur est survenue lors de la mise à jour des paramètres",
"expiration_date": "Date d'expiration",
"form_helper_cas_required_okms": "CAS est activé sur le domaine OKMS, la désactivation sur le secret ne sera pas prise en compte.",
"form_helper_deactivate_version_after": "Indiquez \"0s\" pour désactiver l'expiration.",
"form_helper_max_versions": "Indiquez \"0\" pour utiliser la valeur par défaut ({{default}}).",
"form_tooltip_deactivate_version_after": "Format : 30s, 5m, 2h, 7d, 7d1h30m10s",
"last_update": "Dernière mise à jour",
"maximum_number_of_versions": "Nombre maximum de versions",
"never_expire": "Pas d'expiration",
Expand All @@ -49,6 +56,7 @@
"settings_default": "Paramètres par défaut",
"values": "Valeurs",
"version": "Version",
"current_version": "Version courante",
"version_state_active": "Active",
"version_state_deactivate": "Désactiver",
"version_state_deactivated": "Désactivée",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ import { OkmsServiceState } from '@/components/layout-helpers/Dashboard/okmsServ
import { KMS_ROUTES_URLS } from '@/routes/routes.constants';
import { OkmsDatagridType } from './okmsDatagrid.type';
import { Link } from '@/common/components/Link/Link.component';
import { OKMS_LIST_CELL_TEST_IDS } from './ListingCells.constants';

export const DatagridCellId = (okms: OKMS) => {
return <Clipboard className="w-full" value={okms.id} />;
return (
<Clipboard
className="w-full"
value={okms.id}
data-testid={OKMS_LIST_CELL_TEST_IDS.id(okms.id)}
/>
);
};

export const DatagridCellName = (
Expand All @@ -43,6 +50,7 @@ export const DatagridCellName = (
href={urls[type]}
label={okms.iam.displayName}
isRouterLink
data-testid={OKMS_LIST_CELL_TEST_IDS.name(okms.id)}
onClick={() => {
if (tracking[type].length > 0) {
trackClick({
Expand All @@ -59,7 +67,7 @@ export const DatagridCellName = (

export const DatagridCellRegion = (okms: OKMS) => {
return (
<DataGridTextCell>
<DataGridTextCell data-testid={OKMS_LIST_CELL_TEST_IDS.region(okms.id)}>
<Region
mode="region"
name={okms.region.toLowerCase().replaceAll('_', '-')}
Expand All @@ -78,17 +86,38 @@ export const DatagridCellStatus = (okms: OKMS) => {
if (isError) {
return <></>;
}
return <OkmsServiceState state={OkmsServiceInfos.data.resource.state} />;
return (
<OkmsServiceState
state={OkmsServiceInfos.data.resource.state}
data-testid={OKMS_LIST_CELL_TEST_IDS.status(okms.id)}
/>
);
};

export const DatagridCellKmipCount = (okms: OKMS) => {
return <DataGridTextCell>{okms.kmipObjectCount}</DataGridTextCell>;
return (
<DataGridTextCell data-testid={OKMS_LIST_CELL_TEST_IDS.kmipCount(okms.id)}>
{okms.kmipObjectCount}
</DataGridTextCell>
);
};

export const DatagridCellServiceKeyCount = (okms: OKMS) => {
return <DataGridTextCell>{okms.serviceKeyCount}</DataGridTextCell>;
return (
<DataGridTextCell
data-testid={OKMS_LIST_CELL_TEST_IDS.serviceKeyCount(okms.id)}
>
{okms.serviceKeyCount}
</DataGridTextCell>
);
};

export const DatagridCellSecretCount = (okms: OKMS) => {
return <DataGridTextCell>{okms.secretCount}</DataGridTextCell>;
return (
<DataGridTextCell
data-testid={OKMS_LIST_CELL_TEST_IDS.secretCount(okms.id)}
>
{okms.secretCount}
</DataGridTextCell>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const OKMS_LIST_CELL_TEST_IDS = {
id: (id: string) => `okms-list-cell-${id}-id`,
name: (id: string) => `okms-list-cell-${id}-name`,
region: (id: string) => `okms-list-cell-${id}-region`,
status: (id: string) => `okms-list-cell-${id}-status`,
kmipCount: (id: string) => `okms-list-cell-${id}-kmip-count`,
serviceKeyCount: (id: string) => `okms-list-cell-${id}-service-key-count`,
secretCount: (id: string) => `okms-list-cell-${id}-secret-count`,
};
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,21 @@ const clickOnConfirmCheckbox = async () => {
ORDER_OKMS_TC_CONFIRM_CHECKBOX_TEST_ID,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) as any;
await act(() => {
act(() => {
confirmCheckbox.odsChange.emit({
checked: 'true',
});
});
};

const clickOnConfirmButton = async (user: UserEvent) => {
const confirmButton = screen.getByTestId(
ORDER_OKMS_TC_CONFIRM_BUTTON_TEST_ID,
);
// Small wait to ensure state updates
// Fails intermittently without this - button click does not always works
await wait(300);

let confirmButton: HTMLElement;
await waitFor(() => {
confirmButton = screen.getByTestId(ORDER_OKMS_TC_CONFIRM_BUTTON_TEST_ID);
expect(confirmButton).toHaveAttribute('is-disabled', 'false');
});
await act(() => user.click(confirmButton));
Expand Down Expand Up @@ -273,12 +275,10 @@ describe('Order Okms Modal test suite', () => {
);

// WHEN

// THEN - Test loading state
await clickOnConfirmCheckbox();
// Small wait to ensure state updates
// Fails intermittently without this - button click does not always works
await wait(500);
const confirmButton = await clickOnConfirmButton(user);

// THEN - Test loading state
await waitFor(() => {
expect(confirmButton).toHaveAttribute('is-loading', 'true');
Expand All @@ -296,9 +296,6 @@ describe('Order Okms Modal test suite', () => {

// WHEN
await clickOnConfirmCheckbox();
// Small wait to ensure state updates
// Fails intermittently without this - button click does not always works
await wait(500);
await clickOnConfirmButton(user);

// THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ vi.mock('@/utils/dom/download', () => ({
initiateTextFileDownload: vi.fn(),
}));

vi.mock('@ovh-ux/manager-react-shell-client', () => ({
useOvhTracking: () => ({ trackClick: vi.fn() }),
}));

const mockOkms = {
id: 'test-okms-id',
region: 'test-region',
Expand Down Expand Up @@ -55,6 +59,7 @@ const renderComponentAndGetLink = async ({
container,
label,
isLink: true,
timeout: 2000,
});

return { downloadLink };
Expand All @@ -69,46 +74,74 @@ describe('DownloadKmsPublicCaLink component tests suite', () => {
vi.clearAllMocks();
});

test('should render publicCa download link correctly', async () => {
const { downloadLink } = await renderComponentAndGetLink({
type: 'publicCa',
const buttons: {
type: CertificateType;
label: string;
expectedCa: 'publicCA' | 'publicRsaCA';
expectedFilename: string;
expectedCertificate: string;
}[] = [
{
type: 'publicCaRest',
label: 'key_management_service_dashboard_button_label_download_ca',
});
expect(downloadLink).toBeInTheDocument();
});

test('should render publicRsaCa download link correctly', async () => {
const { downloadLink } = await renderComponentAndGetLink({
type: 'publicRsaCa',
expectedCa: 'publicCA',
expectedFilename: 'okms_test-region_public_ca.pem',
expectedCertificate: mockCertificates.publicCA,
},
{
type: 'publicCaKmip',
label: 'key_management_service_dashboard_button_label_download_ca',
expectedCa: 'publicCA',
expectedFilename: 'okms_test-region_public_ca.pem',
expectedCertificate: mockCertificates.publicCA,
},
{
type: 'publicCaRsaKmip',
label: 'key_management_service_dashboard_button_label_download_rsa_ca',
});
expect(downloadLink).toBeInTheDocument();
});
expectedCa: 'publicRsaCA',
expectedFilename: 'okms_test-region_public_rsa_ca.pem',
expectedCertificate: mockCertificates.publicRsaCA,
},
];

test.each(buttons)(
'should render $type download link correctly',
async ({ type, label }) => {
const { downloadLink } = await renderComponentAndGetLink({
type,
label,
});
expect(downloadLink).toBeInTheDocument();
},
);

test('should download publicCa certificate when clicked', async () => {
const { downloadLink } = await renderComponentAndGetLink({
type: 'publicCa',
label: 'key_management_service_dashboard_button_label_download_ca',
});
test.each(buttons)(
'should download $expectedCa certificate when clicked on $type button',
async ({ type, label, expectedFilename, expectedCertificate }) => {
const { downloadLink } = await renderComponentAndGetLink({
type,
label,
});

const user = userEvent.setup();
await waitFor(() => user.click(downloadLink));
const user = userEvent.setup();
await waitFor(() => user.click(downloadLink));

await waitFor(() => {
expect(api.getOkmsPublicCa).toHaveBeenCalledWith(mockOkms.id);
});
await waitFor(() => {
expect(api.getOkmsPublicCa).toHaveBeenCalledWith(mockOkms.id);
});

await waitFor(() => {
expect(initiateTextFileDownload).toHaveBeenCalledWith({
text: mockCertificates.publicCA,
filename: 'okms_test-region_public_ca.pem',
await waitFor(() => {
expect(initiateTextFileDownload).toHaveBeenCalledWith({
text: expectedCertificate,
filename: expectedFilename,
});
});
});
});
},
);

test('should download publicRsaCa certificate when clicked', async () => {
const { downloadLink } = await renderComponentAndGetLink({
type: 'publicRsaCa',
type: 'publicCaRsaKmip',
label: 'key_management_service_dashboard_button_label_download_rsa_ca',
});

Expand All @@ -134,7 +167,7 @@ describe('DownloadKmsPublicCaLink component tests suite', () => {
);

const { downloadLink } = await renderComponentAndGetLink({
type: 'publicCa',
type: 'publicCaRest',
label: 'key_management_service_dashboard_button_label_download_ca',
});

Expand Down
Loading
Loading