18
18
using dds::remote_config::changeset;
19
19
20
20
const 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": [] } ] })";
22
22
const std::string waf_rule_with_data =
23
23
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"]}]})" ;
24
24
@@ -104,7 +104,7 @@ TEST(EngineTest, MultipleSubscriptors)
104
104
std::string rasp) -> void {
105
105
std::unordered_set<std::string_view> subs{" a" , " b" , " e" , " f" };
106
106
if (subs.find (data[0 ].parameterName ) != subs.end ()) {
107
- event_.data .push_back (" some event" );
107
+ event_.triggers .push_back (" some event" );
108
108
event_.actions .push_back ({dds::action_type::block, {}});
109
109
}
110
110
}));
@@ -115,7 +115,7 @@ TEST(EngineTest, MultipleSubscriptors)
115
115
std::string rasp) -> void {
116
116
std::unordered_set<std::string_view> subs{" c" , " d" , " e" , " g" };
117
117
if (subs.find (data[0 ].parameterName ) != subs.end ()) {
118
- event_.data .push_back (" some event" );
118
+ event_.triggers .push_back (" some event" );
119
119
}
120
120
}));
121
121
@@ -382,8 +382,8 @@ TEST(EngineTest, WafSubscriptorBasic)
382
382
Mock::VerifyAndClearExpectations (&msubmitter);
383
383
EXPECT_TRUE (res);
384
384
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 ) {
387
387
rapidjson::Document doc;
388
388
doc.Parse (match);
389
389
EXPECT_FALSE (doc.HasParseError ());
@@ -562,7 +562,7 @@ TEST(EngineTest, WafSubscriptorUpdateRuleData)
562
562
auto res = ctx.publish (std::move (p));
563
563
EXPECT_TRUE (res);
564
564
EXPECT_EQ (res->actions [0 ].type , dds::action_type::block);
565
- EXPECT_EQ (res->events .size (), 1 );
565
+ EXPECT_EQ (res->triggers .size (), 1 );
566
566
}
567
567
568
568
{
@@ -672,7 +672,7 @@ TEST(EngineTest, WafSubscriptorUpdateRules)
672
672
auto res = ctx.publish (std::move (p));
673
673
EXPECT_TRUE (res);
674
674
EXPECT_EQ (res->actions [0 ].type , dds::action_type::block);
675
- EXPECT_EQ (res->events .size (), 1 );
675
+ EXPECT_EQ (res->triggers .size (), 1 );
676
676
}
677
677
}
678
678
@@ -791,6 +791,56 @@ TEST(EngineTest, WafSubscriptorUpdateRuleOverrideAndActions)
791
791
EXPECT_TRUE (res);
792
792
EXPECT_EQ (res->actions [0 ].type , dds::action_type::record);
793
793
}
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
+ }
794
844
}
795
845
796
846
TEST (EngineTest, WafSubscriptorExclusions)
0 commit comments