From 1f753f16f37f0bd628c72c4b752fb312ecdfa58c Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Tue, 3 Sep 2024 14:58:13 +0000 Subject: [PATCH] new(falco): add test for object cli configuration, minor test fix Signed-off-by: Luca Guerra --- .../test_configuration_rule_selection.cpp | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/unit_tests/falco/test_configuration_rule_selection.cpp b/unit_tests/falco/test_configuration_rule_selection.cpp index 725793fdf96..01f944439ef 100644 --- a/unit_tests/falco/test_configuration_rule_selection.cpp +++ b/unit_tests/falco/test_configuration_rule_selection.cpp @@ -21,7 +21,7 @@ limitations under the License. TEST(ConfigurationRuleSelection, parse_yaml) { falco_configuration falco_config; - EXPECT_NO_THROW(falco_config.init_from_content(R"( + ASSERT_NO_THROW(falco_config.init_from_content(R"( rules: - enable: rule: 'Terminal Shell in Container' @@ -33,28 +33,42 @@ TEST(ConfigurationRuleSelection, parse_yaml) rule: 'hello*' )", {})); - ASSERT_EQ(falco_config.m_rules_selection.size(), 3); + EXPECT_EQ(falco_config.m_rules_selection.size(), 3); - ASSERT_EQ(falco_config.m_rules_selection[0].m_op, falco_configuration::rule_selection_operation::enable); - ASSERT_EQ(falco_config.m_rules_selection[0].m_rule, "Terminal Shell in Container"); + EXPECT_EQ(falco_config.m_rules_selection[0].m_op, falco_configuration::rule_selection_operation::enable); + EXPECT_EQ(falco_config.m_rules_selection[0].m_rule, "Terminal Shell in Container"); - ASSERT_EQ(falco_config.m_rules_selection[1].m_op, falco_configuration::rule_selection_operation::disable); - ASSERT_EQ(falco_config.m_rules_selection[1].m_tag, "experimental"); + EXPECT_EQ(falco_config.m_rules_selection[1].m_op, falco_configuration::rule_selection_operation::disable); + EXPECT_EQ(falco_config.m_rules_selection[1].m_tag, "experimental"); - ASSERT_EQ(falco_config.m_rules_selection[2].m_op, falco_configuration::rule_selection_operation::enable); - ASSERT_EQ(falco_config.m_rules_selection[2].m_rule, "hello*"); + EXPECT_EQ(falco_config.m_rules_selection[2].m_op, falco_configuration::rule_selection_operation::enable); + EXPECT_EQ(falco_config.m_rules_selection[2].m_rule, "hello*"); } TEST(ConfigurationRuleSelection, cli_options) { falco_configuration falco_config; - EXPECT_NO_THROW(falco_config.init_from_content("", std::vector{"rules[].disable.tag=maturity_incubating", "rules[].enable.rule=Adding ssh keys to authorized_keys"})); + ASSERT_NO_THROW(falco_config.init_from_content("", std::vector{"rules[].disable.tag=maturity_incubating", "rules[].enable.rule=Adding ssh keys to authorized_keys"})); - ASSERT_EQ(falco_config.m_rules_selection.size(), 2); + EXPECT_EQ(falco_config.m_rules_selection.size(), 2); - ASSERT_EQ(falco_config.m_rules_selection[0].m_op, falco_configuration::rule_selection_operation::disable); - ASSERT_EQ(falco_config.m_rules_selection[0].m_tag, "maturity_incubating"); + EXPECT_EQ(falco_config.m_rules_selection[0].m_op, falco_configuration::rule_selection_operation::disable); + EXPECT_EQ(falco_config.m_rules_selection[0].m_tag, "maturity_incubating"); - ASSERT_EQ(falco_config.m_rules_selection[1].m_op, falco_configuration::rule_selection_operation::enable); - ASSERT_EQ(falco_config.m_rules_selection[1].m_rule, "Adding ssh keys to authorized_keys"); + EXPECT_EQ(falco_config.m_rules_selection[1].m_op, falco_configuration::rule_selection_operation::enable); + EXPECT_EQ(falco_config.m_rules_selection[1].m_rule, "Adding ssh keys to authorized_keys"); +} + +TEST(ConfigurationRuleSelection, cli_options_object) +{ + falco_configuration falco_config; + ASSERT_NO_THROW(falco_config.init_from_content("", std::vector{R"(rules[]={"disable": {"tag": "maturity_incubating"}})", R"(rules[]={"enable": {"rule": "Adding ssh keys to authorized_keys"}})"})); + + EXPECT_EQ(falco_config.m_rules_selection.size(), 2); + + EXPECT_EQ(falco_config.m_rules_selection[0].m_op, falco_configuration::rule_selection_operation::disable); + EXPECT_EQ(falco_config.m_rules_selection[0].m_tag, "maturity_incubating"); + + EXPECT_EQ(falco_config.m_rules_selection[1].m_op, falco_configuration::rule_selection_operation::enable); + EXPECT_EQ(falco_config.m_rules_selection[1].m_rule, "Adding ssh keys to authorized_keys"); }