Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Veeam non-immutable policy support #702

Merged
merged 1 commit into from
Dec 11, 2023
Merged
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
2 changes: 2 additions & 0 deletions src/js/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {

//Subject Under Testing
const SUT = jest.fn();
export const PolicySUT = jest.fn();
const instanceId = INSTANCE_ID;
const accountName = 'Veeam';
const accountNameAlreadyExist = 'Veeam-Account-Error';
Expand Down Expand Up @@ -256,6 +257,7 @@ export const getVeeamMutationHandler = () => [
),
);
}
PolicySUT(decodeURIComponent(req.body as string));
return res(
ctx.status(200),
ctx.xml(
Expand Down
28 changes: 28 additions & 0 deletions src/react/ui-elements/Veeam/VeeamConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,31 @@ export const unitChoices = {
};
export const VEEAM_OBJECT_KEY = `${VEEAM_XML_PREFIX}/capacity.xml`;
export const VEEAM_SYSTEM_KEY = `${VEEAM_XML_PREFIX}/system.xml`;
export const GET_VEEAM_NON_IMMUTABLE_POLICY = (bucketName: string) =>
JSON.stringify({
Version: '2012-10-17',
Statement: [
{
Sid: 'SecureBucketPolicy0',
Effect: 'Allow',
Action: [
's3:PutObject',
's3:GetObject',
's3:DeleteObject',
's3:GetBucketLocation',
's3:GetBucketVersioning',
's3:GetBucketObjectLockConfiguration',
],
Resource: [
`arn:aws:s3:::${bucketName}/*`,
`arn:aws:s3:::${bucketName}`,
],
},
{
Sid: 'SecureBucketPolicy1',
Effect: 'Allow',
Action: ['s3:ListAllMyBuckets', 's3:ListBucket'],
Resource: '*',
},
],
});
29 changes: 29 additions & 0 deletions src/react/ui-elements/Veeam/VeeamTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { setupServer } from 'msw/node';
import {
bucketName,
getVeeamMutationHandler,
PolicySUT,
} from '../../../js/mutations.test';
import { getConfigOverlay } from '../../../js/mock/managementClientMSWHandlers';
import { INSTANCE_ID } from '../../actions/__tests__/utils/testUtil';
import Configuration from './VeeamConfiguration';
import userEvent from '@testing-library/user-event';
import { rest } from 'msw';
import { GET_VEEAM_NON_IMMUTABLE_POLICY } from './VeeamConstants';

const VeeamVBOActions = [
'Create an Account',
Expand Down Expand Up @@ -74,6 +76,8 @@ describe('VeeamTable', () => {
screen.getByRole('option', {
name: /Veeam Backup for Microsoft Office 365/i,
}),
immutableBackupToggle: () =>
screen.getByRole('checkbox', { name: /Active/i }),
};

const setupTest = () => {
Expand Down Expand Up @@ -216,4 +220,29 @@ describe('VeeamTable', () => {
//V
await verifySuccessActions(VeeamVBOActions);
});

it('should get non immutable policy when immutable backup is not selected', async () => {
//Setup
server.resetHandlers(...goodHandlers);
setupTest();
//Exercise
//type the bucket name in configuration form
userEvent.type(selectors.setBucketName(), bucketName);
userEvent.click(selectors.immutableBackupToggle());

await waitFor(() => {
expect(selectors.continueButton()).toBeEnabled();
expect(selectors.immutableBackupToggle()).not.toBeChecked();
});
userEvent.click(selectors.continueButton());
//V
await verifySuccessActions(mutationActions);
await waitFor(() => {
expect(PolicySUT).toHaveBeenCalledWith(
`Action=CreatePolicy&PolicyDocument=${GET_VEEAM_NON_IMMUTABLE_POLICY(
bucketName,
)}&PolicyName=veeam-veeam&Version=2010-05-08`,
);
});
});
});
7 changes: 4 additions & 3 deletions src/react/ui-elements/Veeam/useMutationTableData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
BUCKET_TAG_VEEAM_APPLICATION,
GET_CAPACITY_XML_CONTENT,
GET_VEEAM_IMMUTABLE_POLICY,
GET_VEEAM_NON_IMMUTABLE_POLICY,
SYSTEM_XML_CONTENT,
VEEAM_BACKUP_REPLICATION_XML_VALUE,
VEEAM_XML_PREFIX,
Expand Down Expand Up @@ -146,9 +147,9 @@ export const useMutationTableData = ({
} else if (isStep('Create Veeam policy')) {
return {
policyName: `${propsConfiguration.bucketName}-veeam`,
policyDocument: GET_VEEAM_IMMUTABLE_POLICY(
propsConfiguration.bucketName,
),
policyDocument: propsConfiguration.enableImmutableBackup
? GET_VEEAM_IMMUTABLE_POLICY(propsConfiguration.bucketName)
: GET_VEEAM_NON_IMMUTABLE_POLICY(propsConfiguration.bucketName),
};
} else if (isStep('Attach Veeam policy to User')) {
return {
Expand Down
Loading