summaryrefslogtreecommitdiffstats
path: root/test-dnsdistrules_cc.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:14:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:14:48 +0000
commite10ff189aca57bba91933088195d4edda199cb20 (patch)
tree056237559582eba27e68fa864434436ac5b7f535 /test-dnsdistrules_cc.cc
parentAdding upstream version 1.8.3. (diff)
downloaddnsdist-e10ff189aca57bba91933088195d4edda199cb20.tar.xz
dnsdist-e10ff189aca57bba91933088195d4edda199cb20.zip
Adding upstream version 1.9.3.upstream/1.9.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test-dnsdistrules_cc.cc')
-rw-r--r--test-dnsdistrules_cc.cc74
1 files changed, 74 insertions, 0 deletions
diff --git a/test-dnsdistrules_cc.cc b/test-dnsdistrules_cc.cc
index b636ea9..8f7363a 100644
--- a/test-dnsdistrules_cc.cc
+++ b/test-dnsdistrules_cc.cc
@@ -1,5 +1,8 @@
+#ifndef BOOST_TEST_DYN_LINK
#define BOOST_TEST_DYN_LINK
+#endif
+
#define BOOST_TEST_NO_MAIN
#include <thread>
@@ -154,4 +157,75 @@ BOOST_AUTO_TEST_CASE(test_poolOutstandingRule) {
BOOST_CHECK_EQUAL(pOR2.matches(&dq), false);
}
+BOOST_AUTO_TEST_CASE(test_payloadSizeRule) {
+ auto dnsQuestion = getDQ();
+
+ {
+ PayloadSizeRule rule("equal", dnsQuestion.getData().size());
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), true);
+ BOOST_CHECK_EQUAL(rule.toString(), "payload size is equal to " + std::to_string(dnsQuestion.getData().size()));
+ }
+
+ {
+ PayloadSizeRule rule("equal", dnsQuestion.getData().size() + 1);
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), false);
+ }
+
+ {
+ PayloadSizeRule rule("greater", dnsQuestion.getData().size());
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), false);
+ BOOST_CHECK_EQUAL(rule.toString(), "payload size is greater than " + std::to_string(dnsQuestion.getData().size()));
+ }
+
+ {
+ PayloadSizeRule rule("greater", dnsQuestion.getData().size() - 1);
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), true);
+ }
+
+ {
+ PayloadSizeRule rule("smaller", dnsQuestion.getData().size());
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), false);
+ BOOST_CHECK_EQUAL(rule.toString(), "payload size is smaller than " + std::to_string(dnsQuestion.getData().size()));
+ }
+
+ {
+ PayloadSizeRule rule("smaller", dnsQuestion.getData().size() + 1);
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), true);
+ }
+
+ {
+ PayloadSizeRule rule("greaterOrEqual", dnsQuestion.getData().size());
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), true);
+ BOOST_CHECK_EQUAL(rule.toString(), "payload size is equal to or greater than " + std::to_string(dnsQuestion.getData().size()));
+ }
+
+ {
+ PayloadSizeRule rule("greaterOrEqual", dnsQuestion.getData().size() - 1);
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), true);
+ }
+
+ {
+ PayloadSizeRule rule("greaterOrEqual", dnsQuestion.getData().size() + 1);
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), false);
+ }
+
+ {
+ PayloadSizeRule rule("smallerOrEqual", dnsQuestion.getData().size());
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), true);
+ BOOST_CHECK_EQUAL(rule.toString(), "payload size is equal to or smaller than " + std::to_string(dnsQuestion.getData().size()));
+ }
+
+ {
+ PayloadSizeRule rule("smallerOrEqual", dnsQuestion.getData().size() + 1);
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), true);
+ }
+
+ {
+ PayloadSizeRule rule("smallerOrEqual", dnsQuestion.getData().size() - 1);
+ BOOST_CHECK_EQUAL(rule.matches(&dnsQuestion), false);
+ }
+
+ BOOST_CHECK_THROW(PayloadSizeRule("invalid", 42U), std::runtime_error);
+}
+
BOOST_AUTO_TEST_SUITE_END()