Skip to content

Commit

Permalink
Timeout tests and missing free
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilm3 committed Sep 21, 2024
1 parent 60b8e09 commit b7fc7a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/condition/scalar_condition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "../test.hpp"
#include "condition/scalar_condition.hpp"
#include "exception.hpp"
#include "matcher/regex_match.hpp"
#include "utils.hpp"

Expand Down Expand Up @@ -53,6 +54,24 @@ TEST(TestScalarCondition, NoMatch)
ASSERT_FALSE(res.ephemeral);
}

TEST(TestScalarCondition, Timeout)
{
scalar_condition cond{std::make_unique<matcher::regex_match>(".*", 0, true), {},
{gen_variadic_param("server.request.uri.raw")}};

ddwaf_object tmp;
ddwaf_object root;
ddwaf_object_map(&root);
ddwaf_object_map_add(&root, "server.request.uri.raw", ddwaf_object_invalid(&tmp));

object_store store;
store.insert(root);

ddwaf::timer deadline{0s};
condition_cache cache;
EXPECT_THROW(cond.eval(cache, store, {}, {}, deadline), ddwaf::timeout_exception);
}

TEST(TestScalarCondition, SimpleMatch)
{
scalar_condition cond{std::make_unique<matcher::regex_match>(".*", 0, true), {},
Expand Down Expand Up @@ -167,6 +186,8 @@ TEST(TestScalarCondition, SimpleEphemeralMatch)
ASSERT_TRUE(res.outcome);
ASSERT_TRUE(res.ephemeral);
}

ddwaf_object_free(&root);
}

} // namespace
21 changes: 21 additions & 0 deletions tests/condition/scalar_negated_condition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "../test.hpp"
#include "condition/scalar_condition.hpp"
#include "exception.hpp"
#include "matcher/regex_match.hpp"
#include "utils.hpp"

Expand Down Expand Up @@ -64,6 +65,24 @@ TEST(TestScalarNegatedCondition, NoMatch)
ASSERT_FALSE(res.ephemeral);
}

TEST(TestScalarNegatedCondition, Timeout)
{
scalar_negated_condition cond{std::make_unique<matcher::regex_match>(".*", 0, true), {},
{gen_variadic_param("server.request.uri.raw")}, {}};

ddwaf_object tmp;
ddwaf_object root;
ddwaf_object_map(&root);
ddwaf_object_map_add(&root, "server.request.uri.raw", ddwaf_object_string(&tmp, "hello"));

object_store store;
store.insert(root);

ddwaf::timer deadline{0s};
condition_cache cache;
EXPECT_THROW(cond.eval(cache, store, {}, {}, deadline), ddwaf::timeout_exception);
}

TEST(TestScalarNegatedCondition, SimpleMatch)
{
scalar_negated_condition cond{std::make_unique<matcher::regex_match>(".*", 0, true), {},
Expand Down Expand Up @@ -178,6 +197,8 @@ TEST(TestScalarNegatedCondition, SimpleEphemeralMatch)
ASSERT_TRUE(res.outcome);
ASSERT_TRUE(res.ephemeral);
}

ddwaf_object_free(&root);
}

} // namespace

0 comments on commit b7fc7a5

Please sign in to comment.