1818using dds::remote_config::changeset;
1919
2020const std::string waf_rule =
21- R"( {"version":"2.1","rules":[{"id":"1","name":"rule1","tags":{"type":"flow1","category":"category1"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"arg1","key_path":[]}],"regex":"^string.*"}},{"operator":"match_regex","parameters":{"inputs":[{"address":"arg2","key_path":[]}],"regex":".*"}}]},{"id":"2","name":"rule2","tags":{"type":"flow2","category":"category2"},"conditions":[{"operator":"match_regex","parameters":{"inputs":[{"address":"arg3","key_path":[]}],"regex":"^string.*"}}]}]})" ;
21+ R"({"version": "2.1", "rules": [{"id": "1", "name": "rule1", "tags": {"type": "flow1", "category": "category1" }, "conditions": [{"operator": "match_regex", "parameters": {"inputs": [{"address": "arg1", "key_path": [] } ], "regex": "^string.*" } }, {"operator": "match_regex", "parameters": {"inputs": [{"address": "arg2", "key_path": [] } ], "regex": ".*" } } ] }, {"id": "2", "name": "rule2", "tags": {"type": "flow2", "category": "category2" }, "conditions": [{"operator": "match_regex", "parameters": {"inputs": [{"address": "arg3", "key_path": [] } ], "regex": "^string.*" } } ] } ], "rules_compat": [{"id": "ttr-000-001", "name": "Trace Tagging Rule: Attributes, Keep, No Event", "tags": {"type": "security_scanner", "category": "attack_attempt" }, "conditions": [{"operator": "match_regex", "parameters": {"inputs": [{"address": "arg4", "key_path": [] } ], "regex": "^string.*" } } ], "output": {"event": false, "keep": true, "attributes": {"_dd.appsec.trace.integer": {"value": 12345 }, "_dd.appsec.trace.string": {"value": "678" }, "_dd.appsec.trace.agent": {"address": "server.request.headers.no_cookies", "key_path": ["user-agent" ] } } }, "on_match": [] }, {"id": "ttr-000-002", "name": "Trace Tagging Rule: Attributes, No Keep, No Event", "tags": {"type": "security_scanner", "category": "attack_attempt" }, "conditions": [{"operator": "match_regex", "parameters": {"inputs": [{"address": "arg5", "key_path": [] } ], "regex": "^string.*" } } ], "output": {"event": false, "keep": false, "attributes": {"_dd.appsec.trace.integer": {"value": 12345 }, "_dd.appsec.trace.string": {"value": "678" }, "_dd.appsec.trace.agent": {"address": "server.request.headers.no_cookies", "key_path": ["user-agent" ] } } }, "on_match": [] } ] })";
2222const std::string waf_rule_with_data =
2323 R"( {"version":"2.1","rules":[{"id":"blk-001-001","name":"Block IP Addresses","tags":{"type":"block_ip","category":"security_response"},"conditions":[{"parameters":{"inputs":[{"address":"http.client_ip"}],"data":"blocked_ips"},"operator":"ip_match"}],"transformers":[],"on_match":["block"]}]})" ;
2424
@@ -104,7 +104,7 @@ TEST(EngineTest, MultipleSubscriptors)
104104 std::string rasp) -> void {
105105 std::unordered_set<std::string_view> subs{" a" , " b" , " e" , " f" };
106106 if (subs.find (data[0 ].parameterName ) != subs.end ()) {
107- event_.data .push_back (" some event" );
107+ event_.triggers .push_back (" some event" );
108108 event_.actions .push_back ({dds::action_type::block, {}});
109109 }
110110 }));
@@ -115,7 +115,7 @@ TEST(EngineTest, MultipleSubscriptors)
115115 std::string rasp) -> void {
116116 std::unordered_set<std::string_view> subs{" c" , " d" , " e" , " g" };
117117 if (subs.find (data[0 ].parameterName ) != subs.end ()) {
118- event_.data .push_back (" some event" );
118+ event_.triggers .push_back (" some event" );
119119 }
120120 }));
121121
@@ -382,8 +382,8 @@ TEST(EngineTest, WafSubscriptorBasic)
382382 Mock::VerifyAndClearExpectations (&msubmitter);
383383 EXPECT_TRUE (res);
384384 EXPECT_EQ (res->actions [0 ].type , dds::action_type::record);
385- EXPECT_EQ (res->events .size (), 1 );
386- for (auto &match : res->events ) {
385+ EXPECT_EQ (res->triggers .size (), 1 );
386+ for (auto &match : res->triggers ) {
387387 rapidjson::Document doc;
388388 doc.Parse (match);
389389 EXPECT_FALSE (doc.HasParseError ());
@@ -562,7 +562,7 @@ TEST(EngineTest, WafSubscriptorUpdateRuleData)
562562 auto res = ctx.publish (std::move (p));
563563 EXPECT_TRUE (res);
564564 EXPECT_EQ (res->actions [0 ].type , dds::action_type::block);
565- EXPECT_EQ (res->events .size (), 1 );
565+ EXPECT_EQ (res->triggers .size (), 1 );
566566 }
567567
568568 {
@@ -672,7 +672,7 @@ TEST(EngineTest, WafSubscriptorUpdateRules)
672672 auto res = ctx.publish (std::move (p));
673673 EXPECT_TRUE (res);
674674 EXPECT_EQ (res->actions [0 ].type , dds::action_type::block);
675- EXPECT_EQ (res->events .size (), 1 );
675+ EXPECT_EQ (res->triggers .size (), 1 );
676676 }
677677}
678678
@@ -791,6 +791,56 @@ TEST(EngineTest, WafSubscriptorUpdateRuleOverrideAndActions)
791791 EXPECT_TRUE (res);
792792 EXPECT_EQ (res->actions [0 ].type , dds::action_type::record);
793793 }
794+
795+ { // Test keep is true
796+ auto ctx = e->get_context ();
797+
798+ auto p = parameter::map ();
799+ p.add (" arg4" , parameter::string (" string 4" sv));
800+
801+ auto res = ctx.publish (std::move (p));
802+ EXPECT_TRUE (res);
803+ EXPECT_EQ (res->actions [0 ].type , dds::action_type::record);
804+ EXPECT_EQ (res->force_keep , true );
805+ }
806+ }
807+
808+ TEST (EngineTest, TestKeep)
809+ {
810+ auto msubmitter = NiceMock<mock::tel_submitter>{};
811+
812+ auto e{engine::create ()};
813+ e->subscribe (waf::instance::from_string (waf_rule, msubmitter));
814+
815+ {
816+ auto ctx = e->get_context ();
817+
818+ auto p = parameter::map ();
819+ p.add (" arg12" , parameter::string (" string 12" sv));
820+
821+ auto res = ctx.publish (std::move (p));
822+ EXPECT_FALSE (res);
823+ }
824+ {
825+ auto ctx = e->get_context ();
826+
827+ auto p = parameter::map ();
828+ p.add (" arg5" , parameter::string (" string 5" sv));
829+
830+ auto res = ctx.publish (std::move (p));
831+ EXPECT_FALSE (res);
832+ }
833+ {
834+ auto ctx = e->get_context ();
835+
836+ auto p = parameter::map ();
837+ p.add (" arg4" , parameter::string (" string 4" sv));
838+
839+ auto res = ctx.publish (std::move (p));
840+ EXPECT_TRUE (res);
841+ EXPECT_EQ (res->actions [0 ].type , dds::action_type::record);
842+ EXPECT_EQ (res->force_keep , true );
843+ }
794844}
795845
796846TEST (EngineTest, WafSubscriptorExclusions)
0 commit comments