@@ -701,5 +701,43 @@ describe('repository', () => {
701701 repositoryName : 'a//a-a' ,
702702 } ) ) . toThrow ( / m u s t f o l l o w t h e s p e c i f i e d p a t t e r n / ) ;
703703 } ) ;
704+
705+ test ( 'return value addToResourcePolicy' , ( ) => {
706+ // GIVEN
707+ const stack = new cdk . Stack ( ) ;
708+ const policyStmt1 = new iam . PolicyStatement ( {
709+ actions : [ '*' ] ,
710+ principals : [ new iam . AnyPrincipal ( ) ] ,
711+ } ) ;
712+ const policyStmt2 = new iam . PolicyStatement ( {
713+ effect : iam . Effect . DENY ,
714+ actions : [ 'ecr:BatchGetImage' , 'ecr:GetDownloadUrlForLayer' ] ,
715+ principals : [ new iam . AnyPrincipal ( ) ] ,
716+ } ) ;
717+ const policyText1 = '{"Statement": [{"Action": "*", "Effect": "Allow", "Principal": {"AWS": "*"}}], "Version": "2012-10-17"}' ;
718+ const policyText2 = `{"Statement": [
719+ {"Action": "*", "Effect": "Allow", "Principal": {"AWS": "*"}},
720+ {"Action": ["ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer"], "Effect": "Deny", "Principal": {"AWS": "*"}}
721+ ], "Version": "2012-10-17"}` ;
722+
723+ // WHEN
724+ const artifact1 = new ecr . Repository ( stack , 'Repo1' ) . addToResourcePolicy ( policyStmt1 ) ;
725+ const repo = new ecr . Repository ( stack , 'Repo2' ) ;
726+ repo . addToResourcePolicy ( policyStmt1 ) ;
727+ const artifact2 = repo . addToResourcePolicy ( policyStmt2 ) ;
728+
729+ // THEN
730+ expect ( stack . resolve ( artifact1 . statementAdded ) ) . toEqual ( true ) ;
731+ expect ( stack . resolve ( artifact1 . policyDependable ) ) . toEqual ( JSON . parse ( policyText1 ) ) ;
732+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECR::Repository' , {
733+ RepositoryPolicyText : JSON . parse ( policyText1 ) ,
734+ } ) ;
735+
736+ expect ( stack . resolve ( artifact2 . statementAdded ) ) . toEqual ( true ) ;
737+ expect ( stack . resolve ( artifact2 . policyDependable ) ) . toEqual ( JSON . parse ( policyText2 ) ) ;
738+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECR::Repository' , {
739+ RepositoryPolicyText : JSON . parse ( policyText2 ) ,
740+ } ) ;
741+ } ) ;
704742 } ) ;
705743} ) ;
0 commit comments