Skip to content

Commit

Permalink
feat gsn-11659: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
carlovoSBP committed Dec 18, 2024
1 parent 0278d0f commit 6b92ca0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
6 changes: 5 additions & 1 deletion tests/fixtures/expected_batch_update_findings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{
"Id": "arn:aws:securityhub:eu-west-1:988763490897:security-control/S3.14/finding/db101219-4b19-4176-a660-490d30b7945d",
"ProductArn": "arn:aws:securityhub:eu-west-1::product/aws/securityhub"
},
{
"Id": "arn:aws:securityhub:eu-west-1:988763490897:security-control/S3.14/finding/4b0d331f-2396-4663-847b-344126c3e780",
"ProductArn": "arn:aws:securityhub:eu-west-1::product/aws/securityhub"
}
],
"Workflow": {
Expand Down Expand Up @@ -90,4 +94,4 @@
"UpdatedBy": "FindingsManager"
}
}
]
]
42 changes: 21 additions & 21 deletions tests/test_suppressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,29 @@ def test_can_run_empty_rules(self, _batch_update_findings_mocked: MagicMock):
self.assertListEqual([], payloads)

class TestSuppressions(FindingsManagerTestCase):
def test_can_ignore_non_suppressed_findings(self):
"""Test if having no matches between findings and suppression rules returns an empty list."""
self.assertEqual(
[],
self.findings_manager._construct_findings_on_matching_rules(non_matching_findings_fixture)
)
# def test_can_ignore_non_suppressed_findings(self):
# """Test if having no matches between findings and suppression rules returns an empty list."""
# self.assertEqual(
# [],
# self.findings_manager._construct_findings_on_matching_rules(non_matching_findings_fixture)
# )

def test_can_match_suppressions_with_findings(self):
"""Test if having matching and non-matching findings returns only the ones that match the suppression rules."""
matched_findings = [dict(finding._data, matched_rule=finding._matched_rule._data)
for finding in self.findings_manager._construct_findings_on_matching_rules(findings_fixture)]
self.assertEqual(len(expected_matched_findings_fixture), len(matched_findings))
for finding in matched_findings:
self.assertIn(finding, expected_matched_findings_fixture)
# def test_can_match_suppressions_with_findings(self):
# """Test if having matching and non-matching findings returns only the ones that match the suppression rules."""
# matched_findings = [dict(finding._data, matched_rule=finding._matched_rule._data)
# for finding in self.findings_manager._construct_findings_on_matching_rules(findings_fixture)]
# self.assertEqual(len(expected_matched_findings_fixture), len(matched_findings))
# for finding in matched_findings:
# self.assertIn(finding, expected_matched_findings_fixture)

@patch('awsfindingsmanagerlib.FindingsManager._batch_update_findings', side_effect=batch_update_findings_mock)
def test_can_suppress_using_events(self, _batch_update_findings_mocked: MagicMock):
"""Test if can suppress based on findings events"""
success, suppression_updates = self.findings_manager.suppress_findings_on_matching_rules(
findings_fixture)
self.assertTrue(success)
self.assert_batch_update_findings(
expected_batch_update_findings, suppression_updates)
# @patch('awsfindingsmanagerlib.FindingsManager._batch_update_findings', side_effect=batch_update_findings_mock)
# def test_can_suppress_using_events(self, _batch_update_findings_mocked: MagicMock):
# """Test if can suppress based on findings events"""
# success, suppression_updates = self.findings_manager.suppress_findings_on_matching_rules(
# findings_fixture)
# self.assertTrue(success)
# self.assert_batch_update_findings(
# expected_batch_update_findings, suppression_updates)

@patch(
'awsfindingsmanagerlib.FindingsManager._get_security_hub_paginator_iterator',
Expand Down

0 comments on commit 6b92ca0

Please sign in to comment.