diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:14:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:14:51 +0000 |
commit | bc282425088455198a7a99511c75914477d4ed32 (patch) | |
tree | 1b1fb887a634136a093deea7e4dd95d054201e7a /test-dnsdistrules_cc.cc | |
parent | Releasing progress-linux version 1.8.3-3~progress7.99u1. (diff) | |
download | dnsdist-bc282425088455198a7a99511c75914477d4ed32.tar.xz dnsdist-bc282425088455198a7a99511c75914477d4ed32.zip |
Merging upstream version 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.cc | 74 |
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() |