File tree Expand file tree Collapse file tree 2 files changed +38
-12
lines changed
__tests__/commands/gen2-migration/_infra
commands/gen2-migration/_infra Expand file tree Collapse file tree 2 files changed +38
-12
lines changed Original file line number Diff line number Diff line change @@ -784,6 +784,39 @@ describe('AmplifyGen2MigrationValidations', () => {
784784 await expect ( validations . validateLockStatus ( ) ) . resolves . not . toThrow ( ) ;
785785 } ) ;
786786
787+ it ( 'should pass when lock statement exists alongside other statements' , async ( ) => {
788+ jest . spyOn ( stateManager , 'getTeamProviderInfo' ) . mockReturnValue ( {
789+ mock : {
790+ awscloudformation : {
791+ StackName : 'test-stack' ,
792+ } ,
793+ } ,
794+ } ) ;
795+
796+ const policyWithBoth = {
797+ Statement : [
798+ {
799+ Effect : 'Allow' ,
800+ Action : 'Update:*' ,
801+ Principal : '*' ,
802+ Resource : '*' ,
803+ } ,
804+ {
805+ Effect : 'Deny' ,
806+ Action : 'Update:*' ,
807+ Principal : '*' ,
808+ Resource : '*' ,
809+ } ,
810+ ] ,
811+ } ;
812+
813+ mockCfnSend . mockResolvedValue ( {
814+ StackPolicyBody : JSON . stringify ( policyWithBoth ) ,
815+ } ) ;
816+
817+ await expect ( validations . validateLockStatus ( ) ) . resolves . not . toThrow ( ) ;
818+ } ) ;
819+
787820 it ( 'should throw MigrationError when stack policy has wrong effect' , async ( ) => {
788821 jest . spyOn ( stateManager , 'getTeamProviderInfo' ) . mockReturnValue ( {
789822 mock : {
Original file line number Diff line number Diff line change @@ -161,18 +161,11 @@ export class AmplifyGen2MigrationValidations {
161161 }
162162
163163 const currentPolicy = JSON . parse ( StackPolicyBody ) ;
164- const expectedPolicy = {
165- Statement : [
166- {
167- Effect : 'Deny' ,
168- Action : 'Update:*' ,
169- Principal : '*' ,
170- Resource : '*' ,
171- } ,
172- ] ,
173- } ;
174-
175- if ( JSON . stringify ( currentPolicy ) !== JSON . stringify ( expectedPolicy ) ) {
164+ const hasLockStatement = currentPolicy . Statement . some (
165+ ( s : Record < string , string > ) => s . Effect === 'Deny' && s . Action === 'Update:*' && s . Principal === '*' && s . Resource === '*' ,
166+ ) ;
167+
168+ if ( ! hasLockStatement ) {
176169 throw new AmplifyError ( 'MigrationError' , {
177170 message : 'Stack policy does not match expected lock policy' ,
178171 resolution : 'Run the lock command to set the correct stack policy.' ,
You can’t perform that action at this time.
0 commit comments