@@ -1560,6 +1560,63 @@ describe('#compileIamRole', () => {
1560
1560
expectation ( policy2 , lambdaArns [ 2 ] , lambdaArns [ 3 ] ) ;
1561
1561
} ) ;
1562
1562
1563
+ it ( 'should give CodeBuild permissions' , ( ) => {
1564
+ const projectName = 'HelloProject' ;
1565
+ const genStateMachine = id => ( {
1566
+ id,
1567
+ definition : {
1568
+ StartAt : 'A' ,
1569
+ States : {
1570
+ A : {
1571
+ Type : 'Task' ,
1572
+ Resource : 'arn:aws:states:::codebuild:startBuild' ,
1573
+ Parameters : {
1574
+ ProjectName : projectName ,
1575
+ } ,
1576
+ Next : 'B' ,
1577
+ } ,
1578
+ B : {
1579
+ Type : 'Task' ,
1580
+ Resource : 'arn:aws:states:::codebuild:startBuild.sync' ,
1581
+ Parameters : {
1582
+ ProjectName : projectName ,
1583
+ } ,
1584
+ End : true ,
1585
+ } ,
1586
+ } ,
1587
+ } ,
1588
+ } ) ;
1589
+ serverless . service . stepFunctions = {
1590
+ stateMachines : {
1591
+ myStateMachine1 : genStateMachine ( 'StateMachine1' ) ,
1592
+ } ,
1593
+ } ;
1594
+
1595
+ serverlessStepFunctions . compileIamRole ( ) ;
1596
+ const statements = serverlessStepFunctions . serverless . service
1597
+ . provider . compiledCloudFormationTemplate . Resources . StateMachine1Role
1598
+ . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
1599
+
1600
+ const codeBuildPermissions = statements . filter ( s => _ . isEqual ( s . Action , [ 'codebuild:StartBuild' , 'codebuild:StopBuild' , 'codebuild:BatchGetBuilds' ] ) ) ;
1601
+ expect ( codeBuildPermissions ) . to . have . lengthOf ( 1 ) ;
1602
+ expect ( codeBuildPermissions [ 0 ] . Resource ) . to . deep . eq ( [ {
1603
+ 'Fn::Sub' : [
1604
+ `arn:aws:codebuild:$\{AWS::Region}:$\{AWS::AccountId}:project/${ projectName } ` ,
1605
+ { } ,
1606
+ ] ,
1607
+ } ] ) ;
1608
+
1609
+
1610
+ const eventPermissions = statements . filter ( s => _ . isEqual ( s . Action , [ 'events:PutTargets' , 'events:PutRule' , 'events:DescribeRule' ] ) ) ;
1611
+ expect ( eventPermissions ) . to . have . lengthOf ( 1 ) ;
1612
+ expect ( eventPermissions [ 0 ] . Resource ) . to . deep . eq ( [ {
1613
+ 'Fn::Sub' : [
1614
+ 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventForCodeBuildStartBuildRule' ,
1615
+ { } ,
1616
+ ] ,
1617
+ } ] ) ;
1618
+ } ) ;
1619
+
1563
1620
it ( 'should give step functions permissions (too permissive, but mirrors console behaviour)' , ( ) => {
1564
1621
const stateMachineArn = 'arn:aws:states:us-east-1:123456789:stateMachine:HelloStateMachine' ;
1565
1622
const genStateMachine = id => ( {
@@ -1935,7 +1992,6 @@ describe('#compileIamRole', () => {
1935
1992
. Properties . Policies [ 0 ] . PolicyDocument . Statement ;
1936
1993
const lambdaPermissions2 = statements2 . filter ( s => _ . isEqual ( s . Action , [ 'lambda:InvokeFunction' ] ) ) ;
1937
1994
expect ( lambdaPermissions2 ) . to . have . lengthOf ( 1 ) ;
1938
- console . log ( lambdaPermissions2 ) ;
1939
1995
expect ( lambdaPermissions2 [ 0 ] . Resource ) . to . deep . equal ( [
1940
1996
'arn:aws:lambda:us-west-2:1234567890:function:foo' ,
1941
1997
'*limited*' ,
0 commit comments