From eb04b1c66ff6689e5e8352d3c1f1ddee2b718228 Mon Sep 17 00:00:00 2001 From: Gianmatteo Palmieri Date: Mon, 15 Apr 2024 14:50:32 +0200 Subject: [PATCH] fix(test): expect warning instead of error on invalid macro/list name Signed-off-by: Gianmatteo Palmieri --- unit_tests/engine/test_rule_loader.cpp | 16 ++++------------ userspace/engine/rule_loader_reader.cpp | 4 ++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/unit_tests/engine/test_rule_loader.cpp b/unit_tests/engine/test_rule_loader.cpp index 1fd1ecc0925..a9e5bda0175 100644 --- a/unit_tests/engine/test_rule_loader.cpp +++ b/unit_tests/engine/test_rule_loader.cpp @@ -872,18 +872,10 @@ TEST_F(test_falco_engine, macro_name_invalid) std::string rules_content = R"END( - macro: test-macro condition: evt.type = close - -- rule: test_rule - desc: test rule description - condition: test-macro - output: user=%user.name command=%proc.cmdline file=%fd.name - priority: INFO - enabled: false - )END"; - ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); - ASSERT_TRUE(check_error_message("Macro has an invalid name. Macro names must match a regular expression")); + ASSERT_TRUE(load_rules(rules_content, "rules.yaml")); + ASSERT_TRUE(check_warning_message("Macro has an invalid name. Macro names should match a regular expression")); } TEST_F(test_falco_engine, list_name_invalid) @@ -901,8 +893,8 @@ TEST_F(test_falco_engine, list_name_invalid) )END"; - ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); - ASSERT_TRUE(check_error_message("List has an invalid name. List names must match a regular expression")); + ASSERT_TRUE(load_rules(rules_content, "rules.yaml")); + ASSERT_TRUE(check_warning_message("List has an invalid name. List names should match a regular expression")); } // The appended exception has a purposely miswritten field (value), diff --git a/userspace/engine/rule_loader_reader.cpp b/userspace/engine/rule_loader_reader.cpp index e0b134b114f..517f214472f 100644 --- a/userspace/engine/rule_loader_reader.cpp +++ b/userspace/engine/rule_loader_reader.cpp @@ -473,7 +473,7 @@ void rule_loader::reader::read_item( bool invalid_name = !re2::RE2::FullMatch(name, s_rgx_barestr); if(invalid_name) { - cfg.res->add_warning(falco::load_result::LOAD_INVALID_LIST_NAME, "List has an invalid name. List names must match a regular expression: " RGX_BARESTR, ctx); + cfg.res->add_warning(falco::load_result::LOAD_INVALID_LIST_NAME, "List has an invalid name. List names should match a regular expression: " RGX_BARESTR, ctx); } rule_loader::list_info v(ctx); @@ -520,7 +520,7 @@ void rule_loader::reader::read_item( bool invalid_name = !re2::RE2::FullMatch(name, s_rgx_identifier); if(invalid_name) { - cfg.res->add_warning(falco::load_result::LOAD_INVALID_MACRO_NAME, "Macro has an invalid name. Macro names must match a regular expression: " RGX_IDENTIFIER, ctx); + cfg.res->add_warning(falco::load_result::LOAD_INVALID_MACRO_NAME, "Macro has an invalid name. Macro names should match a regular expression: " RGX_IDENTIFIER, ctx); } rule_loader::macro_info v(ctx);