From 01cf3fc61daa74c71402c63667dc4a066fbb56c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Sobo=C5=84?= Date: Wed, 11 Sep 2024 12:43:58 +0200 Subject: [PATCH] [Asset Inventory][AWS] Add integration test cases for implemented assets (#2487) --- .../inventory/awsfetcher/fetcher_lambda.go | 6 +- .../data/aws_asset_inventory/test_cases.py | 120 ++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/internal/inventory/awsfetcher/fetcher_lambda.go b/internal/inventory/awsfetcher/fetcher_lambda.go index 9b4472f2f1..3c195078a8 100644 --- a/internal/inventory/awsfetcher/fetcher_lambda.go +++ b/internal/inventory/awsfetcher/fetcher_lambda.go @@ -79,9 +79,13 @@ func (s *lambdaFetcher) fetch(ctx context.Context, resourceName string, function } for _, item := range awsResources { + var id string = item.GetResourceArn() + if id == "" { // e.g. LambdaEventSourceMappings + id = item.GetResourceName() + } assetChannel <- inventory.NewAssetEvent( classification, - []string{item.GetResourceArn()}, + []string{id}, item.GetResourceName(), inventory.WithRawAsset(item), inventory.WithCloud(inventory.AssetCloud{ diff --git a/tests/product/tests/data/aws_asset_inventory/test_cases.py b/tests/product/tests/data/aws_asset_inventory/test_cases.py index b408f51d36..3b308bbca8 100644 --- a/tests/product/tests/data/aws_asset_inventory/test_cases.py +++ b/tests/product/tests/data/aws_asset_inventory/test_cases.py @@ -18,4 +18,124 @@ type_="role", sub_type="iam-role", ), + "[Asset Inventory][AWS][ELBv1] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="load-balancer", + sub_type="elastic-load-balancer", + ), + "[Asset Inventory][AWS][ELBv2] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="load-balancer", + sub_type="elastic-load-balancer-v2", + ), + "[Asset Inventory][AWS][IAM Policy] assets found": AssetInventoryCase( + category="identity", + sub_category="digital-identity", + type_="policy", + sub_type="iam-policy", + ), + "[Asset Inventory][AWS][IAM User] assets found": AssetInventoryCase( + category="identity", + sub_category="digital-identity", + type_="user", + sub_type="iam-user", + ), + "[Asset Inventory][AWS][Lambda Event Source Mapping] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="integration", + type_="event-source", + sub_type="lambda-event-source-mapping", + ), + "[Asset Inventory][AWS][Lambda Function] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="compute", + type_="serverless", + sub_type="lambda-function", + ), + "[Asset Inventory][AWS][Lambda Layer] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="compute", + type_="serverless", + sub_type="lambda-layer", + ), + "[Asset Inventory][AWS][Internet Gateway] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="gateway", + sub_type="internet-gateway", + ), + "[Asset Inventory][AWS][NAT Gateway] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="gateway", + sub_type="nat-gateway", + ), + "[Asset Inventory][AWS][VPC ACL] assets found": AssetInventoryCase( + category="identity", + sub_category="authorization", + type_="acl", + sub_type="s3-access-control-list", + ), + "[Asset Inventory][AWS][EC2 Network Interface] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="interface", + sub_type="ec2-network-interface", + ), + "[Asset Inventory][AWS][Security Group] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="firewall", + sub_type="ec2-security-group", + ), + "[Asset Inventory][AWS][EC2 Subnet] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="subnet", + sub_type="ec2-subnet", + ), + "[Asset Inventory][AWS][Transit Gateway] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="virtual-network", + sub_type="transit-gateway", + ), + "[Asset Inventory][AWS][Transit Gateway Attachment] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="virtual-network", + sub_type="transit-gateway-attachment", + ), + "[Asset Inventory][AWS][VPC Peering Connection] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="peering", + sub_type="vpc-peering-connection", + ), + "[Asset Inventory][AWS][VPC] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="network", + type_="virtual-network", + sub_type="vpc", + ), + "[Asset Inventory][AWS][RDS] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="database", + type_="relational", + sub_type="rds-instance", + ), + "[Asset Inventory][AWS][S3] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="storage", + type_="object-storage", + sub_type="s3-bucket", + ), + "[Asset Inventory][AWS][SNS Topic] assets found": AssetInventoryCase( + category="infrastructure", + sub_category="messaging", + type_="notification-service", + sub_type="sns-topic", + ), }