diff --git a/tests/providers/aws/services/dynamodb/dynamodb_accelerator_cluster_encryption_enabled/dynamodb_accelerator_cluster_encryption_enabled_test.py b/tests/providers/aws/services/dynamodb/dynamodb_accelerator_cluster_encryption_enabled/dynamodb_accelerator_cluster_encryption_enabled_test.py index 1b30bfdf..67b63d64 100644 --- a/tests/providers/aws/services/dynamodb/dynamodb_accelerator_cluster_encryption_enabled/dynamodb_accelerator_cluster_encryption_enabled_test.py +++ b/tests/providers/aws/services/dynamodb/dynamodb_accelerator_cluster_encryption_enabled/dynamodb_accelerator_cluster_encryption_enabled_test.py @@ -1,22 +1,49 @@ from re import search from unittest import mock -from boto3 import client +from boto3 import client, session from moto import mock_dax from moto.core import DEFAULT_ACCOUNT_ID +from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info + AWS_REGION = "us-east-1" class Test_dynamodb_accelerator_cluster_encryption_enabled: + def set_mocked_audit_info(self): + audit_info = AWS_Audit_Info( + session_config=None, + original_session=None, + audit_session=session.Session( + profile_name=None, + botocore_session=None, + ), + audited_account=DEFAULT_ACCOUNT_ID, + audited_user_id=None, + audited_partition="aws", + audited_identity_arn=None, + profile=None, + profile_region=None, + credentials=None, + assumed_role_info=None, + audited_regions=["us-east-1", "eu-west-1"], + organizations_metadata=None, + audit_resources=None, + ) + + return audit_info + @mock_dax def test_dax_no_clusters(self): - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DAX - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_accelerator_cluster_encryption_enabled.dynamodb_accelerator_cluster_encryption_enabled.dax_client", new=DAX(current_audit_info), ): @@ -40,12 +67,14 @@ class Test_dynamodb_accelerator_cluster_encryption_enabled: ReplicationFactor=3, IamRoleArn=iam_role_arn, )["Cluster"] - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DAX - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_accelerator_cluster_encryption_enabled.dynamodb_accelerator_cluster_encryption_enabled.dax_client", new=DAX(current_audit_info), ): @@ -77,12 +106,14 @@ class Test_dynamodb_accelerator_cluster_encryption_enabled: IamRoleArn=iam_role_arn, SSESpecification={"Enabled": True}, )["Cluster"] - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DAX - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_accelerator_cluster_encryption_enabled.dynamodb_accelerator_cluster_encryption_enabled.dax_client", new=DAX(current_audit_info), ): diff --git a/tests/providers/aws/services/dynamodb/dynamodb_tables_kms_cmk_encryption_enabled/dynamodb_tables_kms_cmk_encryption_enabled_test.py b/tests/providers/aws/services/dynamodb/dynamodb_tables_kms_cmk_encryption_enabled/dynamodb_tables_kms_cmk_encryption_enabled_test.py index 533bdc4e..2d64c00c 100644 --- a/tests/providers/aws/services/dynamodb/dynamodb_tables_kms_cmk_encryption_enabled/dynamodb_tables_kms_cmk_encryption_enabled_test.py +++ b/tests/providers/aws/services/dynamodb/dynamodb_tables_kms_cmk_encryption_enabled/dynamodb_tables_kms_cmk_encryption_enabled_test.py @@ -1,21 +1,49 @@ from re import search from unittest import mock -from boto3 import client +from boto3 import client, session from moto import mock_dynamodb +from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info + AWS_REGION = "us-east-1" +AWS_ACCOUNT_NUMBER = "123456789012" class Test_dynamodb_tables_kms_cmk_encryption_enabled: + def set_mocked_audit_info(self): + audit_info = AWS_Audit_Info( + session_config=None, + original_session=None, + audit_session=session.Session( + profile_name=None, + botocore_session=None, + ), + audited_account=AWS_ACCOUNT_NUMBER, + audited_user_id=None, + audited_partition="aws", + audited_identity_arn=None, + profile=None, + profile_region=None, + credentials=None, + assumed_role_info=None, + audited_regions=["us-east-1", "eu-west-1"], + organizations_metadata=None, + audit_resources=None, + ) + + return audit_info + @mock_dynamodb def test_dynamodb_no_tables(self): - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DynamoDB - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_tables_kms_cmk_encryption_enabled.dynamodb_tables_kms_cmk_encryption_enabled.dynamodb_client", new=DynamoDB(current_audit_info), ): @@ -45,12 +73,14 @@ class Test_dynamodb_tables_kms_cmk_encryption_enabled: BillingMode="PAY_PER_REQUEST", SSESpecification={"Enabled": True, "KMSMasterKeyId": "/custom-kms-key"}, )["TableDescription"] - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DynamoDB - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_tables_kms_cmk_encryption_enabled.dynamodb_tables_kms_cmk_encryption_enabled.dynamodb_client", new=DynamoDB(current_audit_info), ): @@ -83,12 +113,14 @@ class Test_dynamodb_tables_kms_cmk_encryption_enabled: ], BillingMode="PAY_PER_REQUEST", )["TableDescription"] - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DynamoDB - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_tables_kms_cmk_encryption_enabled.dynamodb_tables_kms_cmk_encryption_enabled.dynamodb_client", new=DynamoDB(current_audit_info), ): diff --git a/tests/providers/aws/services/dynamodb/dynamodb_tables_pitr_enabled/dynamodb_tables_pitr_enabled_test.py b/tests/providers/aws/services/dynamodb/dynamodb_tables_pitr_enabled/dynamodb_tables_pitr_enabled_test.py index cfb2f5b2..f8b52d2e 100644 --- a/tests/providers/aws/services/dynamodb/dynamodb_tables_pitr_enabled/dynamodb_tables_pitr_enabled_test.py +++ b/tests/providers/aws/services/dynamodb/dynamodb_tables_pitr_enabled/dynamodb_tables_pitr_enabled_test.py @@ -1,21 +1,49 @@ from re import search from unittest import mock -from boto3 import client +from boto3 import client, session from moto import mock_dynamodb +from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info + AWS_REGION = "us-east-1" +AWS_ACCOUNT_NUMBER = "123456789012" class Test_dynamodb_tables_pitr_enabled: + def set_mocked_audit_info(self): + audit_info = AWS_Audit_Info( + session_config=None, + original_session=None, + audit_session=session.Session( + profile_name=None, + botocore_session=None, + ), + audited_account=AWS_ACCOUNT_NUMBER, + audited_user_id=None, + audited_partition="aws", + audited_identity_arn=None, + profile=None, + profile_region=None, + credentials=None, + assumed_role_info=None, + audited_regions=["us-east-1", "eu-west-1"], + organizations_metadata=None, + audit_resources=None, + ) + + return audit_info + @mock_dynamodb def test_dynamodb_no_tables(self): - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DynamoDB - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_tables_pitr_enabled.dynamodb_tables_pitr_enabled.dynamodb_client", new=DynamoDB(current_audit_info), ): @@ -44,12 +72,14 @@ class Test_dynamodb_tables_pitr_enabled: ], BillingMode="PAY_PER_REQUEST", )["TableDescription"] - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DynamoDB - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_tables_pitr_enabled.dynamodb_tables_pitr_enabled.dynamodb_client", new=DynamoDB(current_audit_info), ): @@ -89,12 +119,14 @@ class Test_dynamodb_tables_pitr_enabled: TableName="test1", PointInTimeRecoverySpecification={"PointInTimeRecoveryEnabled": True}, ) - from prowler.providers.aws.lib.audit_info.audit_info import current_audit_info from prowler.providers.aws.services.dynamodb.dynamodb_service import DynamoDB - current_audit_info.audited_partition = "aws" + current_audit_info = self.set_mocked_audit_info() with mock.patch( + "prowler.providers.aws.lib.audit_info.audit_info.current_audit_info", + new=current_audit_info, + ), mock.patch( "prowler.providers.aws.services.dynamodb.dynamodb_tables_pitr_enabled.dynamodb_tables_pitr_enabled.dynamodb_client", new=DynamoDB(current_audit_info), ):