[LYN-4743] Add CFN resource attribute key check (#1528)
This commit is contained in:
@@ -261,6 +261,25 @@ class TestAWSUtils(TestCase):
|
||||
mocked_paginator.paginate.assert_called_once_with(StackName=TestAWSUtils._expected_stack, PaginationConfig=ANY)
|
||||
assert not actual_stack_resources
|
||||
|
||||
def test_list_cloudformation_stack_resources_return_empty_list_when_resource_has_invalid_attributes(self) -> None:
|
||||
mocked_cloudformation_client: MagicMock = self._mock_client.return_value
|
||||
mocked_paginator: MagicMock = MagicMock()
|
||||
mocked_cloudformation_client.get_paginator.return_value = mocked_paginator
|
||||
mocked_iterator: MagicMock = MagicMock()
|
||||
mocked_iterator.resume_token = None
|
||||
mocked_paginator.paginate.return_value = mocked_iterator
|
||||
mocked_iterator.__iter__.return_value = [{"StackResourceSummaries": [
|
||||
{"DummyAttribute": "DummyValue"}]}]
|
||||
|
||||
actual_stack_resources: List[BasicResourceAttributes] = \
|
||||
aws_utils.list_cloudformation_stack_resources(TestAWSUtils._expected_stack, TestAWSUtils._expected_region)
|
||||
self._mock_client.assert_called_once_with(aws_utils.AWSConstants.CLOUDFORMATION_SERVICE_NAME,
|
||||
region_name=TestAWSUtils._expected_region)
|
||||
mocked_cloudformation_client.get_paginator.assert_called_once_with(
|
||||
aws_utils.AWSConstants.CLOUDFORMATION_LIST_STACK_RESOURCES_API_NAME)
|
||||
mocked_paginator.paginate.assert_called_once_with(StackName=TestAWSUtils._expected_stack, PaginationConfig=ANY)
|
||||
assert not actual_stack_resources
|
||||
|
||||
def test_list_cloudformation_stack_resources_return_expected_stack_resources(self) -> None:
|
||||
mocked_cloudformation_client: MagicMock = self._mock_client.return_value
|
||||
mocked_paginator: MagicMock = MagicMock()
|
||||
|
||||
@@ -179,10 +179,11 @@ def list_cloudformation_stack_resources(stack_name, region=None) -> List[BasicRe
|
||||
# iterate through page iterator to fetch all resources
|
||||
resource: Dict[str, any]
|
||||
for resource in page["StackResourceSummaries"]:
|
||||
resource_type_and_name.append(BasicResourceAttributesBuilder()
|
||||
.build_type(resource["ResourceType"])
|
||||
.build_name_id(resource["PhysicalResourceId"])
|
||||
.build())
|
||||
if "ResourceType" in resource.keys() and "PhysicalResourceId" in resource.keys():
|
||||
resource_type_and_name.append(BasicResourceAttributesBuilder()
|
||||
.build_type(resource["ResourceType"])
|
||||
.build_name_id(resource["PhysicalResourceId"])
|
||||
.build())
|
||||
if iterator.resume_token is None:
|
||||
# when resume token is none, it means there is no more resources left
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user