Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge 9859ee0 into 8b73fd4
Browse files Browse the repository at this point in the history
  • Loading branch information
MBtea authored Jul 1, 2021
2 parents 8b73fd4 + 9859ee0 commit 0999324
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ describe('UpgradeToUserId', () => {
});

describe('Run post deployment step', () => {
it('should successful update policy', async () => {
it('should successful update policy without stack policy', async () => {
service.cfn.getStackPolicy = jest.fn(() => ({
promise: () => Promise.resolve({}),
}));
service.cfn.setStackPolicy = jest.fn(() => ({
promise: () => Promise.resolve({}),
}));
await service.execute();
expect(service.cfn.getStackPolicy).toHaveBeenCalledTimes(1);
expect(service.cfn.setStackPolicy).toHaveBeenCalledWith({
StackName: 'backendStackName',
StackPolicyBody:
'{"Statement":[{"Effect":"Allow","Action":"Update:*","Principal":"*","Resource":"*"},{"Effect":"Deny","Action":"Update:Delete","Principal":"*","Resource":"LogicalResourceId/EgressStore*"}]}',
});
});
it('should successful update policy with empty stack policy', async () => {
service.cfn.getStackPolicy = jest.fn(() => ({
promise: () =>
Promise.resolve({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ class UpdateCfnStackPolicy extends Service {
// fetch the current cloudformation stack policy
const backendStackName = this.settings.get(settingKeys.backendStackName);
const currentStackPolicy = await this.cfn.getStackPolicy({ StackName: backendStackName }).promise();
const currentStackPolicyBody = JSON.parse(currentStackPolicy.StackPolicyBody);
let isEmptyPolicy = _.isEmpty(currentStackPolicyBody);
const tempStackPolicyBody = currentStackPolicy.StackPolicyBody;
let isEmptyPolicy = _.isEmpty(tempStackPolicyBody);
let currentStackPolicyBody = {};
if (!isEmptyPolicy) {
currentStackPolicyBody = JSON.parse(tempStackPolicyBody);
}
if (!currentStackPolicyBody.Statement) {
currentStackPolicyBody.Statement = [];
}
Expand Down

0 comments on commit 0999324

Please sign in to comment.