Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(engine): raise warning instead of error on not-unique exceptions names #3159

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions unit_tests/engine/test_rule_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,6 @@ TEST_F(test_falco_engine, exceptions_names_not_unique)
- [curl 127.0.0.1]
)END";

ASSERT_FALSE(load_rules(rules_content, "rules.yaml"));
ASSERT_TRUE(check_error_message("Exceptions names in the same object must be unique"));
ASSERT_TRUE(load_rules(rules_content, "rules.yaml"));
ASSERT_TRUE(check_warning_message("Multiple definitions of exception"));
}
9 changes: 6 additions & 3 deletions userspace/engine/falco_load_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static const std::string warning_codes[] = {
"LOAD_UNKNOWN_ITEM",
"LOAD_DEPRECATED_ITEM",
"LOAD_WARNING_EXTENSION",
"LOAD_APPEND_NO_VALUES"
"LOAD_APPEND_NO_VALUES",
"LOAD_EXCEPTION_NAME_NOT_UNIQUE"
};

const std::string& falco::load_result::warning_code_str(warning_code wc)
Expand All @@ -90,7 +91,8 @@ static const std::string warning_strings[] = {
"Unknown rules file item",
"Used deprecated item",
"Warning in extension item",
"Overriding/appending with no values"
"Overriding/appending with no values",
"Multiple exceptions defined with the same name"
};

const std::string& falco::load_result::warning_str(warning_code wc)
Expand All @@ -108,7 +110,8 @@ static const std::string warning_descs[] = {
"An unknown top-level object is in the rules content. It will be ignored.",
"A deprecated item is employed by lists, macros, or rules.",
"An extension item has a warning",
"A rule exception is overriding/appending with no values"
"A rule exception is overriding/appending with no values",
"A rule is defining multiple exceptions with the same name"
};

const std::string& falco::load_result::warning_desc(warning_code wc)
Expand Down
3 changes: 2 additions & 1 deletion userspace/engine/falco_load_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class load_result {
LOAD_UNKNOWN_ITEM,
LOAD_DEPRECATED_ITEM,
LOAD_WARNING_EXTENSION,
LOAD_APPEND_NO_VALUES
LOAD_APPEND_NO_VALUES,
LOAD_EXCEPTION_NAME_NOT_UNIQUE
};

virtual ~load_result() = default;
Expand Down
6 changes: 4 additions & 2 deletions userspace/engine/rule_loader_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ static void read_rule_exceptions(
// Check if an exception with the same name has already been defined
for (auto &exception : exceptions)
{
THROW((v_ex.name == exception.name),
"Exceptions names in the same object must be unique", ex_ctx);
if(v_ex.name == exception.name)
{
cfg.res->add_warning(falco::load_result::LOAD_EXCEPTION_NAME_NOT_UNIQUE, "Multiple definitions of exception '" + v_ex.name + "' in the same rule", ex_ctx);
}
}

// note: the legacy lua loader used to throw a "xxx must strings" error
Expand Down
Loading