From 9d48f7286af2f29f41c0660f2b4526c81cf6dd89 Mon Sep 17 00:00:00 2001 From: Daniel Barranquero <74871504+danibarranqueroo@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:45:11 +0100 Subject: [PATCH] fix(cloudformation): fix flaky tests (#6398) --- ...stack_cdktoolkit_bootstrap_version_test.py | 9 +++++++ ...rmation_stack_outputs_find_secrets_test.py | 24 +++++++++++++++++++ ...cks_termination_protection_enabled_test.py | 9 +++++++ 3 files changed, 42 insertions(+) diff --git a/tests/providers/aws/services/cloudformation/cloudformation_stack_cdktoolkit_bootstrap_version/cloudformation_stack_cdktoolkit_bootstrap_version_test.py b/tests/providers/aws/services/cloudformation/cloudformation_stack_cdktoolkit_bootstrap_version/cloudformation_stack_cdktoolkit_bootstrap_version_test.py index b9d7c57cbe..8ba9aabb78 100644 --- a/tests/providers/aws/services/cloudformation/cloudformation_stack_cdktoolkit_bootstrap_version/cloudformation_stack_cdktoolkit_bootstrap_version_test.py +++ b/tests/providers/aws/services/cloudformation/cloudformation_stack_cdktoolkit_bootstrap_version/cloudformation_stack_cdktoolkit_bootstrap_version_test.py @@ -12,6 +12,9 @@ class Test_cloudformation_stack_cdktoolkit_bootstrap_version: cloudformation_client.stacks = [] cloudformation_client.audit_config = {"recommended_cdk_bootstrap_version": 21} with mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", + new=cloudformation_client, + ), mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", new=cloudformation_client, ): @@ -37,6 +40,9 @@ class Test_cloudformation_stack_cdktoolkit_bootstrap_version: cloudformation_client.audit_config = {"recommended_cdk_bootstrap_version": 21} with mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", + new=cloudformation_client, + ), mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", new=cloudformation_client, ): @@ -73,6 +79,9 @@ class Test_cloudformation_stack_cdktoolkit_bootstrap_version: cloudformation_client.audit_config = {"recommended_cdk_bootstrap_version": 21} with mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", + new=cloudformation_client, + ), mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", new=cloudformation_client, ): diff --git a/tests/providers/aws/services/cloudformation/cloudformation_stack_outputs_find_secrets/cloudformation_stack_outputs_find_secrets_test.py b/tests/providers/aws/services/cloudformation/cloudformation_stack_outputs_find_secrets/cloudformation_stack_outputs_find_secrets_test.py index 429d8651b4..c985c838f8 100644 --- a/tests/providers/aws/services/cloudformation/cloudformation_stack_outputs_find_secrets/cloudformation_stack_outputs_find_secrets_test.py +++ b/tests/providers/aws/services/cloudformation/cloudformation_stack_outputs_find_secrets/cloudformation_stack_outputs_find_secrets_test.py @@ -10,9 +10,13 @@ class Test_cloudformation_stack_outputs_find_secrets: def test_no_stacks(self): cloudformation_client = mock.MagicMock cloudformation_client.stacks = [] + cloudformation_client.audit_config = {"secrets_ignore_patterns": []} with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", new=cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): # Test Check from prowler.providers.aws.services.cloudformation.cloudformation_stack_outputs_find_secrets.cloudformation_stack_outputs_find_secrets import ( @@ -36,9 +40,14 @@ class Test_cloudformation_stack_outputs_find_secrets: ) ] + cloudformation_client.audit_config = {"secrets_ignore_patterns": []} + with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): from prowler.providers.aws.services.cloudformation.cloudformation_stack_outputs_find_secrets.cloudformation_stack_outputs_find_secrets import ( cloudformation_stack_outputs_find_secrets, @@ -75,9 +84,14 @@ class Test_cloudformation_stack_outputs_find_secrets: ) ] + cloudformation_client.audit_config = {"secrets_ignore_patterns": []} + with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): from prowler.providers.aws.services.cloudformation.cloudformation_stack_outputs_find_secrets.cloudformation_stack_outputs_find_secrets import ( cloudformation_stack_outputs_find_secrets, @@ -112,9 +126,14 @@ class Test_cloudformation_stack_outputs_find_secrets: ) ] + cloudformation_client.audit_config = {"secrets_ignore_patterns": []} + with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): from prowler.providers.aws.services.cloudformation.cloudformation_stack_outputs_find_secrets.cloudformation_stack_outputs_find_secrets import ( cloudformation_stack_outputs_find_secrets, @@ -149,9 +168,14 @@ class Test_cloudformation_stack_outputs_find_secrets: ) ] + cloudformation_client.audit_config = {"secrets_ignore_patterns": []} + with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): from prowler.providers.aws.services.cloudformation.cloudformation_stack_outputs_find_secrets.cloudformation_stack_outputs_find_secrets import ( cloudformation_stack_outputs_find_secrets, diff --git a/tests/providers/aws/services/cloudformation/cloudformation_stacks_termination_protection_enabled/cloudformation_stacks_termination_protection_enabled_test.py b/tests/providers/aws/services/cloudformation/cloudformation_stacks_termination_protection_enabled/cloudformation_stacks_termination_protection_enabled_test.py index 7fa73d68ec..5940c7bf22 100644 --- a/tests/providers/aws/services/cloudformation/cloudformation_stacks_termination_protection_enabled/cloudformation_stacks_termination_protection_enabled_test.py +++ b/tests/providers/aws/services/cloudformation/cloudformation_stacks_termination_protection_enabled/cloudformation_stacks_termination_protection_enabled_test.py @@ -13,6 +13,9 @@ class Test_cloudformation_stacks_termination_protection_enabled: with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", new=cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): # Test Check from prowler.providers.aws.services.cloudformation.cloudformation_stacks_termination_protection_enabled.cloudformation_stacks_termination_protection_enabled import ( @@ -40,6 +43,9 @@ class Test_cloudformation_stacks_termination_protection_enabled: with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): from prowler.providers.aws.services.cloudformation.cloudformation_stacks_termination_protection_enabled.cloudformation_stacks_termination_protection_enabled import ( cloudformation_stacks_termination_protection_enabled, @@ -78,6 +84,9 @@ class Test_cloudformation_stacks_termination_protection_enabled: with mock.patch( "prowler.providers.aws.services.cloudformation.cloudformation_service.CloudFormation", cloudformation_client, + ), mock.patch( + "prowler.providers.aws.services.cloudformation.cloudformation_client.cloudformation_client", + new=cloudformation_client, ): from prowler.providers.aws.services.cloudformation.cloudformation_stacks_termination_protection_enabled.cloudformation_stacks_termination_protection_enabled import ( cloudformation_stacks_termination_protection_enabled,