Skip to content

Commit

Permalink
add test description for AWS SecurityHub Scan (#9904)
Browse files Browse the repository at this point in the history
* add test description for AWS SecurityHub Scan

* ruff, W293

* Update dojo/tools/awssecurityhub/parser.py

Co-authored-by: Charles Neill <[email protected]>

* ruff

---------

Co-authored-by: Charles Neill <[email protected]>
  • Loading branch information
manuel-sommer and cneill authored May 2, 2024
1 parent b2854f5 commit aa8ee18
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dojo/tools/awssecurityhub/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from dojo.tools.awssecurityhub.compliance import Compliance
from dojo.tools.awssecurityhub.guardduty import GuardDuty
from dojo.tools.awssecurityhub.inspector import Inspector
from dojo.tools.parser_test import ParserTest


class AwsSecurityHubParser:
ID = "AWS Security Hub"

def get_scan_types(self):
return ["AWS Security Hub Scan"]
Expand All @@ -16,6 +18,26 @@ def get_label_for_scan_types(self, scan_type):
def get_description_for_scan_types(self, scan_type):
return "AWS Security Hub exports in JSON format."

def get_tests(self, scan_type, scan):
data = json.load(scan)
findings = data.get("Findings", data.get("findings", None))
if not isinstance(findings, list):
msg = "Incorrect Security Hub report format"
raise TypeError(msg)
prod = []
aws_acc = []
for finding in findings:
prod.append(finding.get("ProductName", "AWS Security Hub Ruleset"))
aws_acc.append(finding.get("AwsAccountId"))
report_date = data.get("createdAt")
test = ParserTest(
name=self.ID, type=self.ID, version=""
)
test.description = "**AWS Accounts:** " + ', '.join(set(aws_acc)) + "\n"
test.description += "**Finding Origins:** " + ', '.join(set(prod)) + "\n"
test.findings = self.get_items(data, report_date)
return [test]

def get_findings(self, filehandle, test):
tree = json.load(filehandle)
if not isinstance(tree, dict):
Expand Down

0 comments on commit aa8ee18

Please sign in to comment.