chore(aws): migrate fixers to new structure until ec2_ebs

This commit is contained in:
Daniel Barranquero committed 2025-06-11 14:21:43 +02:00
1 parent 09b33d05a3
commit 07c5ae547f
23 files changed
+960 -631

No files matched your search

@@ -3,7 +3,7 @@ from unittest import mock
from tests.providers.aws.utils import AWS_ACCOUNT_ARN, AWS_REGION_EU_WEST_1
class Test_accessanalyzer_enabled_fixer:
class TestAccessAnalyzerEnabledFixer:
def test_accessanalyzer_enabled_fixer(self):
regional_client = mock.MagicMock()
accessanalyzer_client = mock.MagicMock()
@@ -26,7 +26,7 @@ class Test_accessanalyzer_enabled_fixer:
):
# Test Check
from prowler.providers.aws.services.accessanalyzer.accessanalyzer_enabled.accessanalyzer_enabled_fixer import (
fixer,
AccessAnalyzerEnabledFixer,
)
assert fixer(AWS_REGION_EU_WEST_1)
assert AccessAnalyzerEnabledFixer().fix(region=AWS_REGION_EU_WEST_1)
@@ -11,7 +11,7 @@ from tests.providers.aws.utils import (
)
class Test_awslambda_function_not_publicly_accessible_fixer:
class TestLambdaFunctionNotPubliclyAccessibleFixer:
@mock_aws
def test_function_public(self):
# Create the mock IAM role
@@ -71,12 +71,12 @@ class Test_awslambda_function_not_publicly_accessible_fixer:
new=Lambda(aws_provider),
),
):
# Test Fixer
from prowler.providers.aws.services.awslambda.awslambda_function_not_publicly_accessible.awslambda_function_not_publicly_accessible_fixer import (
fixer,
LambdaFunctionNotPubliclyAccessibleFixer,
)
assert fixer(function_name, AWS_REGION_EU_WEST_1)
fixer = LambdaFunctionNotPubliclyAccessibleFixer()
assert fixer.fix(region=AWS_REGION_EU_WEST_1, resource_id=function_name)
@mock_aws
def test_function_public_with_source_account(self):
@@ -139,12 +139,12 @@ class Test_awslambda_function_not_publicly_accessible_fixer:
new=Lambda(aws_provider),
),
):
# Test Fixer
from prowler.providers.aws.services.awslambda.awslambda_function_not_publicly_accessible.awslambda_function_not_publicly_accessible_fixer import (
fixer,
LambdaFunctionNotPubliclyAccessibleFixer,
)
assert fixer(function_name, AWS_REGION_EU_WEST_1)
fixer = LambdaFunctionNotPubliclyAccessibleFixer()
assert fixer.fix(region=AWS_REGION_EU_WEST_1, resource_id=function_name)
@mock_aws
def test_function_not_public(self):
@@ -206,12 +206,12 @@ class Test_awslambda_function_not_publicly_accessible_fixer:
new=Lambda(aws_provider),
),
):
# Test Fixer
from prowler.providers.aws.services.awslambda.awslambda_function_not_publicly_accessible.awslambda_function_not_publicly_accessible_fixer import (
fixer,
LambdaFunctionNotPubliclyAccessibleFixer,
)
assert fixer(function_name, AWS_REGION_EU_WEST_1)
fixer = LambdaFunctionNotPubliclyAccessibleFixer()
assert fixer.fix(region=AWS_REGION_EU_WEST_1, resource_id=function_name)
@mock_aws
def test_function_public_error(self):
@@ -272,9 +272,9 @@ class Test_awslambda_function_not_publicly_accessible_fixer:
new=Lambda(aws_provider),
),
):
# Test Fixer
from prowler.providers.aws.services.awslambda.awslambda_function_not_publicly_accessible.awslambda_function_not_publicly_accessible_fixer import (
fixer,
LambdaFunctionNotPubliclyAccessibleFixer,
)
assert not fixer("non-exsting", AWS_REGION_EU_WEST_1)
fixer = LambdaFunctionNotPubliclyAccessibleFixer()
assert not fixer.fix(region=AWS_REGION_EU_WEST_1, resource_id="non-exsting")
@@ -28,7 +28,7 @@ def mock_make_api_call_error(self, operation_name, kwarg):
return mock_make_api_call(self, operation_name, kwarg)
class Test_cloudtrail_logs_s3_bucket_is_not_publicly_accessible_fixer:
class TestCloudtrailLogsS3BucketIsNotPubliclyAccessibleFixer:
@mock_aws
def test_trail_bucket_public_acl(self):
aws_provider = set_mocked_aws_provider(
@@ -81,12 +81,12 @@ class Test_cloudtrail_logs_s3_bucket_is_not_publicly_accessible_fixer:
new=S3(aws_provider),
),
):
# Test Check
from prowler.providers.aws.services.cloudtrail.cloudtrail_logs_s3_bucket_is_not_publicly_accessible.cloudtrail_logs_s3_bucket_is_not_publicly_accessible_fixer import (
fixer,
CloudtrailLogsS3BucketIsNotPubliclyAccessibleFixer,
)
assert fixer(trail_name_us, AWS_REGION_US_EAST_1)
fixer = CloudtrailLogsS3BucketIsNotPubliclyAccessibleFixer()
assert fixer.fix(region=AWS_REGION_US_EAST_1, resource_id=trail_name_us)
@mock_aws
def test_trail_bucket_public_acl_error(self):
@@ -145,9 +145,11 @@ class Test_cloudtrail_logs_s3_bucket_is_not_publicly_accessible_fixer:
new=S3(aws_provider),
),
):
# Test Check
from prowler.providers.aws.services.cloudtrail.cloudtrail_logs_s3_bucket_is_not_publicly_accessible.cloudtrail_logs_s3_bucket_is_not_publicly_accessible_fixer import (
fixer,
CloudtrailLogsS3BucketIsNotPubliclyAccessibleFixer,
)
assert not fixer(trail_name_us, AWS_REGION_US_EAST_1)
fixer = CloudtrailLogsS3BucketIsNotPubliclyAccessibleFixer()
assert not fixer.fix(
region=AWS_REGION_US_EAST_1, resource_id=trail_name_us
)
@@ -6,7 +6,7 @@ from moto import mock_aws
from tests.providers.aws.utils import AWS_REGION_US_EAST_1, set_mocked_aws_provider
class Test_cloudtrail_multi_region_enabled_fixer:
class TestCloudtrailMultiRegionEnabledFixer:
@mock_aws
def test_cloudtrail_multi_region_enabled_fixer(self):
from prowler.providers.aws.services.cloudtrail.cloudtrail_service import (
@@ -36,9 +36,9 @@ class Test_cloudtrail_multi_region_enabled_fixer:
"prowler.providers.aws.services.cloudtrail.cloudtrail_multi_region_enabled.cloudtrail_multi_region_enabled_fixer.cloudtrail_client",
new=Cloudtrail(aws_provider),
):
# Test Check
from prowler.providers.aws.services.cloudtrail.cloudtrail_multi_region_enabled.cloudtrail_multi_region_enabled_fixer import (
fixer,
CloudtrailMultiRegionEnabledFixer,
)
assert fixer(AWS_REGION_US_EAST_1)
fixer = CloudtrailMultiRegionEnabledFixer()
assert fixer.fix(region=AWS_REGION_US_EAST_1)
@@ -38,7 +38,7 @@ def mock_make_api_call_codeartifact_error(self, operation_name, kwarg):
return mock_make_api_call(self, operation_name, kwarg)
class Test_codeartifact_packages_external_public_publishing_disabled_fixer:
class TestCodeartifactPackagesExternalPublicPublishingDisabledFixer:
@mock_aws
def test_repository_package_public_publishing_origin_internal(self):
with mock.patch(
@@ -57,12 +57,14 @@ class Test_codeartifact_packages_external_public_publishing_disabled_fixer:
new=CodeArtifact(aws_provider),
),
):
# Test Fixer
from prowler.providers.aws.services.codeartifact.codeartifact_packages_external_public_publishing_disabled.codeartifact_packages_external_public_publishing_disabled_fixer import (
fixer,
CodeartifactPackagesExternalPublicPublishingDisabledFixer,
)
assert fixer("test/test-package", AWS_REGION_EU_WEST_1)
fixer = CodeartifactPackagesExternalPublicPublishingDisabledFixer()
assert fixer.fix(
region=AWS_REGION_EU_WEST_1, resource_id="test/test-package"
)
@mock_aws
def test_repository_package_public_publishing_origin_internal_error(self):
@@ -70,7 +72,6 @@ class Test_codeartifact_packages_external_public_publishing_disabled_fixer:
"botocore.client.BaseClient._make_api_call",
new=mock_make_api_call_codeartifact_error,
):
aws_provider = set_mocked_aws_provider([AWS_REGION_EU_WEST_1])
with (
@@ -83,9 +84,11 @@ class Test_codeartifact_packages_external_public_publishing_disabled_fixer:
new=CodeArtifact(aws_provider),
),
):
# Test Fixer
from prowler.providers.aws.services.codeartifact.codeartifact_packages_external_public_publishing_disabled.codeartifact_packages_external_public_publishing_disabled_fixer import (
fixer,
CodeartifactPackagesExternalPublicPublishingDisabledFixer,
)
assert not fixer("non-existing-package", AWS_REGION_EU_WEST_1)
fixer = CodeartifactPackagesExternalPublicPublishingDisabledFixer()
assert not fixer.fix(
region=AWS_REGION_EU_WEST_1, resource_id="non-existing-package"
)
@@ -39,7 +39,7 @@ def mock_make_api_call_public_snapshot_error(self, operation_name, kwarg):
return mock_make_api_call(self, operation_name, kwarg)
class Test_documentdb_cluster_public_snapshot_fixer:
class TestDocumentdbClusterPublicSnapshotFixer:
@mock_aws
def test_documentdb_cluster_public_snapshot_fixer(self):
with mock.patch(
@@ -63,10 +63,13 @@ class Test_documentdb_cluster_public_snapshot_fixer:
),
):
from prowler.providers.aws.services.documentdb.documentdb_cluster_public_snapshot.documentdb_cluster_public_snapshot_fixer import (
fixer,
DocumentdbClusterPublicSnapshotFixer,
)
assert fixer(resource_id="test-snapshot", region=AWS_REGION_EU_WEST_1)
fixer = DocumentdbClusterPublicSnapshotFixer()
assert fixer.fix(
region=AWS_REGION_EU_WEST_1, resource_id="test-snapshot"
)
@mock_aws
def test_documentdb_cluster_public_snapshot_fixer_error(self):
@@ -91,9 +94,10 @@ class Test_documentdb_cluster_public_snapshot_fixer:
),
):
from prowler.providers.aws.services.documentdb.documentdb_cluster_public_snapshot.documentdb_cluster_public_snapshot_fixer import (
fixer,
DocumentdbClusterPublicSnapshotFixer,
)
assert not fixer(
resource_id="test-snapshot", region=AWS_REGION_EU_WEST_1
fixer = DocumentdbClusterPublicSnapshotFixer()
assert not fixer.fix(
region=AWS_REGION_EU_WEST_1, resource_id="test-snapshot"
)
@@ -12,7 +12,7 @@ from tests.providers.aws.utils import (
EXAMPLE_AMI_ID = "ami-12c6146b"
class Test_ec2_ami_public_fixer:
class TestEc2AmiPublicFixer:
@mock_aws
def test_one_private_ami(self):
ec2 = client("ec2", region_name=AWS_REGION_US_EAST_1)
@@ -42,10 +42,11 @@ class Test_ec2_ami_public_fixer:
),
):
from prowler.providers.aws.services.ec2.ec2_ami_public.ec2_ami_public_fixer import (
fixer,
Ec2AmiPublicFixer,
)
assert fixer(image_id, AWS_REGION_US_EAST_1)
fixer = Ec2AmiPublicFixer()
assert fixer.fix(region=AWS_REGION_US_EAST_1, resource_id=image_id)
@mock_aws
def test_one_public_ami(self):
@@ -85,10 +86,11 @@ class Test_ec2_ami_public_fixer:
),
):
from prowler.providers.aws.services.ec2.ec2_ami_public.ec2_ami_public_fixer import (
fixer,
Ec2AmiPublicFixer,
)
assert fixer(image_id, AWS_REGION_US_EAST_1)
fixer = Ec2AmiPublicFixer()
assert fixer.fix(region=AWS_REGION_US_EAST_1, resource_id=image_id)
@mock_aws
def test_one_public_ami_error(self):
@@ -128,7 +130,10 @@ class Test_ec2_ami_public_fixer:
),
):
from prowler.providers.aws.services.ec2.ec2_ami_public.ec2_ami_public_fixer import (
fixer,
Ec2AmiPublicFixer,
)
assert not fixer("image_id_non_existing", AWS_REGION_US_EAST_1)
fixer = Ec2AmiPublicFixer()
assert not fixer.fix(
region=AWS_REGION_US_EAST_1, resource_id="image_id_non_existing"
)
@@ -5,7 +5,7 @@ from moto import mock_aws
from tests.providers.aws.utils import AWS_REGION_US_EAST_1, set_mocked_aws_provider
class Test_ec2_ebs_default_encryption_fixer:
class TestEc2EbsDefaultEncryptionFixer:
@mock_aws
def test_ec2_ebs_encryption_fixer(self):
from prowler.providers.aws.services.ec2.ec2_service import EC2
@@ -23,8 +23,8 @@ class Test_ec2_ebs_default_encryption_fixer:
),
):
from prowler.providers.aws.services.ec2.ec2_ebs_default_encryption.ec2_ebs_default_encryption_fixer import (
fixer,
Ec2EbsDefaultEncryptionFixer,
)
# By default, the account has not public access blocked
assert fixer(region=AWS_REGION_US_EAST_1)
fixer = Ec2EbsDefaultEncryptionFixer()
assert fixer.fix(region=AWS_REGION_US_EAST_1)
@@ -38,14 +38,13 @@ def mock_make_api_call_error(self, operation_name, kwarg):
return mock_make_api_call(self, operation_name, kwarg)
class Test_ec2_ebs_public_snapshot_fixer_test:
class TestEc2EbsPublicSnapshotFixer:
@mock_aws
def test_ebs_public_snapshot(self):
with mock.patch(
"botocore.client.BaseClient._make_api_call",
new=mock_make_api_call_public_snapshot,
):
from prowler.providers.aws.services.ec2.ec2_service import EC2
aws_provider = set_mocked_aws_provider(
@@ -62,19 +61,18 @@ class Test_ec2_ebs_public_snapshot_fixer_test:
new=EC2(aws_provider),
),
):
# Test Check
from prowler.providers.aws.services.ec2.ec2_ebs_public_snapshot.ec2_ebs_public_snapshot_fixer import (
fixer,
Ec2EbsPublicSnapshotFixer,
)
assert fixer("testsnap", AWS_REGION_US_EAST_1)
fixer = Ec2EbsPublicSnapshotFixer()
assert fixer.fix(region=AWS_REGION_US_EAST_1, resource_id="testsnap")
@mock_aws
def test_ebs_public_snapshot_error(self):
with mock.patch(
"botocore.client.BaseClient._make_api_call", new=mock_make_api_call_error
):
from prowler.providers.aws.services.ec2.ec2_service import EC2
aws_provider = set_mocked_aws_provider(
@@ -91,9 +89,11 @@ class Test_ec2_ebs_public_snapshot_fixer_test:
new=EC2(aws_provider),
),
):
# Test Check
from prowler.providers.aws.services.ec2.ec2_ebs_public_snapshot.ec2_ebs_public_snapshot_fixer import (
fixer,
Ec2EbsPublicSnapshotFixer,
)
assert not fixer("testsnap", AWS_REGION_US_EAST_1)
fixer = Ec2EbsPublicSnapshotFixer()
assert not fixer.fix(
region=AWS_REGION_US_EAST_1, resource_id="testsnap"
)
@@ -26,7 +26,7 @@ def mock_enable_snapshot_block_public_access(State):
return {"State": State}
class Test_ec2_ebs_snapshot_account_block_public_access_fixer:
class TestEc2EbsSnapshotAccountBlockPublicAccessFixer:
@mock_aws
def test_ec2_ebs_snapshot_account_block_public_access_fixer(self):
ec2_service = mock.MagicMock()
@@ -61,10 +61,9 @@ class Test_ec2_ebs_snapshot_account_block_public_access_fixer:
ec2_service,
),
):
from prowler.providers.aws.services.ec2.ec2_ebs_snapshot_account_block_public_access.ec2_ebs_snapshot_account_block_public_access_fixer import (
fixer,
Ec2EbsSnapshotAccountBlockPublicAccessFixer,
)
# By default, the account has not public access blocked
assert fixer(region=AWS_REGION_US_EAST_1)
fixer = Ec2EbsSnapshotAccountBlockPublicAccessFixer()
assert fixer.fix(region=AWS_REGION_US_EAST_1)