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

approval testing #715

Merged
merged 6 commits into from
Dec 4, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
DD_API_KEY: "11111111111111111111111111111111"
DD_ADDITIONAL_TARGET_LAMBDAS: "ironmaiden,megadeth"
run: |
pip install boto3 mock
pip install boto3 mock approvaltests
python -m unittest discover ./aws/logs_monitoring/
python -m unittest discover ./aws/rds_enhanced_monitoring/
Empty file.
13 changes: 13 additions & 0 deletions aws/logs_monitoring/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from approvaltests.approvals import set_default_reporter
from approvaltests.reporters import GenericDiffReporter, GenericDiffReporterConfig


set_default_reporter(
GenericDiffReporter(
GenericDiffReporterConfig(
"VSCODE",
"/Applications/Visual Studio Code.app/contents/Resources/app/bin/code",
["-d"],
)
)
)
3 changes: 3 additions & 0 deletions aws/logs_monitoring/tests/approvaltests_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"subdirectory": "approved_files"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"aws": {
"awslogs": {
"logGroup": "/aws/rds/instance/datadog/postgresql",
"logStream": "datadog.0",
"owner": "123456789012"
}
},
"id": "31953106606966983378809025079804211143289615424298221568",
"message": "2021-01-02 03:04:05 UTC::@:[5306]:LOG: database system is ready to accept connections",
"timestamp": 1609556645000
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ddsource": "postgresql",
"ddtags": "env:dev,test_tag_key:test_tag_value,logname:postgresql",
"host": "datadog",
"service": "postgresql"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"aws": {
"awslogs": {
"logGroup": "/aws/vendedlogs/states/logs-to-traces-sequential-Logs",
"logStream": "states/logs-to-traces-sequential/2022-11-10-15-50/7851b2d9",
"owner": "425362996713"
}
},
"id": "37199773595581154154810589279545129148442535997644275712",
"message": "{\"id\":\"1\",\"type\":\"ExecutionStarted\",\"details\":{\"input\":\"{\"Comment\": \"Insert your JSON here\"}\",\"inputDetails\":{\"truncated\":false},\"roleArn\":\"arn:aws:iam::425362996713:role/service-role/StepFunctions-logs-to-traces-sequential-role-ccd69c03\"},\",previous_event_id\":\"0\",\"event_timestamp\":\"1668095539607\",\"execution_arn\":\"arn:aws:states:sa-east-1:425362996713:express:logs-to-traces-sequential:d0dbefd8-a0f6-b402-da4c-f4863def7456:7fa0cfbe-be28-4a20-9875-73c37f5dc39e\"}",
"timestamp": 1668095539607
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ddsource": "stepfunction",
"ddtags": "env:dev,test_tag_key:test_tag_value",
"host": "/aws/vendedlogs/states/logs-to-traces-sequential-Logs",
"service": "stepfunction"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ddsource": "waf",
"message": {
"httpRequest": {
"headers": {
"header1": "value1",
"header2": "value2"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"ddsource": "waf",
"message": {
"nonTerminatingMatchingRules": {
"nonterminating1": {
"action": "COUNT"
},
"nonterminating2": {
"action": "COUNT"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"ddsource": "waf",
"message": {
"rateBasedRuleList": {
"no-rate-limit": {
"limitKey": "IP",
"limitValue": "195.154.122.189",
"maxRateAllowed": 300,
"rateBasedRuleId": "arn:aws:wafv2:ap-southeast-2:068133125972_MANAGED:regional/ipset/0f94bd8b-0fa5-4865-81ce-d11a60051fb4_fef50279-8b9a-4062-b733-88ecd1cfd889_IPV4/fef50279-8b9a-4062-b733-88ecd1cfd889"
},
"tf-rate-limit-5-min": {
"limitKey": "IP",
"limitValue": "195.154.122.189",
"maxRateAllowed": 300,
"rateBasedRuleId": "arn:aws:wafv2:ap-southeast-2:068133125972_MANAGED:regional/ipset/0f94bd8b-0fa5-4865-81ce-d11a60051fb4_fef50279-8b9a-4062-b733-88ecd1cfd889_IPV4/fef50279-8b9a-4062-b733-88ecd1cfd889"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"ddsource": "waf",
"message": {
"ruleGroupList": {
"AWS#AWSManagedRulesSQLiRuleSet": {
"terminatingRule": {
"SQLi_QUERYARGUMENTS": {
"action": "BLOCK"
},
"secondRULE": {
"action": "BLOCK"
}
}
},
"A_DIFFERENT_ID": {
"terminatingRule": {
"thirdRULE": {
"action": "BLOCK"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"ddsource": "waf",
"message": {
"ruleGroupList": {
"AWS#AWSManagedRulesSQLiRuleSet": {
"terminatingRule": {
"SQLi_QUERYARGUMENTS": {
"action": "BLOCK"
},
"secondRULE": {
"action": "BLOCK"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"ddsource": "waf",
"message": {
"ruleGroupList": {
"AWS#AWSManagedRulesSQLiRuleSet": {
"excludedRules": {
"GenericRFI_BODY": {
"exclusionType": "EXCLUDED_AS_COUNT"
},
"second_exclude": {
"exclusionType": "EXCLUDED_AS_COUNT"
}
},
"nonTerminatingMatchingRules": {
"first_nonterminating": {
"exclusionType": "REGULAR"
},
"second_nonterminating": {
"exclusionType": "REGULAR"
}
},
"terminatingRule": {
"SQLi_QUERYARGUMENTS": {
"action": "BLOCK"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"ddsource": "securityhub",
"detail": {
"finding": {
"myattribute": "somevalue",
"resources": {
"AwsEc2SecurityGroup": {
"Region": "us-east-1"
}
}
}
}
},
{
"ddsource": "securityhub",
"detail": {
"finding": {
"myattribute": "somevalue",
"resources": {
"AwsEc2SecurityGroup": {
"Region": "us-east-1"
},
"AwsOtherSecurityGroup": {
"Region": "us-east-1"
}
}
}
}
},
{
"ddsource": "securityhub",
"detail": {
"finding": {
"myattribute": "somevalue",
"resources": {
"AwsAnotherSecurityGroup": {
"Region": "us-east-1"
},
"AwsEc2SecurityGroup": {
"Region": "us-east-1"
},
"AwsOtherSecurityGroup": {
"Region": "us-east-1"
}
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"ddsource": "securityhub",
"detail": {
"finding": {
"myattribute": "somevalue",
"resources": {}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"ddsource": "securityhub",
"detail": {
"finding": {
"myattribute": "somevalue",
"resources": {
"AwsEc2SecurityGroup": {
"Region": "us-east-1"
}
}
}
}
},
{
"ddsource": "securityhub",
"detail": {
"finding": {
"myattribute": "somevalue",
"resources": {
"AwsEc2SecurityGroup": {
"Region": "us-east-1"
}
}
}
}
}
]
3 changes: 3 additions & 0 deletions aws/logs_monitoring/tests/test_lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import base64
from time import time
from botocore.exceptions import ClientError
from approvaltests.approvals import verify_as_json

sys.modules["trace_forwarder.connection"] = MagicMock()
sys.modules["datadog_lambda.wrapper"] = MagicMock()
Expand Down Expand Up @@ -167,6 +168,8 @@ def test_datadog_forwarder(
enriched_events = enrich(normalized_events)
transformed_events = transform(enriched_events)

verify_as_json(transformed_events)

metrics, logs, trace_payloads = split(transformed_events)
self.assertEqual(len(trace_payloads), 1)

Expand Down
Loading