loolwsd/Util.hpp | 22 ++++++++++++++++++++ loolwsd/test/WhiteBoxTests.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
New commits: commit 3878f3b5154d64fb9416915b0924c4566312a3c9 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Mon Apr 18 21:11:33 2016 -0400 loolwsd: initialization and resetting support in RegexListMatcher Change-Id: Ic262cf9e4a21d30b6dfd9d9fc0d895f89d7d8e7b Reviewed-on: https://gerrit.libreoffice.org/24232 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 1635c5d..3b466cf 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -127,6 +127,22 @@ namespace Util class RegexListMatcher { public: + RegexListMatcher() + { + } + + RegexListMatcher(std::initializer_list<std::string> allow) : + _allowed(allow) + { + } + + RegexListMatcher(std::initializer_list<std::string> allow, + std::initializer_list<std::string> deny) : + _allowed(allow), + _denied(deny) + { + } + void allow(const std::string& pattern) { _allowed.insert(pattern); } void deny(const std::string& pattern) { @@ -134,6 +150,12 @@ namespace Util _denied.insert(pattern); } + void clear() + { + _allowed.clear(); + _denied.clear(); + } + bool match(const std::string& subject) const { return (match(_allowed, subject) && !match(_denied, subject)); diff --git a/loolwsd/test/WhiteBoxTests.cpp b/loolwsd/test/WhiteBoxTests.cpp index 79104f1..92b3df9 100644 --- a/loolwsd/test/WhiteBoxTests.cpp +++ b/loolwsd/test/WhiteBoxTests.cpp @@ -20,10 +20,12 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE(WhiteBoxTests); CPPUNIT_TEST(testRegexListMatcher); + CPPUNIT_TEST(testRegexListMatcher_Init); CPPUNIT_TEST_SUITE_END(); void testRegexListMatcher(); + void testRegexListMatcher_Init(); }; void WhiteBoxTests::testRegexListMatcher() @@ -58,6 +60,47 @@ void WhiteBoxTests::testRegexListMatcher() CPPUNIT_ASSERT(!matcher.match("staging.collaboracloudsuite")); CPPUNIT_ASSERT(!matcher.match("web.collaboracloudsuite")); CPPUNIT_ASSERT(!matcher.match("staging.collaboracloudsuite.com")); + + matcher.allow("10\\.10\\.[0-9]{1,3}\\.[0-9]{1,3}"); + matcher.deny("10\\.10\\.10\\.10"); + CPPUNIT_ASSERT(matcher.match("10.10.001.001")); + CPPUNIT_ASSERT(!matcher.match("10.10.10.10")); + CPPUNIT_ASSERT(matcher.match("10.10.250.254")); +} + + +void WhiteBoxTests::testRegexListMatcher_Init() +{ + Util::RegexListMatcher matcher({"localhost", "192\\..*"}, {"192\\.168\\..*"}); + + CPPUNIT_ASSERT(matcher.match("localhost")); + CPPUNIT_ASSERT(!matcher.match("")); + CPPUNIT_ASSERT(!matcher.match("localhost2")); + CPPUNIT_ASSERT(!matcher.match("xlocalhost")); + CPPUNIT_ASSERT(!matcher.match("192.168.1.1")); + CPPUNIT_ASSERT(matcher.match("192.172.10.122")); + + matcher.deny("localhost"); + CPPUNIT_ASSERT(!matcher.match("localhost")); + + matcher.allow("www[0-9].*"); + CPPUNIT_ASSERT(matcher.match("www1example")); + + matcher.allow("192\\.168\\..*\\..*"); + CPPUNIT_ASSERT(!matcher.match("192.168.1.1")); + CPPUNIT_ASSERT(!matcher.match("192.168.159.1")); + CPPUNIT_ASSERT(!matcher.match("192.168.1.134")); + CPPUNIT_ASSERT(matcher.match("192.169.1.1")); + CPPUNIT_ASSERT(!matcher.match("192.168..")); + + matcher.clear(); + + matcher.allow("192\\.168\\..*\\..*"); + CPPUNIT_ASSERT(matcher.match("192.168.1.1")); + CPPUNIT_ASSERT(matcher.match("192.168.159.1")); + CPPUNIT_ASSERT(matcher.match("192.168.1.134")); + CPPUNIT_ASSERT(!matcher.match("192.169.1.1")); + CPPUNIT_ASSERT(matcher.match("192.168..")); } CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits