2016-04-18 17:52:10 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include <Common.hpp>
|
|
|
|
#include <Util.hpp>
|
|
|
|
|
|
|
|
/// WhiteBox unit-tests.
|
|
|
|
class WhiteBoxTests : public CPPUNIT_NS::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE(WhiteBoxTests);
|
|
|
|
|
|
|
|
CPPUNIT_TEST(testRegexListMatcher);
|
2016-04-18 20:11:33 -05:00
|
|
|
CPPUNIT_TEST(testRegexListMatcher_Init);
|
2016-04-18 17:52:10 -05:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void testRegexListMatcher();
|
2016-04-18 20:11:33 -05:00
|
|
|
void testRegexListMatcher_Init();
|
2016-04-18 17:52:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
void WhiteBoxTests::testRegexListMatcher()
|
|
|
|
{
|
|
|
|
Util::RegexListMatcher matcher;
|
|
|
|
|
|
|
|
matcher.allow("localhost");
|
|
|
|
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"));
|
|
|
|
|
|
|
|
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.deny("192\\.168\\.1\\..*");
|
|
|
|
CPPUNIT_ASSERT(!matcher.match("192.168.1.1"));
|
|
|
|
|
|
|
|
matcher.allow("staging\\.collaboracloudsuite\\.com.*");
|
|
|
|
matcher.deny(".*collaboracloudsuite.*");
|
|
|
|
CPPUNIT_ASSERT(!matcher.match("staging.collaboracloudsuite"));
|
|
|
|
CPPUNIT_ASSERT(!matcher.match("web.collaboracloudsuite"));
|
|
|
|
CPPUNIT_ASSERT(!matcher.match("staging.collaboracloudsuite.com"));
|
2016-04-18 20:11:33 -05:00
|
|
|
|
|
|
|
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.."));
|
2016-04-18 17:52:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests);
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|