feat(s3): add new check s3_bucket_event_notifications_enabled (#5562)

Co-authored-by: Sergio <sergio@prowler.com>
This commit is contained in:
Hugo Pereira Brito
2024-10-29 21:38:38 +01:00
committed by GitHub
parent 82ec3e8779
commit 4bee4d482a
7 changed files with 297 additions and 10 deletions
@@ -479,6 +479,38 @@ class Test_S3_Service:
assert s3.buckets[bucket_arn].lifecycle[0].id == "test"
assert s3.buckets[bucket_arn].lifecycle[0].status == "Enabled"
# Test S3 Get Bucket Notification Configuration
@mock_aws
def test_get_bucket_notification_configuration(self):
# Generate S3 Client
s3_client = client("s3", region_name=AWS_REGION_US_EAST_1)
# Create S3 Bucket
bucket_name = "test-bucket"
bucket_arn = f"arn:aws:s3:::{bucket_name}"
s3_client.create_bucket(
Bucket=bucket_name,
ObjectOwnership="BucketOwnerEnforced",
ObjectLockEnabledForBucket=True,
)
s3_client.put_bucket_notification_configuration(
Bucket=bucket_name,
NotificationConfiguration={
"LambdaFunctionConfigurations": [
{
"LambdaFunctionArn": f"arn:aws:lambda:{AWS_REGION_US_EAST_1}:123456789012:function:Test",
"Events": ["s3:ObjectCreated:*"],
}
]
},
)
# S3 client for this test class
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
s3 = S3(aws_provider)
assert len(s3.buckets) == 1
assert s3.buckets[bucket_arn].name == bucket_name
assert s3.buckets[bucket_arn].region == AWS_REGION_US_EAST_1
assert s3.buckets[bucket_arn].notification_config
# Test S3 Head Bucket
@mock_aws
@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
@@ -505,7 +537,7 @@ class Test_S3_Service:
)
assert s3.buckets[bucket_arn].region == AWS_REGION_US_EAST_1
# Test S3 List Access Points
# Test S3Control List Access Points
@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
@mock_aws
def test_list_access_points(self):
@@ -555,7 +587,7 @@ class Test_S3_Service:
assert s3control.access_points[arn].bucket == "test-bucket"
assert s3control.access_points[arn].region == AWS_REGION_US_EAST_1
# Test S3 Get Access Point
# Test S3Control Get Access Point
@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
@mock_aws
def test_get_access_point(self):