Skip to content

Commit 4b16623

Browse files
committed
test iam policy
1 parent 4301954 commit 4b16623

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

lib/deploy/stepFunctions/compileIamRole.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -594,16 +594,16 @@ function getS3ObjectPermissions(action, state) {
594594
action: 's3:Get*',
595595
resource: [
596596
`arn:aws:s3:::${bucket}`,
597-
`arn:aws:s3:::${bucket}/*`
598-
]
597+
`arn:aws:s3:::${bucket}/*`,
598+
],
599599
},
600600
{
601601
action: 's3:List*',
602602
resource: [
603603
`arn:aws:s3:::${bucket}`,
604-
`arn:aws:s3:::${bucket}/*`
605-
]
606-
}
604+
`arn:aws:s3:::${bucket}/*`,
605+
],
606+
},
607607
];
608608
}
609609

lib/deploy/stepFunctions/compileIamRole.test.js

+53
Original file line numberDiff line numberDiff line change
@@ -3804,4 +3804,57 @@ describe('#compileIamRole', () => {
38043804
.PermissionsBoundary;
38053805
expect(boundary).to.equal('arn:aws:iam::myAccount:policy/permission_boundary');
38063806
});
3807+
3808+
3809+
it('should handle permissions listObjectsV2', () => {
3810+
const myBucket = 'myBucket';
3811+
serverless.service.stepFunctions = {
3812+
stateMachines: {
3813+
myStateMachine1: {
3814+
id: 'StateMachine1',
3815+
definition: {
3816+
StartAt: 'A',
3817+
States: {
3818+
A: {
3819+
Type: 'Map',
3820+
ItemProcessor: {
3821+
ProcessorConfig: {
3822+
Mode: 'DISTRIBUTED',
3823+
},
3824+
},
3825+
StartAt: 'B',
3826+
States: {
3827+
B: {
3828+
Type: 'Task',
3829+
Resource: 'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello',
3830+
End: true,
3831+
},
3832+
},
3833+
ItemReader: {
3834+
Resource: 'arn:aws:states:::s3:listObjectsV2',
3835+
Parameters: {
3836+
Bucket: myBucket,
3837+
Prefix: 'hello',
3838+
},
3839+
},
3840+
End: true,
3841+
},
3842+
},
3843+
},
3844+
},
3845+
},
3846+
};
3847+
3848+
serverlessStepFunctions.compileIamRole();
3849+
const statements = serverlessStepFunctions.serverless.service.provider
3850+
.compiledCloudFormationTemplate.Resources.StateMachine1Role.Properties.Policies[0]
3851+
.PolicyDocument.Statement;
3852+
3853+
expect(statements).to.have.lengthOf(4);
3854+
expect(statements[3].Effect).to.equal('Allow');
3855+
expect(statements[3].Action[0]).to.equal('s3:Get*');
3856+
expect(statements[3].Action[1]).to.equal('s3:List*');
3857+
expect(statements[3].Resource[0]).to.equal(`arn:aws:s3:::${myBucket}`);
3858+
expect(statements[3].Resource[1]).to.equal(`arn:aws:s3:::${myBucket}/*`);
3859+
});
38073860
});

0 commit comments

Comments
 (0)