mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
test(audit_info): refactor redshift (#3144)
This commit is contained in:
@@ -3,11 +3,15 @@ from unittest import mock
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
||||||
|
from tests.providers.aws.audit_info_utils import (
|
||||||
|
AWS_ACCOUNT_NUMBER,
|
||||||
|
AWS_REGION_EU_WEST_1,
|
||||||
|
)
|
||||||
|
|
||||||
AWS_REGION = "eu-west-1"
|
|
||||||
AWS_ACCOUNT_NUMBER = "123456789012"
|
|
||||||
CLUSTER_ID = str(uuid4())
|
CLUSTER_ID = str(uuid4())
|
||||||
CLUSTER_ARN = f"arn:aws:redshift:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
CLUSTER_ARN = (
|
||||||
|
f"arn:aws:redshift:{AWS_REGION_EU_WEST_1}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Test_redshift_cluster_audit_logging:
|
class Test_redshift_cluster_audit_logging:
|
||||||
@@ -33,7 +37,7 @@ class Test_redshift_cluster_audit_logging:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
logging_enabled=False,
|
logging_enabled=False,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -59,7 +63,7 @@ class Test_redshift_cluster_audit_logging:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
logging_enabled=True,
|
logging_enabled=True,
|
||||||
endpoint_address="192.192.192.192",
|
endpoint_address="192.192.192.192",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ from unittest import mock
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
||||||
|
from tests.providers.aws.audit_info_utils import (
|
||||||
AWS_REGION = "eu-west-1"
|
AWS_ACCOUNT_NUMBER,
|
||||||
AWS_ACCOUNT_NUMBER = "123456789012"
|
AWS_REGION_EU_WEST_1,
|
||||||
|
)
|
||||||
|
|
||||||
CLUSTER_ID = str(uuid4())
|
CLUSTER_ID = str(uuid4())
|
||||||
CLUSTER_ARN = f"arn:aws:redshift:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
CLUSTER_ARN = (
|
||||||
|
f"arn:aws:redshift:{AWS_REGION_EU_WEST_1}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Test_redshift_cluster_automated_snapshot:
|
class Test_redshift_cluster_automated_snapshot:
|
||||||
@@ -34,7 +37,7 @@ class Test_redshift_cluster_automated_snapshot:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
cluster_snapshots=False,
|
cluster_snapshots=False,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -60,7 +63,7 @@ class Test_redshift_cluster_automated_snapshot:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
cluster_snapshots=True,
|
cluster_snapshots=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,11 +3,15 @@ from unittest import mock
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
||||||
|
from tests.providers.aws.audit_info_utils import (
|
||||||
|
AWS_ACCOUNT_NUMBER,
|
||||||
|
AWS_REGION_EU_WEST_1,
|
||||||
|
)
|
||||||
|
|
||||||
AWS_REGION = "eu-west-1"
|
|
||||||
AWS_ACCOUNT_NUMBER = "123456789012"
|
|
||||||
CLUSTER_ID = str(uuid4())
|
CLUSTER_ID = str(uuid4())
|
||||||
CLUSTER_ARN = f"arn:aws:redshift:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
CLUSTER_ARN = (
|
||||||
|
f"arn:aws:redshift:{AWS_REGION_EU_WEST_1}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Test_redshift_cluster_automatic_upgrades:
|
class Test_redshift_cluster_automatic_upgrades:
|
||||||
@@ -33,7 +37,7 @@ class Test_redshift_cluster_automatic_upgrades:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
allow_version_upgrade=False,
|
allow_version_upgrade=False,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -59,7 +63,7 @@ class Test_redshift_cluster_automatic_upgrades:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
allow_version_upgrade=True,
|
allow_version_upgrade=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,11 +3,15 @@ from unittest import mock
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
from prowler.providers.aws.services.redshift.redshift_service import Cluster
|
||||||
|
from tests.providers.aws.audit_info_utils import (
|
||||||
|
AWS_ACCOUNT_NUMBER,
|
||||||
|
AWS_REGION_EU_WEST_1,
|
||||||
|
)
|
||||||
|
|
||||||
AWS_REGION = "eu-west-1"
|
|
||||||
AWS_ACCOUNT_NUMBER = "123456789012"
|
|
||||||
CLUSTER_ID = str(uuid4())
|
CLUSTER_ID = str(uuid4())
|
||||||
CLUSTER_ARN = f"arn:aws:redshift:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
CLUSTER_ARN = (
|
||||||
|
f"arn:aws:redshift:{AWS_REGION_EU_WEST_1}:{AWS_ACCOUNT_NUMBER}:cluster:{CLUSTER_ID}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Test_redshift_cluster_public_access:
|
class Test_redshift_cluster_public_access:
|
||||||
@@ -33,7 +37,7 @@ class Test_redshift_cluster_public_access:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
public_access=True,
|
public_access=True,
|
||||||
endpoint_address="192.192.192.192",
|
endpoint_address="192.192.192.192",
|
||||||
)
|
)
|
||||||
@@ -60,7 +64,7 @@ class Test_redshift_cluster_public_access:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
public_access=False,
|
public_access=False,
|
||||||
endpoint_address="192.192.192.192",
|
endpoint_address="192.192.192.192",
|
||||||
)
|
)
|
||||||
@@ -87,7 +91,7 @@ class Test_redshift_cluster_public_access:
|
|||||||
Cluster(
|
Cluster(
|
||||||
id=CLUSTER_ID,
|
id=CLUSTER_ID,
|
||||||
arn=CLUSTER_ARN,
|
arn=CLUSTER_ARN,
|
||||||
region=AWS_REGION,
|
region=AWS_REGION_EU_WEST_1,
|
||||||
public_access=True,
|
public_access=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ from unittest.mock import patch
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import botocore
|
import botocore
|
||||||
from boto3 import client, session
|
from boto3 import client
|
||||||
from moto import mock_redshift
|
from moto import mock_redshift
|
||||||
|
|
||||||
from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info
|
|
||||||
from prowler.providers.aws.services.redshift.redshift_service import Redshift
|
from prowler.providers.aws.services.redshift.redshift_service import Redshift
|
||||||
from prowler.providers.common.models import Audit_Metadata
|
from tests.providers.aws.audit_info_utils import (
|
||||||
|
AWS_ACCOUNT_NUMBER,
|
||||||
AWS_ACCOUNT_NUMBER = "123456789012"
|
AWS_REGION_EU_WEST_1,
|
||||||
AWS_REGION = "eu-west-1"
|
set_mocked_aws_audit_info,
|
||||||
|
)
|
||||||
|
|
||||||
topic_name = "test-topic"
|
topic_name = "test-topic"
|
||||||
test_policy = {
|
test_policy = {
|
||||||
@@ -19,7 +19,7 @@ test_policy = {
|
|||||||
"Effect": "Allow",
|
"Effect": "Allow",
|
||||||
"Principal": {"AWS": f"{AWS_ACCOUNT_NUMBER}"},
|
"Principal": {"AWS": f"{AWS_ACCOUNT_NUMBER}"},
|
||||||
"Action": ["redshift:Publish"],
|
"Action": ["redshift:Publish"],
|
||||||
"Resource": f"arn:aws:redshift:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:{topic_name}",
|
"Resource": f"arn:aws:redshift:{AWS_REGION_EU_WEST_1}:{AWS_ACCOUNT_NUMBER}:{topic_name}",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -47,9 +47,11 @@ def mock_make_api_call(self, operation_name, kwarg):
|
|||||||
|
|
||||||
|
|
||||||
def mock_generate_regional_clients(service, audit_info, _):
|
def mock_generate_regional_clients(service, audit_info, _):
|
||||||
regional_client = audit_info.audit_session.client(service, region_name=AWS_REGION)
|
regional_client = audit_info.audit_session.client(
|
||||||
regional_client.region = AWS_REGION
|
service, region_name=AWS_REGION_EU_WEST_1
|
||||||
return {AWS_REGION: regional_client}
|
)
|
||||||
|
regional_client.region = AWS_REGION_EU_WEST_1
|
||||||
|
return {AWS_REGION_EU_WEST_1: regional_client}
|
||||||
|
|
||||||
|
|
||||||
@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
|
@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
|
||||||
@@ -58,59 +60,29 @@ def mock_generate_regional_clients(service, audit_info, _):
|
|||||||
new=mock_generate_regional_clients,
|
new=mock_generate_regional_clients,
|
||||||
)
|
)
|
||||||
class Test_Redshift_Service:
|
class Test_Redshift_Service:
|
||||||
# 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=AWS_ACCOUNT_NUMBER,
|
|
||||||
audited_account_arn=f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}: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 Redshift Service
|
# Test Redshift Service
|
||||||
def test_service(self):
|
def test_service(self):
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = set_mocked_aws_audit_info([AWS_REGION_EU_WEST_1])
|
||||||
redshift = Redshift(audit_info)
|
redshift = Redshift(audit_info)
|
||||||
assert redshift.service == "redshift"
|
assert redshift.service == "redshift"
|
||||||
|
|
||||||
# Test Redshift client
|
# Test Redshift client
|
||||||
def test_client(self):
|
def test_client(self):
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = set_mocked_aws_audit_info([AWS_REGION_EU_WEST_1])
|
||||||
redshift = Redshift(audit_info)
|
redshift = Redshift(audit_info)
|
||||||
for reg_client in redshift.regional_clients.values():
|
for reg_client in redshift.regional_clients.values():
|
||||||
assert reg_client.__class__.__name__ == "Redshift"
|
assert reg_client.__class__.__name__ == "Redshift"
|
||||||
|
|
||||||
# Test Redshift session
|
# Test Redshift session
|
||||||
def test__get_session__(self):
|
def test__get_session__(self):
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = set_mocked_aws_audit_info([AWS_REGION_EU_WEST_1])
|
||||||
redshift = Redshift(audit_info)
|
redshift = Redshift(audit_info)
|
||||||
assert redshift.session.__class__.__name__ == "Session"
|
assert redshift.session.__class__.__name__ == "Session"
|
||||||
|
|
||||||
@mock_redshift
|
@mock_redshift
|
||||||
def test_describe_clusters(self):
|
def test_describe_clusters(self):
|
||||||
redshift_client = client("redshift", region_name=AWS_REGION)
|
redshift_client = client("redshift", region_name=AWS_REGION_EU_WEST_1)
|
||||||
response = redshift_client.create_cluster(
|
response = redshift_client.create_cluster(
|
||||||
DBName="test",
|
DBName="test",
|
||||||
ClusterIdentifier=cluster_id,
|
ClusterIdentifier=cluster_id,
|
||||||
@@ -123,12 +95,12 @@ class Test_Redshift_Service:
|
|||||||
{"Key": "test", "Value": "test"},
|
{"Key": "test", "Value": "test"},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = set_mocked_aws_audit_info([AWS_REGION_EU_WEST_1])
|
||||||
redshift = Redshift(audit_info)
|
redshift = Redshift(audit_info)
|
||||||
|
|
||||||
assert len(redshift.clusters) == 1
|
assert len(redshift.clusters) == 1
|
||||||
assert redshift.clusters[0].id == cluster_id
|
assert redshift.clusters[0].id == cluster_id
|
||||||
assert redshift.clusters[0].region == AWS_REGION
|
assert redshift.clusters[0].region == AWS_REGION_EU_WEST_1
|
||||||
assert redshift.clusters[0].public_access
|
assert redshift.clusters[0].public_access
|
||||||
assert (
|
assert (
|
||||||
redshift.clusters[0].endpoint_address
|
redshift.clusters[0].endpoint_address
|
||||||
@@ -144,7 +116,7 @@ class Test_Redshift_Service:
|
|||||||
|
|
||||||
@mock_redshift
|
@mock_redshift
|
||||||
def test_describe_logging_status(self):
|
def test_describe_logging_status(self):
|
||||||
redshift_client = client("redshift", region_name=AWS_REGION)
|
redshift_client = client("redshift", region_name=AWS_REGION_EU_WEST_1)
|
||||||
response = redshift_client.create_cluster(
|
response = redshift_client.create_cluster(
|
||||||
DBName="test",
|
DBName="test",
|
||||||
ClusterIdentifier=cluster_id,
|
ClusterIdentifier=cluster_id,
|
||||||
@@ -154,12 +126,12 @@ class Test_Redshift_Service:
|
|||||||
MasterUserPassword="password",
|
MasterUserPassword="password",
|
||||||
PubliclyAccessible=True,
|
PubliclyAccessible=True,
|
||||||
)
|
)
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = set_mocked_aws_audit_info([AWS_REGION_EU_WEST_1])
|
||||||
redshift = Redshift(audit_info)
|
redshift = Redshift(audit_info)
|
||||||
|
|
||||||
assert len(redshift.clusters) == 1
|
assert len(redshift.clusters) == 1
|
||||||
assert redshift.clusters[0].id == cluster_id
|
assert redshift.clusters[0].id == cluster_id
|
||||||
assert redshift.clusters[0].region == AWS_REGION
|
assert redshift.clusters[0].region == AWS_REGION_EU_WEST_1
|
||||||
assert redshift.clusters[0].public_access
|
assert redshift.clusters[0].public_access
|
||||||
assert (
|
assert (
|
||||||
redshift.clusters[0].endpoint_address
|
redshift.clusters[0].endpoint_address
|
||||||
@@ -174,7 +146,7 @@ class Test_Redshift_Service:
|
|||||||
|
|
||||||
@mock_redshift
|
@mock_redshift
|
||||||
def test_describe_describe_cluster_snapshot(self):
|
def test_describe_describe_cluster_snapshot(self):
|
||||||
redshift_client = client("redshift", region_name=AWS_REGION)
|
redshift_client = client("redshift", region_name=AWS_REGION_EU_WEST_1)
|
||||||
response = redshift_client.create_cluster(
|
response = redshift_client.create_cluster(
|
||||||
DBName="test",
|
DBName="test",
|
||||||
ClusterIdentifier=cluster_id,
|
ClusterIdentifier=cluster_id,
|
||||||
@@ -184,12 +156,12 @@ class Test_Redshift_Service:
|
|||||||
MasterUserPassword="password",
|
MasterUserPassword="password",
|
||||||
PubliclyAccessible=True,
|
PubliclyAccessible=True,
|
||||||
)
|
)
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = set_mocked_aws_audit_info([AWS_REGION_EU_WEST_1])
|
||||||
redshift = Redshift(audit_info)
|
redshift = Redshift(audit_info)
|
||||||
|
|
||||||
assert len(redshift.clusters) == 1
|
assert len(redshift.clusters) == 1
|
||||||
assert redshift.clusters[0].id == cluster_id
|
assert redshift.clusters[0].id == cluster_id
|
||||||
assert redshift.clusters[0].region == AWS_REGION
|
assert redshift.clusters[0].region == AWS_REGION_EU_WEST_1
|
||||||
assert redshift.clusters[0].public_access
|
assert redshift.clusters[0].public_access
|
||||||
assert (
|
assert (
|
||||||
redshift.clusters[0].endpoint_address
|
redshift.clusters[0].endpoint_address
|
||||||
|
|||||||
Reference in New Issue
Block a user