Skip to content

Commit 405a0e4

Browse files
authored
ruby: enable apm standalone tests (#6771)
1 parent 586e9be commit 405a0e4

2 files changed

Lines changed: 65 additions & 8 deletions

File tree

manifests/ruby.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,43 @@ manifest:
408408
tests/appsec/rasp/test_ssrf.py::Test_Ssrf_Telemetry_V2: missing_feature
409409
tests/appsec/rasp/test_ssrf.py::Test_Ssrf_UrlQuery: v2.14.0
410410
tests/appsec/rasp/test_ssrf.py::Test_Ssrf_Waf_Version: missing_feature # requires Telemetry V2
411-
tests/appsec/smoke_tests/test_apm_standalone.py: missing_feature # was inccorectly declared as v2.31.0
412-
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecAPMStandalone_Rasp: missing_feature
411+
tests/appsec/smoke_tests/test_apm_standalone.py: v2.30.0
412+
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecAPMStandalone_Rasp::test_lfi_smoke: missing_feature
413+
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecAPMStandalone_Rasp::test_shi_smoke: missing_feature
414+
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecAPMStandalone_Rasp::test_sqli_smoke:
415+
- weblog_declaration:
416+
"*": v2.30.0
417+
rack: irrelevant
418+
sinatra14: irrelevant
419+
sinatra22: irrelevant
420+
sinatra32: irrelevant
421+
sinatra41: irrelevant
422+
uds-sinatra: irrelevant
413423
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecAPMStandalone_RemoteConfig::test_rasp_blocking_smoke: missing_feature
414424
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecAPMStandalone_UserEvents:
415425
- weblog_declaration:
426+
"*": v2.30.0
416427
rack: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
417428
sinatra14: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
418429
sinatra22: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
419430
sinatra32: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
420431
sinatra41: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
421432
uds-sinatra: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
422-
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_Rasp: missing_feature
433+
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_Rasp::test_lfi_smoke: missing_feature
434+
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_Rasp::test_shi_smoke: missing_feature
435+
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_Rasp::test_sqli_smoke:
436+
- weblog_declaration:
437+
"*": v2.30.0
438+
rack: irrelevant
439+
sinatra14: irrelevant
440+
sinatra22: irrelevant
441+
sinatra32: irrelevant
442+
sinatra41: irrelevant
443+
uds-sinatra: irrelevant
423444
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_RemoteConfig::test_rasp_blocking_smoke: missing_feature
424445
tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_UserEvents:
425446
- weblog_declaration:
447+
"*": v2.30.0
426448
rack: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
427449
sinatra14: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)
428450
sinatra22: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack)

tests/appsec/smoke_tests/utils.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
"""AppSec smoke tests at the agent interface level"""
66

7-
from utils import interfaces, remote_config as rc, weblog
7+
from utils import context, interfaces, remote_config as rc, weblog
88
from utils.dd_types import is_same_boolean
99
from utils._weblog import HttpResponse
1010

1111
SMOKE_RC_RULE_ID = "smoke-rc-0001"
1212
SMOKE_RC_RASP_RULE_ID = "rasp-930-100"
13+
SMOKE_RC_IP_BLOCK_RULE_ID = "blk-001-001"
1314
SMOKE_RC_RULE_FILE: tuple[str, dict[str, object]] = (
1415
"datadog/2/ASM_DD/rules/config",
1516
{
@@ -65,6 +66,25 @@
6566
"transformers": [],
6667
"on_match": ["block"],
6768
},
69+
{
70+
"id": SMOKE_RC_IP_BLOCK_RULE_ID,
71+
"name": "Block IP Addresses",
72+
"tags": {
73+
"type": "block_ip",
74+
"category": "security_response",
75+
},
76+
"conditions": [
77+
{
78+
"parameters": {
79+
"inputs": [{"address": "http.client_ip"}],
80+
"data": "blocked_ips",
81+
},
82+
"operator": "ip_match",
83+
}
84+
],
85+
"transformers": [],
86+
"on_match": ["block"],
87+
},
6888
],
6989
},
7090
)
@@ -232,6 +252,7 @@ class BaseRemoteConfigSmokeTests:
232252
def setup_remote_config_smoke(self) -> None:
233253
self.config_state = rc.tracer_rc_state.reset().set_config(*SMOKE_RC_RULE_FILE).apply().state
234254
self.r = weblog.get("/waf", headers={"X-Smoke-Test": "rc-smoke"})
255+
rc.tracer_rc_state.reset().apply()
235256

236257
def test_remote_config_smoke(self) -> None:
237258
assert self.config_state == rc.ApplyState.ACKNOWLEDGED, (
@@ -250,22 +271,34 @@ def setup_rasp_blocking_smoke(self) -> None:
250271
"""Push RASP LFI blocking rule via RC, then trigger the attack."""
251272
rc.tracer_rc_state.reset().set_config(*SMOKE_RC_RULE_FILE).apply()
252273
self.r = weblog.get("/rasp/lfi", params={"file": "../etc/passwd"})
274+
rc.tracer_rc_state.reset().apply()
253275

254276
def test_rasp_blocking_smoke(self) -> None:
255277
assert self.r.status_code == 403
278+
_assert_rasp_attack(
279+
self.r,
280+
"rasp-930-100",
281+
{
282+
"resource": {"address": "server.io.fs.file", "value": "../etc/passwd"},
283+
"params": {"address": "server.request.query", "value": "../etc/passwd"},
284+
},
285+
)
256286

257287
def setup_ip_blocking_smoke(self) -> None:
258288
config = {
259289
"rules_data": [
260290
{
261291
"id": "blocked_ips",
262292
"type": "ip_with_expiration",
263-
"data": [{"value": "10.10.10.1", "expiration": 9999999999}],
293+
"data": [{"value": "1.2.3.4", "expiration": 9999999999}],
264294
}
265295
]
266296
}
267-
rc.tracer_rc_state.reset().set_config("datadog/2/ASM_DATA/blocked_ips/config", config).apply()
268-
self.r = weblog.get("/waf", headers={"X-Forwarded-For": "10.10.10.1"})
297+
rc.tracer_rc_state.reset().set_config(*SMOKE_RC_RULE_FILE).set_config(
298+
"datadog/2/ASM_DATA/blocked_ips/config", config
299+
).apply()
300+
self.r = weblog.get("/waf", headers={"X-Forwarded-For": "1.2.3.4"})
301+
rc.tracer_rc_state.reset().apply()
269302

270303
def test_ip_blocking_smoke(self) -> None:
271304
assert self.r.status_code == 403
@@ -297,7 +330,9 @@ class BaseUserEventsSmokeTests:
297330
"""Verify user login events are tracked in standalone mode."""
298331

299332
def setup_login_success_smoke(self) -> None:
300-
self.r = weblog.post("/login?auth=local", data={"username": "test", "password": "1234"})
333+
username_key = "user[username]" if "rails" in context.weblog_variant else "username"
334+
password_key = "user[password]" if "rails" in context.weblog_variant else "password"
335+
self.r = weblog.post("/login?auth=local", data={username_key: "test", password_key: "1234"})
301336

302337
def test_login_success_smoke(self) -> None:
303338
for _, span in interfaces.agent.get_spans(self.r):

0 commit comments

Comments
 (0)