Skip to content

Commit 2ca59f1

Browse files
fix(okms): kmip public ca button downloads the wrong file
ref: #MANAGER-18832 Signed-off-by: Mathieu Mousnier <[email protected]>
1 parent cc77566 commit 2ca59f1

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

packages/manager/apps/okms/src/components/dashboard/downloadKmsPublicCaLink/DownloadKmsPublicCaLink.spec.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,30 @@ describe('DownloadKmsPublicCaLink component tests suite', () => {
7777
const buttons: {
7878
type: CertificateType;
7979
label: string;
80+
expectedCa: 'publicCA' | 'publicRsaCA';
81+
expectedFilename: string;
82+
expectedCertificate: string;
8083
}[] = [
8184
{
8285
type: 'publicCaRest',
8386
label: 'key_management_service_dashboard_button_label_download_ca',
87+
expectedCa: 'publicCA',
88+
expectedFilename: 'okms_test-region_public_ca.pem',
89+
expectedCertificate: mockCertificates.publicCA,
8490
},
8591
{
8692
type: 'publicCaKmip',
8793
label: 'key_management_service_dashboard_button_label_download_ca',
94+
expectedCa: 'publicCA',
95+
expectedFilename: 'okms_test-region_public_ca.pem',
96+
expectedCertificate: mockCertificates.publicCA,
8897
},
8998
{
9099
type: 'publicCaRsaKmip',
91100
label: 'key_management_service_dashboard_button_label_download_rsa_ca',
101+
expectedCa: 'publicRsaCA',
102+
expectedFilename: 'okms_test-region_public_rsa_ca.pem',
103+
expectedCertificate: mockCertificates.publicRsaCA,
92104
},
93105
];
94106

@@ -103,26 +115,29 @@ describe('DownloadKmsPublicCaLink component tests suite', () => {
103115
},
104116
);
105117

106-
test('should download publicCa certificate when clicked', async () => {
107-
const { downloadLink } = await renderComponentAndGetLink({
108-
type: 'publicCaRest',
109-
label: 'key_management_service_dashboard_button_label_download_ca',
110-
});
118+
test.each(buttons)(
119+
'should download $expectedCa certificate when clicked on $type button',
120+
async ({ type, label, expectedFilename, expectedCertificate }) => {
121+
const { downloadLink } = await renderComponentAndGetLink({
122+
type,
123+
label,
124+
});
111125

112-
const user = userEvent.setup();
113-
await waitFor(() => user.click(downloadLink));
126+
const user = userEvent.setup();
127+
await waitFor(() => user.click(downloadLink));
114128

115-
await waitFor(() => {
116-
expect(api.getOkmsPublicCa).toHaveBeenCalledWith(mockOkms.id);
117-
});
129+
await waitFor(() => {
130+
expect(api.getOkmsPublicCa).toHaveBeenCalledWith(mockOkms.id);
131+
});
118132

119-
await waitFor(() => {
120-
expect(initiateTextFileDownload).toHaveBeenCalledWith({
121-
text: mockCertificates.publicCA,
122-
filename: 'okms_test-region_public_ca.pem',
133+
await waitFor(() => {
134+
expect(initiateTextFileDownload).toHaveBeenCalledWith({
135+
text: expectedCertificate,
136+
filename: expectedFilename,
137+
});
123138
});
124-
});
125-
});
139+
},
140+
);
126141

127142
test('should download publicRsaCa certificate when clicked', async () => {
128143
const { downloadLink } = await renderComponentAndGetLink({

packages/manager/apps/okms/src/components/dashboard/downloadKmsPublicCaLink/DownloadKmsPublicCaLink.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
PUBLIC_CA_FILENAME,
1515
PUBLIC_RSA_CA_FILENAME,
1616
} from './downloadKmsPublicCaLink.constants';
17-
import { OKMS } from '@/types/okms.type';
17+
import { OKMS, OkmsPublicCa } from '@/types/okms.type';
1818

1919
export type CertificateType =
2020
| 'publicCaRest'
@@ -24,6 +24,7 @@ export type CertificateType =
2424
type ButtonResource = {
2525
label: string;
2626
filename: string;
27+
certificateType: keyof OkmsPublicCa;
2728
tracking: string;
2829
};
2930

@@ -45,16 +46,19 @@ export const DownloadKmsPublicCaLink = ({
4546
publicCaRest: {
4647
label: t('key_management_service_dashboard_button_label_download_ca'),
4748
filename: PUBLIC_CA_FILENAME,
49+
certificateType: 'publicCA',
4850
tracking: 'download_rest-api-endpoint-ca',
4951
},
5052
publicCaKmip: {
5153
label: t('key_management_service_dashboard_button_label_download_ca'),
52-
filename: PUBLIC_RSA_CA_FILENAME,
54+
filename: PUBLIC_CA_FILENAME,
55+
certificateType: 'publicCA',
5356
tracking: 'download_kmip-endpoint-ca',
5457
},
5558
publicCaRsaKmip: {
5659
label: t('key_management_service_dashboard_button_label_download_rsa_ca'),
5760
filename: PUBLIC_RSA_CA_FILENAME,
61+
certificateType: 'publicRsaCA',
5862
tracking: 'download_kmip-endpoint-ca-rsa',
5963
},
6064
};
@@ -68,14 +72,8 @@ export const DownloadKmsPublicCaLink = ({
6872
setLoading(true);
6973
const certificates = await getOkmsPublicCa(okms.id);
7074

71-
const content: Record<CertificateType, string> = {
72-
publicCaRest: certificates.publicCA,
73-
publicCaKmip: certificates.publicRsaCA,
74-
publicCaRsaKmip: certificates.publicRsaCA,
75-
};
76-
7775
initiateTextFileDownload({
78-
text: content[type],
76+
text: certificates[resources[type].certificateType],
7977
filename: resources[type].filename.replace('{region}', okms.region),
8078
});
8179

0 commit comments

Comments
 (0)