fix(tests): patch head_bucket function correctly (#5246)

This commit is contained in:
Sergio Garcia
2024-09-30 11:00:30 -04:00
committed by GitHub
parent 7732ec7d34
commit da87c0d81e
@@ -18,7 +18,7 @@ class Test_cloudfront_s3_origin_non_existent_bucket:
# Distributions
cloudfront_client = mock.MagicMock
cloudfront_client.distributions = {}
s3_client = mock.MagicMock
s3_client = mock.MagicMock()
# Buckets
s3_client.buckets = {}
@@ -38,10 +38,6 @@ class Test_cloudfront_s3_origin_non_existent_bucket:
assert len(result) == 0
@mock.patch(
"prowler.providers.aws.services.s3.s3_service.S3._head_bucket",
new=mock.MagicMock(return_value=False),
)
def test_distribution_nonexistent_origins(self):
# Distributions
domain = "nonexistent-bucket.s3.eu-west-1.amazonaws.com"
@@ -64,7 +60,7 @@ class Test_cloudfront_s3_origin_non_existent_bucket:
}
# Buckets
nonexistent_bucket = "nonexistent-bucket"
s3_client = mock.MagicMock
s3_client = mock.MagicMock()
s3_client.buckets = {}
with mock.patch(
@@ -72,6 +68,9 @@ class Test_cloudfront_s3_origin_non_existent_bucket:
), mock.patch(
"prowler.providers.aws.services.cloudfront.cloudfront_service.CloudFront",
new=cloudfront_client,
), mock.patch(
"prowler.providers.aws.services.cloudfront.cloudfront_distributions_s3_origin_non_existent_bucket.cloudfront_distributions_s3_origin_non_existent_bucket.s3_client._head_bucket",
new=mock.MagicMock(return_value=False),
):
# Test Check
from prowler.providers.aws.services.cloudfront.cloudfront_distributions_s3_origin_non_existent_bucket.cloudfront_distributions_s3_origin_non_existent_bucket import (
@@ -91,10 +90,6 @@ class Test_cloudfront_s3_origin_non_existent_bucket:
== f"CloudFront Distribution {DISTRIBUTION_ID} has non-existent S3 buckets as origins: {nonexistent_bucket}."
)
@mock.patch(
"prowler.providers.aws.services.s3.s3_service.S3._head_bucket",
new=mock.MagicMock(return_value=True),
)
def test_distribution_no_nonexistent_origins(self):
# Distributions
domain = "existent-bucket.s3.eu-west-1.amazonaws.com"
@@ -117,7 +112,7 @@ class Test_cloudfront_s3_origin_non_existent_bucket:
}
# Buckets
bucket_name = "existent-bucket"
s3_client = mock.MagicMock
s3_client = mock.MagicMock()
s3_client.audited_account = AWS_ACCOUNT_NUMBER
s3_client.buckets = {
f"arn:aws:s3:::{bucket_name}": Bucket(
@@ -131,6 +126,9 @@ class Test_cloudfront_s3_origin_non_existent_bucket:
), mock.patch(
"prowler.providers.aws.services.cloudfront.cloudfront_service.CloudFront",
new=cloudfront_client,
), mock.patch(
"prowler.providers.aws.services.cloudfront.cloudfront_distributions_s3_origin_non_existent_bucket.cloudfront_distributions_s3_origin_non_existent_bucket.s3_client._head_bucket",
new=mock.MagicMock(return_value=True),
):
# Test Check
from prowler.providers.aws.services.cloudfront.cloudfront_distributions_s3_origin_non_existent_bucket.cloudfront_distributions_s3_origin_non_existent_bucket import (