Skip to content

Commit 9546648

Browse files
committed
fix minor tweaks
1 parent e975809 commit 9546648

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

tests/appsec/api_security/test_schemas.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def equal_value(t1, t2):
4343

4444
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
4545
@scenarios.appsec_api_security
46+
@scenarios.appsec_lambda_api_security
4647
@features.api_security_schemas
4748
class Test_Schema_Request_Headers:
4849
"""Test API Security - Request Headers Schema"""
@@ -63,6 +64,7 @@ def test_request_method(self):
6364

6465
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
6566
@scenarios.appsec_api_security
67+
@scenarios.appsec_lambda_api_security
6668
@features.api_security_schemas
6769
class Test_Schema_Request_Cookies:
6870
"""Test API Security - Request Cookies Schema"""
@@ -87,6 +89,7 @@ def test_request_method(self):
8789

8890
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
8991
@scenarios.appsec_api_security
92+
@scenarios.appsec_lambda_api_security
9093
@features.api_security_schemas
9194
class Test_Schema_Request_Query_Parameters:
9295
"""Test API Security - Request Query Parameters Schema"""
@@ -107,6 +110,7 @@ def test_request_method(self):
107110

108111
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
109112
@scenarios.appsec_api_security
113+
@scenarios.appsec_lambda_api_security
110114
@features.api_security_schemas
111115
class Test_Schema_Request_Path_Parameters:
112116
"""Test API Security - Request Path Parameters Schema"""
@@ -128,6 +132,7 @@ def test_request_method(self):
128132

129133
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
130134
@scenarios.appsec_api_security
135+
@scenarios.appsec_lambda_api_security
131136
@features.api_security_schemas
132137
class Test_Schema_Request_Json_Body:
133138
"""Test API Security - Request Body and list length"""
@@ -148,6 +153,7 @@ def test_request_method(self):
148153

149154
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
150155
@scenarios.appsec_api_security
156+
@scenarios.appsec_lambda_api_security
151157
@features.api_security_schemas
152158
class Test_Schema_Request_FormUrlEncoded_Body:
153159
"""Test API Security - Request Body and list length"""
@@ -188,6 +194,7 @@ def test_request_method(self):
188194

189195
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
190196
@scenarios.appsec_api_security
197+
@scenarios.appsec_lambda_api_security
191198
@features.api_security_schemas
192199
class Test_Schema_Response_Headers:
193200
"""Test API Security - Response Header Schema"""
@@ -207,6 +214,7 @@ def test_request_method(self):
207214

208215
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
209216
@scenarios.appsec_api_security
217+
@scenarios.appsec_lambda_api_security
210218
@features.api_security_schemas
211219
class Test_Schema_Response_Body:
212220
"""Test API Security - Response Body Schema with urlencoded body"""
@@ -233,6 +241,7 @@ def test_request_method(self):
233241

234242
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
235243
@scenarios.appsec_api_security
244+
@scenarios.appsec_lambda_api_security
236245
@features.api_security_schemas
237246
class Test_Schema_Response_on_Block:
238247
"""Test API Security - Response Schemas with urlencoded body
@@ -293,6 +302,7 @@ def test_request_method(self):
293302

294303
@rfc("https://docs.google.com/document/d/1OCHPBCAErOL2FhLl64YAHB8woDyq66y5t-JGolxdf1Q/edit#heading=h.bth088vsbjrz")
295304
@scenarios.appsec_api_security
305+
@scenarios.appsec_lambda_api_security
296306
@features.api_security_schemas
297307
class Test_Scanners:
298308
"""Test API Security - Scanners"""

tests/appsec/test_traces.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@ def setup_custom_span_tags(self):
6868
weblog.get("/waf", params={"key": "\n :"}) # rules.http_protocol_violation.crs_921_160
6969
weblog.get("/waf", headers={"random-key": "acunetix-user-agreement"}) # rules.security_scanner.crs_913_110
7070

71-
@bug(library="python_lambda", reason="APPSEC-58201")
7271
def test_custom_span_tags(self):
7372
"""AppSec should store in all APM spans some tags when enabled."""
7473

7574
spans = [span for _, span in interfaces.library.get_root_spans()]
7675
assert spans, "No root spans to validate"
77-
spans = [s for s in spans if s.get("type") == "web"]
78-
assert spans, "No spans of type web to validate"
76+
spans = [s for s in spans if s.get("type") in ("web", "serverless")]
77+
assert spans, "No spans of type web or serverless to validate"
7978
for span in spans:
79+
if span.get("type") == "serverless" and "_dd.appsec.unsupported_event_type" in span["metrics"]:
80+
# For serverless, the `healthcheck` event is not supported
81+
assert (
82+
span["metrics"]["_dd.appsec.unsupported_event_type"] == 1
83+
), "_dd.appsec.unsupported_event_type should be 1 or 1.0"
84+
continue
8085
assert "_dd.appsec.enabled" in span["metrics"], "Cannot find _dd.appsec.enabled in span metrics"
8186
assert span["metrics"]["_dd.appsec.enabled"] == 1, "_dd.appsec.enabled should be 1 or 1.0"
8287
assert "_dd.runtime_family" in span["meta"], "Cannot find _dd.runtime_family in span meta"
@@ -87,14 +92,15 @@ def test_custom_span_tags(self):
8792
def setup_header_collection(self):
8893
self.r = weblog.get("/headers", headers={"User-Agent": "Arachni/v1", "Content-Type": "text/plain"})
8994

95+
@bug(library="python_lambda", reason="APPSEC-58202")
9096
@bug(context.library < f"python@{PYTHON_RELEASE_GA_1_1}", reason="APMRP-360")
9197
@bug(context.library < "java@1.2.0", weblog_variant="spring-boot-openliberty", reason="APPSEC-6734")
9298
@bug(
9399
context.library < "nodejs@5.57.0",
94100
weblog_variant="fastify",
95101
reason="APPSEC-57432", # Response headers collection not supported yet
96102
)
97-
@irrelevant(context.library not in ["golang", "nodejs", "java", "dotnet"], reason="test")
103+
@irrelevant(context.library not in ["golang", "nodejs", "java", "dotnet", "python_lambda"], reason="test")
98104
@irrelevant(context.scenario is scenarios.external_processing, reason="Irrelevant tag set for golang")
99105
def test_header_collection(self):
100106
"""AppSec should collect some headers for http.request and http.response and store them in span tags.

