From: Francis Dupont Date: Tue, 31 May 2022 22:04:59 +0000 (+0200) Subject: [#1706] Added (too) basic unit tests X-Git-Tag: Kea-2.1.7~51 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=609f4397a363dc1920f3e97b998910a036e2763b;p=thirdparty%2Fkea.git [#1706] Added (too) basic unit tests --- diff --git a/src/lib/config/tests/Makefile.am b/src/lib/config/tests/Makefile.am index 88e34b633e..b58dada343 100644 --- a/src/lib/config/tests/Makefile.am +++ b/src/lib/config/tests/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = testdata . AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib AM_CPPFLAGS += $(BOOST_INCLUDES) $(CRYPTO_CFLAGS) $(CRYPTO_INCLUDES) AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/config/tests\" +AM_CPPFLAGS += -DTEST_CA_DIR=\"$(srcdir)/../../asiolink/testutils/ca\" AM_CXXFLAGS = $(KEA_CXXFLAGS) diff --git a/src/lib/config/tests/cmd_http_listener_unittests.cc b/src/lib/config/tests/cmd_http_listener_unittests.cc index 4eca580ff6..854a471eea 100644 --- a/src/lib/config/tests/cmd_http_listener_unittests.cc +++ b/src/lib/config/tests/cmd_http_listener_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2021-2022 Internet Systems Consortium, Inc. ("ISC") // // 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 @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -24,10 +25,11 @@ #include using namespace isc; +using namespace isc::asiolink; +using namespace isc::asiolink::test; using namespace isc::config; using namespace isc::data; using namespace boost::asio::ip; -using namespace isc::asiolink; using namespace isc::http; using namespace isc::util; namespace ph = std::placeholders; @@ -731,7 +733,7 @@ public: TEST_F(CmdHttpListenerTest, basics) { // Make sure multi-threading is off. MultiThreadingMgr::instance().setMode(false); - asiolink::IOAddress address(SERVER_ADDRESS); + IOAddress address(SERVER_ADDRESS); uint16_t port = SERVER_PORT; // Make sure we can create one. @@ -742,6 +744,7 @@ TEST_F(CmdHttpListenerTest, basics) { EXPECT_EQ(listener_->getAddress(), address); EXPECT_EQ(listener_->getPort(), port); EXPECT_EQ(listener_->getThreadPoolSize(), 1); + EXPECT_FALSE(listener_->getTlsContext()); // It should not have an IOService, should not be listening and // should have no threads. @@ -942,4 +945,36 @@ TEST_F(CmdHttpListenerTest, pauseAndResume) { workPauseAndResume(num_threads, num_clients, num_pauses); } +// Check if a TLS listener can be created. +TEST_F(CmdHttpListenerTest, tls) { + IOAddress address(SERVER_ADDRESS); + uint16_t port = SERVER_PORT; + TlsContextPtr context; + configServer(context); + + // Make sure we can create the listener. + ASSERT_NO_THROW_LOG(listener_.reset(new CmdHttpListener(address, port, 1, context))); + EXPECT_EQ(listener_->getAddress(), address); + EXPECT_EQ(listener_->getPort(), port); + EXPECT_EQ(listener_->getThreadPoolSize(), 1); + EXPECT_EQ(listener_->getTlsContext(), context); + EXPECT_TRUE(listener_->isStopped()); + EXPECT_EQ(listener_->getThreadCount(), 0); + + // Make sure we can start it and it's listening with 1 thread. + ASSERT_NO_THROW_LOG(listener_->start()); + ASSERT_TRUE(listener_->isRunning()); + EXPECT_EQ(listener_->getThreadCount(), 1); + ASSERT_TRUE(listener_->getThreadIOService()); + EXPECT_FALSE(listener_->getThreadIOService()->stopped()); + + // Stop it. + ASSERT_NO_THROW_LOG(listener_->stop()); + ASSERT_TRUE(listener_->isStopped()); + EXPECT_EQ(listener_->getThreadCount(), 0); + EXPECT_EQ(listener_->getThreadPoolSize(), 1); + ASSERT_FALSE(listener_->getThreadIOService()); + EXPECT_TRUE(listener_->isStopped()); +} + } // end of anonymous namespace