From a269866976e0090e3472ec8e8284f395beaa963d Mon Sep 17 00:00:00 2001 From: Lorenzo Susini Date: Thu, 18 May 2023 07:35:38 +0000 Subject: [PATCH] test(unit_tests/engine): test filter_details_resolver class Signed-off-by: Lorenzo Susini --- .../engine/test_filter_details_resolver.cpp | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 unit_tests/engine/test_filter_details_resolver.cpp diff --git a/unit_tests/engine/test_filter_details_resolver.cpp b/unit_tests/engine/test_filter_details_resolver.cpp new file mode 100644 index 00000000..d83c100d --- /dev/null +++ b/unit_tests/engine/test_filter_details_resolver.cpp @@ -0,0 +1,49 @@ +/* +Copyright (C) 2023 The Falco Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless ASSERT_EQd by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include + + +TEST(DetailsResolver, resolve_ast) +{ + std::string cond = "(spawned_process or evt.type = open) and (proc.name icontains cat or proc.name in (known_procs, ps))"; + auto ast = libsinsp::filter::parser(cond).parse(); + filter_details details; + details.known_macros.insert("spawned_process"); + details.known_lists.insert("known_procs"); + filter_details_resolver resolver; + resolver.run(ast.get(), details); + + // Assert fields + ASSERT_EQ(details.fields.size(), 2); + ASSERT_NE(details.fields.find("evt.type"), details.fields.end()); + ASSERT_NE(details.fields.find("proc.name"), details.fields.end()); + + // Assert macros + ASSERT_EQ(details.macros.size(), 1); + ASSERT_NE(details.macros.find("spawned_process"), details.macros.end()); + + // Assert operators + ASSERT_EQ(details.operators.size(), 3); + ASSERT_NE(details.operators.find("="), details.operators.end()); + ASSERT_NE(details.operators.find("icontains"), details.operators.end()); + ASSERT_NE(details.operators.find("in"), details.operators.end()); + + // Assert lists + ASSERT_EQ(details.lists.size(), 1); + ASSERT_NE(details.lists.find("known_procs"), details.lists.end()); +} \ No newline at end of file