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
88from utils .dd_types import is_same_boolean
99from utils ._weblog import HttpResponse
1010
1111SMOKE_RC_RULE_ID = "smoke-rc-0001"
1212SMOKE_RC_RASP_RULE_ID = "rasp-930-100"
13+ SMOKE_RC_IP_BLOCK_RULE_ID = "blk-001-001"
1314SMOKE_RC_RULE_FILE : tuple [str , dict [str , object ]] = (
1415 "datadog/2/ASM_DD/rules/config" ,
1516 {
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