Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 466: Add mock to rule test #1364

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from fnmatch import fnmatch
from unittest.mock import MagicMock

from panther_base_helpers import aws_rule_context, deep_get
from panther_default import aws_cloudtrail_success
Expand All @@ -18,11 +20,15 @@

ALLOW_LIST = [
# Add expected events and users here to suppress alerts
{"userName": "ExampleUser", "eventName": "ExampleEvent"},
# {"userName": "ExampleUser", "eventName": "DeleteRule"},
]


def rule(event):
global ALLOW_LIST # pylint: disable=global-statement
if isinstance(ALLOW_LIST, MagicMock):
ALLOW_LIST = json.loads(ALLOW_LIST()) # pylint: disable=not-callable

if not aws_cloudtrail_success(event):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,16 @@ Tests:
}
- Name: Security Configuration Changed - Allowlisted User
ExpectedResult: false
Mocks:
- {
"objectName": "ALLOW_LIST",
"returnValue": '[{"userName": "ExampleUser", "eventName": "DeleteRule"}]',
}
Log:
{
"awsRegion": "us-west-2",
"eventID": "1111",
"eventName": "ExampleEvent",
"eventName": "DeleteRule",
"eventSource": "cloudtrail.amazonaws.com",
"eventTime": "2019-01-01T00:00:00Z",
"eventType": "AwsApiCall",
Expand Down
Loading