mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
test(audit_info): refactor emr (#3149)
This commit is contained in:
@@ -5,8 +5,7 @@ from moto.core import DEFAULT_ACCOUNT_ID
|
||||
from prowler.providers.aws.services.emr.emr_service import (
|
||||
BlockPublicAccessConfiguration,
|
||||
)
|
||||
|
||||
AWS_REGION = "eu-west-1"
|
||||
from tests.providers.aws.audit_info_utils import AWS_REGION_EU_WEST_1
|
||||
|
||||
|
||||
class Test_emr_cluster_account_public_block_enabled:
|
||||
@@ -14,7 +13,7 @@ class Test_emr_cluster_account_public_block_enabled:
|
||||
emr_client = mock.MagicMock
|
||||
emr_client.audited_account = DEFAULT_ACCOUNT_ID
|
||||
emr_client.block_public_access_configuration = {
|
||||
AWS_REGION: BlockPublicAccessConfiguration(
|
||||
AWS_REGION_EU_WEST_1: BlockPublicAccessConfiguration(
|
||||
block_public_security_group_rules=True
|
||||
)
|
||||
}
|
||||
@@ -31,7 +30,7 @@ class Test_emr_cluster_account_public_block_enabled:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == DEFAULT_ACCOUNT_ID
|
||||
assert result[0].status == "PASS"
|
||||
assert (
|
||||
@@ -43,7 +42,7 @@ class Test_emr_cluster_account_public_block_enabled:
|
||||
emr_client = mock.MagicMock
|
||||
emr_client.audited_account = DEFAULT_ACCOUNT_ID
|
||||
emr_client.block_public_access_configuration = {
|
||||
AWS_REGION: BlockPublicAccessConfiguration(
|
||||
AWS_REGION_EU_WEST_1: BlockPublicAccessConfiguration(
|
||||
block_public_security_group_rules=False
|
||||
)
|
||||
}
|
||||
@@ -60,7 +59,7 @@ class Test_emr_cluster_account_public_block_enabled:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == DEFAULT_ACCOUNT_ID
|
||||
assert result[0].status == "FAIL"
|
||||
assert (
|
||||
|
||||
@@ -3,8 +3,7 @@ from unittest import mock
|
||||
from moto.core import DEFAULT_ACCOUNT_ID
|
||||
|
||||
from prowler.providers.aws.services.emr.emr_service import Cluster, ClusterStatus
|
||||
|
||||
AWS_REGION = "eu-west-1"
|
||||
from tests.providers.aws.audit_info_utils import AWS_REGION_EU_WEST_1
|
||||
|
||||
|
||||
class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
@@ -29,14 +28,14 @@ class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.RUNNING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="test.amazonaws.com",
|
||||
public=True,
|
||||
)
|
||||
@@ -54,7 +53,7 @@ class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "FAIL"
|
||||
@@ -67,14 +66,14 @@ class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.RUNNING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="compute.internal",
|
||||
public=False,
|
||||
)
|
||||
@@ -92,7 +91,7 @@ class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "PASS"
|
||||
@@ -105,14 +104,14 @@ class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.TERMINATED,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="test.amazonaws.com",
|
||||
public=True,
|
||||
)
|
||||
@@ -135,14 +134,14 @@ class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.BOOTSTRAPPING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="compute.internal",
|
||||
public=False,
|
||||
)
|
||||
@@ -160,7 +159,7 @@ class Test_emr_cluster_master_nodes_no_public_ip:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "PASS"
|
||||
|
||||
@@ -1,49 +1,18 @@
|
||||
from unittest import mock
|
||||
from uuid import uuid4
|
||||
|
||||
from boto3 import resource, session
|
||||
from boto3 import resource
|
||||
from moto import mock_ec2
|
||||
from moto.core import DEFAULT_ACCOUNT_ID
|
||||
|
||||
from prowler.providers.aws.lib.audit_info.audit_info import AWS_Audit_Info
|
||||
from prowler.providers.aws.services.emr.emr_service import Cluster, ClusterStatus, Node
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
AWS_REGION = "eu-west-1"
|
||||
from tests.providers.aws.audit_info_utils import (
|
||||
AWS_REGION_EU_WEST_1,
|
||||
set_mocked_aws_audit_info,
|
||||
)
|
||||
|
||||
|
||||
class Test_emr_cluster_publicly_accesible:
|
||||
# Mocked Audit Info
|
||||
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=None,
|
||||
audited_account_arn=None,
|
||||
audited_user_id=None,
|
||||
audited_partition="aws",
|
||||
audited_identity_arn=None,
|
||||
profile=None,
|
||||
profile_region=None,
|
||||
credentials=None,
|
||||
assumed_role_info=None,
|
||||
audited_regions=None,
|
||||
organizations_metadata=None,
|
||||
audit_resources=None,
|
||||
mfa_enabled=False,
|
||||
audit_metadata=Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=[],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
),
|
||||
)
|
||||
return audit_info
|
||||
|
||||
def test_no_clusters(self):
|
||||
# EMR Client
|
||||
emr_client = mock.MagicMock
|
||||
@@ -71,7 +40,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
@mock_ec2
|
||||
def test_clusters_master_public_sg(self):
|
||||
# EC2 Client
|
||||
ec2 = resource("ec2", AWS_REGION)
|
||||
ec2 = resource("ec2", AWS_REGION_EU_WEST_1)
|
||||
# Create Security Group
|
||||
master_security_group = ec2.create_security_group(
|
||||
GroupName=str(uuid4()), Description="test-decurity-group"
|
||||
@@ -87,14 +56,14 @@ class Test_emr_cluster_publicly_accesible:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.RUNNING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="test.amazonaws.com",
|
||||
public=True,
|
||||
master=Node(
|
||||
@@ -113,10 +82,10 @@ class Test_emr_cluster_publicly_accesible:
|
||||
new=emr_client,
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
|
||||
self.set_mocked_audit_info(),
|
||||
set_mocked_aws_audit_info(),
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible.ec2_client",
|
||||
new=EC2(self.set_mocked_audit_info()),
|
||||
new=EC2(set_mocked_aws_audit_info()),
|
||||
):
|
||||
# Test Check
|
||||
from prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible import (
|
||||
@@ -127,7 +96,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "FAIL"
|
||||
@@ -139,7 +108,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
@mock_ec2
|
||||
def test_clusters_master_private_sg(self):
|
||||
# EC2 Client
|
||||
ec2 = resource("ec2", AWS_REGION)
|
||||
ec2 = resource("ec2", AWS_REGION_EU_WEST_1)
|
||||
# Create Security Group
|
||||
master_security_group = ec2.create_security_group(
|
||||
GroupName=str(uuid4()), Description="test-decurity-group"
|
||||
@@ -155,14 +124,14 @@ class Test_emr_cluster_publicly_accesible:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.RUNNING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="test.amazonaws.com",
|
||||
public=True,
|
||||
master=Node(
|
||||
@@ -179,10 +148,10 @@ class Test_emr_cluster_publicly_accesible:
|
||||
new=emr_client,
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
|
||||
self.set_mocked_audit_info(),
|
||||
set_mocked_aws_audit_info(),
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible.ec2_client",
|
||||
new=EC2(self.set_mocked_audit_info()),
|
||||
new=EC2(set_mocked_aws_audit_info()),
|
||||
):
|
||||
# Test Check
|
||||
from prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible import (
|
||||
@@ -193,7 +162,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "PASS"
|
||||
@@ -205,7 +174,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
@mock_ec2
|
||||
def test_clusters_master_private_slave_public_sg(self):
|
||||
# EC2 Client
|
||||
ec2 = resource("ec2", AWS_REGION)
|
||||
ec2 = resource("ec2", AWS_REGION_EU_WEST_1)
|
||||
# Create Master Security Group
|
||||
master_security_group = ec2.create_security_group(
|
||||
GroupName=str(uuid4()), Description="test-decurity-group"
|
||||
@@ -232,14 +201,14 @@ class Test_emr_cluster_publicly_accesible:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.RUNNING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="test.amazonaws.com",
|
||||
public=True,
|
||||
master=Node(
|
||||
@@ -262,10 +231,10 @@ class Test_emr_cluster_publicly_accesible:
|
||||
new=emr_client,
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
|
||||
self.set_mocked_audit_info(),
|
||||
set_mocked_aws_audit_info(),
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible.ec2_client",
|
||||
new=EC2(self.set_mocked_audit_info()),
|
||||
new=EC2(set_mocked_aws_audit_info()),
|
||||
):
|
||||
# Test Check
|
||||
from prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible import (
|
||||
@@ -276,7 +245,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "FAIL"
|
||||
@@ -288,7 +257,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
@mock_ec2
|
||||
def test_clusters_master_public_slave_private_two_sg(self):
|
||||
# EC2 Client
|
||||
ec2 = resource("ec2", AWS_REGION)
|
||||
ec2 = resource("ec2", AWS_REGION_EU_WEST_1)
|
||||
# Create Master Security Group
|
||||
master_security_group = ec2.create_security_group(
|
||||
GroupName=str(uuid4()), Description="test-decurity-group"
|
||||
@@ -315,14 +284,14 @@ class Test_emr_cluster_publicly_accesible:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.RUNNING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="test.amazonaws.com",
|
||||
public=True,
|
||||
master=Node(
|
||||
@@ -348,10 +317,10 @@ class Test_emr_cluster_publicly_accesible:
|
||||
new=emr_client,
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
|
||||
self.set_mocked_audit_info(),
|
||||
set_mocked_aws_audit_info(),
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible.ec2_client",
|
||||
new=EC2(self.set_mocked_audit_info()),
|
||||
new=EC2(set_mocked_aws_audit_info()),
|
||||
):
|
||||
# Test Check
|
||||
from prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible import (
|
||||
@@ -362,7 +331,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "FAIL"
|
||||
@@ -374,7 +343,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
@mock_ec2
|
||||
def test_clusters_master_private_slave_public_sg_none_additional_sgs(self):
|
||||
# EC2 Client
|
||||
ec2 = resource("ec2", AWS_REGION)
|
||||
ec2 = resource("ec2", AWS_REGION_EU_WEST_1)
|
||||
# Create Master Security Group
|
||||
master_security_group = ec2.create_security_group(
|
||||
GroupName=str(uuid4()), Description="test-decurity-group"
|
||||
@@ -401,14 +370,14 @@ class Test_emr_cluster_publicly_accesible:
|
||||
emr_client = mock.MagicMock
|
||||
cluster_name = "test-cluster"
|
||||
cluster_id = "j-XWO1UKVCC6FCV"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
cluster_arn = f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_name}"
|
||||
emr_client.clusters = {
|
||||
"test-cluster": Cluster(
|
||||
id=cluster_id,
|
||||
arn=cluster_arn,
|
||||
name=cluster_name,
|
||||
status=ClusterStatus.RUNNING,
|
||||
region=AWS_REGION,
|
||||
region=AWS_REGION_EU_WEST_1,
|
||||
master_public_dns_name="test.amazonaws.com",
|
||||
public=True,
|
||||
master=Node(
|
||||
@@ -431,10 +400,10 @@ class Test_emr_cluster_publicly_accesible:
|
||||
new=emr_client,
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
|
||||
self.set_mocked_audit_info(),
|
||||
set_mocked_aws_audit_info(),
|
||||
), mock.patch(
|
||||
"prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible.ec2_client",
|
||||
new=EC2(self.set_mocked_audit_info()),
|
||||
new=EC2(set_mocked_aws_audit_info()),
|
||||
):
|
||||
# Test Check
|
||||
from prowler.providers.aws.services.emr.emr_cluster_publicly_accesible.emr_cluster_publicly_accesible import (
|
||||
@@ -445,7 +414,7 @@ class Test_emr_cluster_publicly_accesible:
|
||||
result = check.execute()
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].region == AWS_REGION
|
||||
assert result[0].region == AWS_REGION_EU_WEST_1
|
||||
assert result[0].resource_id == cluster_id
|
||||
assert result[0].resource_arn == cluster_arn
|
||||
assert result[0].status == "FAIL"
|
||||
|
||||
@@ -2,17 +2,15 @@ from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
import botocore
|
||||
from boto3 import client, session
|
||||
from boto3 import client
|
||||
from moto import mock_emr
|
||||
from moto.core import DEFAULT_ACCOUNT_ID
|
||||
|
||||
from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info
|
||||
from prowler.providers.aws.services.emr.emr_service import EMR, ClusterStatus
|
||||
from prowler.providers.common.models import Audit_Metadata
|
||||
|
||||
# Mock Test Region
|
||||
AWS_REGION = "eu-west-1"
|
||||
|
||||
from tests.providers.aws.audit_info_utils import (
|
||||
AWS_REGION_EU_WEST_1,
|
||||
set_mocked_aws_audit_info,
|
||||
)
|
||||
|
||||
# Mocking Access Analyzer Calls
|
||||
make_api_call = botocore.client.BaseClient._make_api_call
|
||||
@@ -39,9 +37,11 @@ def mock_make_api_call(self, operation_name, kwarg):
|
||||
|
||||
# Mock generate_regional_clients()
|
||||
def mock_generate_regional_clients(service, audit_info, _):
|
||||
regional_client = audit_info.audit_session.client(service, region_name=AWS_REGION)
|
||||
regional_client.region = AWS_REGION
|
||||
return {AWS_REGION: regional_client}
|
||||
regional_client = audit_info.audit_session.client(
|
||||
service, region_name=AWS_REGION_EU_WEST_1
|
||||
)
|
||||
regional_client.region = AWS_REGION_EU_WEST_1
|
||||
return {AWS_REGION_EU_WEST_1: regional_client}
|
||||
|
||||
|
||||
@patch(
|
||||
@@ -50,59 +50,29 @@ def mock_generate_regional_clients(service, audit_info, _):
|
||||
)
|
||||
@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
|
||||
class Test_EMR_Service:
|
||||
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_account_arn=f"arn:aws:iam::{DEFAULT_ACCOUNT_ID}:root",
|
||||
audited_user_id=None,
|
||||
audited_partition="aws",
|
||||
audited_identity_arn=None,
|
||||
profile=None,
|
||||
profile_region=None,
|
||||
credentials=None,
|
||||
assumed_role_info=None,
|
||||
audited_regions=None,
|
||||
organizations_metadata=None,
|
||||
audit_resources=None,
|
||||
mfa_enabled=False,
|
||||
audit_metadata=Audit_Metadata(
|
||||
services_scanned=0,
|
||||
expected_checks=[],
|
||||
completed_checks=0,
|
||||
audit_progress=0,
|
||||
),
|
||||
)
|
||||
return audit_info
|
||||
|
||||
# Test EMR Client
|
||||
@mock_emr
|
||||
def test__get_client__(self):
|
||||
emr = EMR(self.set_mocked_audit_info())
|
||||
assert emr.regional_clients[AWS_REGION].__class__.__name__ == "EMR"
|
||||
emr = EMR(set_mocked_aws_audit_info())
|
||||
assert emr.regional_clients[AWS_REGION_EU_WEST_1].__class__.__name__ == "EMR"
|
||||
|
||||
# Test EMR Session
|
||||
@mock_emr
|
||||
def test__get_session__(self):
|
||||
emr = EMR(self.set_mocked_audit_info())
|
||||
emr = EMR(set_mocked_aws_audit_info())
|
||||
assert emr.session.__class__.__name__ == "Session"
|
||||
|
||||
# Test EMR Service
|
||||
@mock_emr
|
||||
def test__get_service__(self):
|
||||
emr = EMR(self.set_mocked_audit_info())
|
||||
emr = EMR(set_mocked_aws_audit_info())
|
||||
assert emr.service == "emr"
|
||||
|
||||
# Test __list_clusters__ and __describe_cluster__
|
||||
@mock_emr
|
||||
def test__list_clusters__(self):
|
||||
# Create EMR Cluster
|
||||
emr_client = client("emr", region_name=AWS_REGION)
|
||||
emr_client = client("emr", region_name=AWS_REGION_EU_WEST_1)
|
||||
cluster_name = "test-cluster"
|
||||
run_job_flow_args = dict(
|
||||
Instances={
|
||||
@@ -123,7 +93,7 @@ class Test_EMR_Service:
|
||||
)
|
||||
cluster_id = emr_client.run_job_flow(**run_job_flow_args)["JobFlowId"]
|
||||
# EMR Class
|
||||
emr = EMR(self.set_mocked_audit_info())
|
||||
emr = EMR(set_mocked_aws_audit_info())
|
||||
|
||||
assert len(emr.clusters) == 1
|
||||
assert emr.clusters[cluster_id].id == cluster_id
|
||||
@@ -131,9 +101,9 @@ class Test_EMR_Service:
|
||||
assert emr.clusters[cluster_id].status == ClusterStatus.WAITING
|
||||
assert (
|
||||
emr.clusters[cluster_id].arn
|
||||
== f"arn:aws:elasticmapreduce:{AWS_REGION}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_id}"
|
||||
== f"arn:aws:elasticmapreduce:{AWS_REGION_EU_WEST_1}:{DEFAULT_ACCOUNT_ID}:cluster/{cluster_id}"
|
||||
)
|
||||
assert emr.clusters[cluster_id].region == AWS_REGION
|
||||
assert emr.clusters[cluster_id].region == AWS_REGION_EU_WEST_1
|
||||
assert (
|
||||
emr.clusters[cluster_id].master_public_dns_name
|
||||
== "ec2-184-0-0-1.us-west-1.compute.amazonaws.com"
|
||||
@@ -145,9 +115,9 @@ class Test_EMR_Service:
|
||||
|
||||
@mock_emr
|
||||
def test__get_block_public_access_configuration__(self):
|
||||
emr = EMR(self.set_mocked_audit_info())
|
||||
emr = EMR(set_mocked_aws_audit_info())
|
||||
|
||||
assert len(emr.block_public_access_configuration) == 1
|
||||
assert emr.block_public_access_configuration[
|
||||
AWS_REGION
|
||||
AWS_REGION_EU_WEST_1
|
||||
].block_public_security_group_rules
|
||||
|
||||
Reference in New Issue
Block a user