Skip to content

Commit

Permalink
feat(kms): servicekey list ti implementation
Browse files Browse the repository at this point in the history
ref: MANAGER-16001

Signed-off-by: Vincent BONMARCHAND <[email protected]>
  • Loading branch information
vovh committed Dec 6, 2024
1 parent ee5c8cc commit 8c4bd71
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 8 deletions.
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: [],
},
];
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',
},
];
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' },
],
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export type GetServiceKeysMockParams = {
nbServiceKey?: number;
};

const findOkmsById = (params: PathParams) =>
serviceKeyMock.find(({ id }) => id === params.id);
const findServiceKeyById = (params: PathParams) =>
serviceKeyMock.find(({ id }) => id === params.serviceKeyId);

export const getServiceKeysMock = ({
isServiceKeyKO,
Expand All @@ -23,16 +23,32 @@ export const getServiceKeysMock = ({
message: 'serviceKeys error',
},
}
: (_: unknown, params: PathParams) => findOkmsById(params),
: serviceKeyMock.slice(0, nbServiceKey),
status: isServiceKeyKO ? 500 : 200,
api: 'v2',
},
{
url: '/okms/resource/:okmsId/serviceKey/:serviceKeyId',
response: isServiceKeyKO
? { message: 'serviceKey error' }
: serviceKeyMock.slice(0, nbServiceKey),
: (_: unknown, params: PathParams) => findServiceKeyById(params),
status: isServiceKeyKO ? 500 : 200,
api: 'v2',
},
{
url: '/okms/resource/:okmsId/serviceKey/:serviceKeyId',
method: 'put',
response: (_: unknown, params: PathParams) => findServiceKeyById(params),
status: 200,
api: 'v2',
},
{
url: '/okms/resource/:okmsId/serviceKey',
method: 'post',
response: (_: unknown, params: PathParams) => {
findServiceKeyById(params);
},
status: 200,
api: 'v2',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

export const serviceKeyMock: OkmsAllServiceKeys[] = [
{
name: 'ServiceKeyTest',
createdAt: '2024-10-23T15:24:23Z',
id: '8f8a75b0-3bde-4b8d-a8c0-928ba2ceb8ed',
operations: [
Expand All @@ -17,10 +18,26 @@ export const serviceKeyMock: OkmsAllServiceKeys[] = [
type: OkmsKeyTypes.EC,
curve: 'P-256',
iam: {
id: '8f8a75b0-3bde-4b8d-a8c0-928basvced',
id: '8f8a75b0-3bde-4b8d-a8c0-928ba2ceb8ed',
urn:
'urn:v1:eu:resource:okms:8f8a75b0-b57d-45fc-8d4f-256664DFE/serviceKey/dqd63-5688-409c-234-125e24538f34',
'urn:v1:eu:resource:okms:7f3a82ac-a8d8-4c2a-ab0c-f6e86ddf6a7c/serviceKey/8f8a75b0-3bde-4b8d-a8c0-928ba2ceb8ed',
displayName: 'ServiceKeyTest',
},
},
];

export const createdKeyMock: OkmsAllServiceKeys = {
name: 'New Key',
createdAt: '2024-10-23T15:24:23Z',
id: '4575b0-3bde-4b8d-a8c0-928ba2ceb8ed',
operations: [OkmsServiceKeyOperations.sign, OkmsServiceKeyOperations.verify],
state: OkmsServiceKeyState.active,
type: OkmsKeyTypes.EC,
curve: 'P-256',
iam: {
id: '4575b0-3bde-4b8d-a8c0-928ba2ceb8ed',
urn:
'urn:v1:eu:resource:okms:7f3a82ac-a8d8-4c2a-ab0c-f6e86ddf6a7c/serviceKey/4575b0-3bde-4b8d-a8c0-928ba2ceb8ed',
displayName: 'New Key',
},
};
Loading

0 comments on commit 8c4bd71

Please sign in to comment.