fix(resourceexplorer2): solve test and region (#2206)

This commit is contained in:
Sergio Garcia
2023-04-14 12:33:52 +02:00
committed by GitHub
parent 291e2adffa
commit 4be2539bc2
2 changed files with 9 additions and 24 deletions

View File

@@ -14,7 +14,13 @@ class ResourceExplorer2:
self.session = audit_info.audit_session
self.audit_resources = audit_info.audit_resources
self.regional_clients = generate_regional_clients(self.service, audit_info)
self.region = audit_info.profile_region
# If the region is not set in the audit profile,
# we pick the first region from the regional clients list
self.region = (
audit_info.profile_region
if audit_info.profile_region
else list(self.regional_clients.keys())[0]
)
self.indexes = []
self.__threading_call__(self.__list_indexes__)

View File

@@ -1,7 +1,5 @@
from unittest import mock
from unittest.mock import patch
import botocore
from boto3 import session
from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info
@@ -15,25 +13,6 @@ INDEX_ARN = "arn:aws:resource-explorer-2:ap-south-1:123456789012:index/123456-28
INDEX_REGION = "us-east-1"
# Mocking Backup Calls
make_api_call = botocore.client.BaseClient._make_api_call
def mock_make_api_call(self, operation_name, kwarg):
"""
Mock every AWS API call
"""
if operation_name == "ListIndexes":
return {
"Indexes": [
{"Arn": INDEX_ARN, "Region": INDEX_REGION, "Type": "LOCAL"},
],
"NextToken": "string",
}
return make_api_call(self, operation_name, kwarg)
@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call)
class Test_resourceexplorer2_indexes_found:
def set_mocked_audit_info(self):
audit_info = AWS_Audit_Info(
@@ -48,10 +27,10 @@ class Test_resourceexplorer2_indexes_found:
audited_partition="aws",
audited_identity_arn=None,
profile=None,
profile_region="us-east-1",
profile_region=None,
credentials=None,
assumed_role_info=None,
audited_regions="us-east-1",
audited_regions=[AWS_REGION],
organizations_metadata=None,
audit_resources=None,
)