-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kms): servicekey list ti implementation
ref: MANAGER-16001 Signed-off-by: Vincent BONMARCHAND <[email protected]>
- Loading branch information
Showing
10 changed files
with
429 additions
and
8 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/manager/apps/key-management-service/src/mocks/iam/iam.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { IamCheckResponse } from '@ovh-ux/manager-react-components'; | ||
import { kmsIamActions } from '@/utils/iam/iam.constants'; | ||
import { okmsMock } from '../kms/okms.mock'; | ||
import { serviceKeyMock } from '../serviceKeys/serviceKeys.mock'; | ||
|
||
export const kmsIamMock: IamCheckResponse[] = [ | ||
{ | ||
urn: okmsMock[0].iam.urn, | ||
authorizedActions: [...Object.values(kmsIamActions)], | ||
unauthorizedActions: [], | ||
}, | ||
{ | ||
urn: serviceKeyMock[0].iam.urn, | ||
authorizedActions: [...Object.values(kmsIamActions)], | ||
unauthorizedActions: [], | ||
}, | ||
]; |
27 changes: 27 additions & 0 deletions
27
packages/manager/apps/key-management-service/src/mocks/reference/reference.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Handler } from '../../../../../../../playwright-helpers'; | ||
import { referenceServiceKeyMock } from './reference.mock'; | ||
|
||
export type GetReferenceMockParams = { | ||
isReferenceKO?: boolean; | ||
}; | ||
|
||
export const getReferenceMock = ({ | ||
isReferenceKO, | ||
}: GetReferenceMockParams): Handler[] => [ | ||
{ | ||
url: '/okms/reference/serviceKey', | ||
response: isReferenceKO | ||
? { | ||
status: 500, | ||
data: { | ||
message: 'serviceKeys error', | ||
}, | ||
} | ||
: () => { | ||
console.log(referenceServiceKeyMock); | ||
return referenceServiceKeyMock; | ||
}, | ||
status: isReferenceKO ? 500 : 200, | ||
api: 'v2', | ||
}, | ||
]; |
53 changes: 53 additions & 0 deletions
53
packages/manager/apps/key-management-service/src/mocks/reference/reference.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
OkmsKeyTypes, | ||
OkmsServiceKeyOperations, | ||
OkmsServiceKeyTypeOctSize, | ||
} from '@/types/okmsServiceKey.type'; | ||
import OkmsServiceKeyReference, { | ||
OkmsServiceKeyReferenceSize, | ||
} from '@/types/okmsServiceKeyReference.type'; | ||
|
||
export const referenceServiceKeyMock: OkmsServiceKeyReference[] = [ | ||
{ | ||
sizes: [ | ||
{ value: 128, default: false }, | ||
{ value: 192, default: false }, | ||
{ value: 256, default: true }, | ||
] as OkmsServiceKeyReferenceSize[], | ||
type: OkmsKeyTypes.oct, | ||
default: true, | ||
operations: [ | ||
{ | ||
value: [ | ||
OkmsServiceKeyOperations.encrypt, | ||
OkmsServiceKeyOperations.decrypt, | ||
], | ||
default: true, | ||
}, | ||
{ | ||
value: [ | ||
OkmsServiceKeyOperations.wrapKey, | ||
OkmsServiceKeyOperations.unwrapKey, | ||
], | ||
default: false, | ||
}, | ||
], | ||
curves: [], | ||
}, | ||
{ | ||
sizes: [], | ||
type: OkmsKeyTypes.EC, | ||
default: false, | ||
operations: [ | ||
{ | ||
value: [OkmsServiceKeyOperations.sign, OkmsServiceKeyOperations.verify], | ||
default: true, | ||
}, | ||
], | ||
curves: [ | ||
{ default: true, value: 'P-256' }, | ||
{ default: false, value: 'P-384' }, | ||
{ default: false, value: 'P-521' }, | ||
], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
...ps/key-management-service/src/pages/dashboard/serviceKeyList/ServiceKeyList.page.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import { act, fireEvent, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { renderTestApp } from '@/utils/tests/renderTestApp'; | ||
import '@testing-library/jest-dom'; | ||
import { labels } from '@/utils/tests/init.i18n'; | ||
import { okmsMock } from '@/mocks/kms/okms.mock'; | ||
import { serviceKeyMock } from '@/mocks/serviceKeys/serviceKeys.mock'; | ||
|
||
describe('Service Key list test suite', () => { | ||
it('should display an error if the API is KO', async () => { | ||
await renderTestApp(`/${okmsMock[0].id}/keys`, { | ||
isServiceKeyKO: true, | ||
}); | ||
|
||
await waitFor( | ||
() => expect(screen.getByAltText('OOPS')).toBeInTheDocument(), | ||
{ | ||
timeout: 30_000, | ||
}, | ||
); | ||
}); | ||
|
||
it('should display the kms keys listing page', async () => { | ||
await renderTestApp(`/${okmsMock[0].id}/keys`); | ||
|
||
await waitFor( | ||
() => | ||
expect( | ||
screen.getByText( | ||
labels.serviceKeys['key_management_service_service-keys_headline'], | ||
), | ||
).toBeVisible(), | ||
|
||
{ timeout: 30_000 }, | ||
); | ||
|
||
expect(screen.queryByAltText('OOPS')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it(`should navigate to the service key page creation on click on ${labels.serviceKeys['key_management_service_service-keys_cta_create']} and then create a key `, async () => { | ||
const user = userEvent.setup(); | ||
await renderTestApp(`/${okmsMock[0].id}/keys`); | ||
await waitFor( | ||
() => | ||
expect( | ||
screen.getAllByText( | ||
labels.serviceKeys['key_management_service_service-keys_headline'], | ||
{ exact: false }, | ||
).length, | ||
).toBeGreaterThan(0), | ||
{ timeout: 30_000 }, | ||
); | ||
await waitFor( | ||
() => | ||
expect( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_title' | ||
], | ||
), | ||
).toBeEnabled(), | ||
{ | ||
timeout: 30_000, | ||
}, | ||
); | ||
|
||
await act(() => | ||
user.click( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_title' | ||
], | ||
), | ||
), | ||
); | ||
|
||
await waitFor( | ||
() => | ||
expect( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_crypto_field_type_description_oct' | ||
], | ||
), | ||
).toBeVisible(), | ||
{ timeout: 30_000 }, | ||
); | ||
await waitFor( | ||
() => | ||
expect( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_crypto_field_usage_description_encrypt_decrypt' | ||
], | ||
), | ||
).toBeVisible(), | ||
{ timeout: 30_000 }, | ||
); | ||
const keyNameInput = screen.getByPlaceholderText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_general_information_field_name_placeholder' | ||
], | ||
); | ||
await act(() => { | ||
fireEvent.change(keyNameInput, { target: { value: '' } }); | ||
fireEvent.change(keyNameInput, { | ||
target: { value: 'New Key' }, | ||
}); | ||
}); | ||
await waitFor( | ||
() => | ||
expect( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_cta_submit' | ||
], | ||
), | ||
).toBeEnabled(), | ||
{ | ||
timeout: 30_000, | ||
}, | ||
); | ||
|
||
await act(() => | ||
user.click( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_cta_submit' | ||
], | ||
), | ||
), | ||
); | ||
await waitFor( | ||
() => | ||
expect( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_create_success' | ||
], | ||
), | ||
).toBeEnabled(), | ||
{ | ||
timeout: 30_000, | ||
}, | ||
); | ||
}); | ||
|
||
it('should navigate to the service key dashboard page after clicking on a key from the listing', async () => { | ||
await renderTestApp(`/${okmsMock[0].id}/keys`); | ||
|
||
await waitFor( | ||
() => | ||
expect( | ||
screen.getAllByText( | ||
labels.serviceKeys['key_management_service_service-keys_headline'], | ||
{ exact: false }, | ||
).length, | ||
).toBeGreaterThan(0), | ||
{ timeout: 30_000 }, | ||
); | ||
|
||
await waitFor( | ||
() => | ||
userEvent.click(screen.getByText(serviceKeyMock[0].iam.displayName)), | ||
{ | ||
timeout: 30_000, | ||
}, | ||
); | ||
await waitFor( | ||
() => | ||
expect( | ||
screen.getByText( | ||
labels.serviceKeys[ | ||
'key_management_service_service-keys_dashboard_tab_informations' | ||
], | ||
), | ||
).toBeVisible(), | ||
{ | ||
timeout: 30_000, | ||
}, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.