utils/_context/_scenarios/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import json
22

3-
from utils._context._scenarios.aws_lambda import LambdaScenario
43
from utils._context.header_tag_vars import VALID_CONFIGS, INVALID_CONFIGS, CONFIG_WILDCARD
54
from utils.proxy.ports import ProxyPorts
65
from utils.tools import update_environ_with_local_env
76

7+
from .aws_lambda import LambdaScenario
88
from .core import Scenario, scenario_groups
99
from .default import DefaultScenario
1010
from .endtoend import DockerScenario, EndToEndScenario
@@ -1085,6 +1085,22 @@ class _Scenarios:
10851085
doc="Default Lambda scenario",
10861086
scenario_groups=[scenario_groups.appsec],
10871087
)
1088+
appsec_lambda_api_security = LambdaScenario(
1089+
"APPSEC_LAMBDA_API_SECURITY",
1090+
weblog_env={
1091+
"DD_API_SECURITY_ENABLED": "true",
1092+
"DD_API_SECURITY_REQUEST_SAMPLE_RATE": "1.0",
1093+
"DD_API_SECURITY_SAMPLE_DELAY": "0.0",
1094+
"DD_API_SECURITY_MAX_CONCURRENT_REQUESTS": "50",
1095+
"DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED": "true",
1096+
"DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT": "30",
1097+
},
1098+
doc="""
1099+
Scenario for API Security feature in lambda, testing schema types sent into span tags if
1100+
DD_API_SECURITY_ENABLED is set to true.
1101+
""",
1102+
scenario_groups=[scenario_groups.appsec],
1103+
)
10881104

10891105

10901106
scenarios = _Scenarios()

utils/_context/containers.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,26 +1060,24 @@ def __init__(
10601060
"DD_SITE": os.environ.get("DD_SITE", "datad0g.com"),
10611061
"DD_API_KEY": os.environ.get("DD_API_KEY", _FAKE_DD_API_KEY),
10621062
"DD_SERVERLESS_FLUSH_STRATEGY": "periodically,100",
1063+
"DD_TRACE_MANAGED_SERVICES": "false",
10631064
}
10641065

10651066
volumes = volumes or {}
10661067

10671068
environment["DD_PROXY_HTTPS"] = f"http://proxy:{ProxyPorts.agent}"
1068-
environment["DD_PROXY_HTTP"] = f"http://proxy:{ProxyPorts.agent}"
1069-
environment["DD_APM_NON_LOCAL_TRAFFIC"] = (
1070-
"true" # Required for the extension to receive traces from outside the container
1071-
)
1069+
environment["DD_LOG_LEVEL"] = "debug"
10721070
volumes.update(
10731071
{
10741072
"./utils/build/docker/agent/ca-certificates.crt": {
10751073
"bind": "/etc/ssl/certs/ca-certificates.crt",
10761074
"mode": "ro",
10771075
},
10781076
"./utils/build/docker/agent/datadog.yaml": {
1079-
"bind": "/etc/datadog-agent/datadog.yaml",
1077+
"bind": "/var/task/datadog.yaml",
10801078
"mode": "ro",
10811079
},
1082-
},
1080+
}
10831081
)
10841082

10851083
super().__init__(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aws-lambda-powertools
1+
aws-lambda-powertools==3.17.0

0 commit comments

Comments
 (0)