From: Michal 'vorner' Vaner Date: Fri, 23 Dec 2011 13:46:02 +0000 (+0100) Subject: [805] Make the auth tests pass X-Git-Tag: trac2351_base~304^2~16^2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6d541b2acec75ea2ab8811619f8ccda8c05eec69;p=thirdparty%2Fkea.git [805] Make the auth tests pass We need to fake the SocketRequestor in them. This also asked for little update of the general base for socket requesting tests. --- diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index ac25cd60d9..d3d9b0af0c 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -41,6 +41,7 @@ #include #include #include +#include using namespace std; using namespace isc::cc; @@ -64,9 +65,10 @@ const char* const CONFIG_TESTDB = const char* const BADCONFIG_TESTDB = "{ \"database_file\": \"" TEST_DATA_DIR "/nodir/notexist\"}"; -class AuthSrvTest : public SrvTestBase { +class AuthSrvTest : public SrvTestBase, public TestSocketRequestor { protected: AuthSrvTest() : + TestSocketRequestor(dnss_, address_store_, 53210), dnss_(ios_, NULL, NULL, NULL), server(true, xfrout), rrclass(RRClass::IN()) @@ -86,6 +88,7 @@ protected: AuthSrv server; const RRClass rrclass; vector response_data; + AddressList address_store_; }; // A helper function that builds a response to version.bind/TXT/CH that @@ -888,6 +891,18 @@ TEST_F(AuthSrvTest, stop) { TEST_F(AuthSrvTest, listenAddresses) { isc::testutils::portconfig::listenAddresses(server); + // Check it requests the correct addresses + const char* tokens[] = { + "TCP:127.0.0.1:53210:1", + "UDP:127.0.0.1:53210:2", + "TCP:::1:53210:3", + "UDP:::1:53210:4", + NULL + }; + checkTokens(tokens, given_tokens_, "Given tokens"); + // It returns back to empty set of addresses afterwards, so + // they should be released + checkTokens(tokens, released_tokens_, "Released tokens"); } } diff --git a/src/bin/auth/tests/config_unittest.cc b/src/bin/auth/tests/config_unittest.cc index dadb0ee390..90048ac5f7 100644 --- a/src/bin/auth/tests/config_unittest.cc +++ b/src/bin/auth/tests/config_unittest.cc @@ -31,6 +31,7 @@ #include #include +#include using namespace isc::dns; using namespace isc::data; @@ -39,9 +40,10 @@ using namespace isc::asiodns; using namespace isc::asiolink; namespace { -class AuthConfigTest : public ::testing::Test { +class AuthConfigTest : public isc::testutils::TestSocketRequestor { protected: AuthConfigTest() : + TestSocketRequestor(dnss_, address_store_, 53210), dnss_(ios_, NULL, NULL, NULL), rrclass(RRClass::IN()), server(true, xfrout) @@ -53,6 +55,7 @@ protected: const RRClass rrclass; MockXfroutClient xfrout; AuthSrv server; + isc::server_common::portconfig::AddressList address_store_; }; TEST_F(AuthConfigTest, datasourceConfig) { diff --git a/src/lib/server_common/tests/portconfig_unittest.cc b/src/lib/server_common/tests/portconfig_unittest.cc index 7e3ec1f2a1..9e6ad460e5 100644 --- a/src/lib/server_common/tests/portconfig_unittest.cc +++ b/src/lib/server_common/tests/portconfig_unittest.cc @@ -133,7 +133,7 @@ TEST_F(ParseAddresses, invalid) { struct InstallListenAddresses : public testutils::TestSocketRequestor { InstallListenAddresses() : // The members aren't initialized yet, but we need to store refs only - TestSocketRequestor(dnss_, store_), dnss_(ios_, NULL, NULL, NULL) + TestSocketRequestor(dnss_, store_, 5288), dnss_(ios_, NULL, NULL, NULL) { valid_.push_back(AddressPair("127.0.0.1", 5288)); valid_.push_back(AddressPair("::1", 5288)); diff --git a/src/lib/testutils/portconfig.h b/src/lib/testutils/portconfig.h index 8e61ffc2d2..a4dc2bd6bd 100644 --- a/src/lib/testutils/portconfig.h +++ b/src/lib/testutils/portconfig.h @@ -95,12 +95,11 @@ listenAddressConfig(Server& server) { EXPECT_EQ("127.0.0.1", server.getListenAddresses()[0].first); EXPECT_EQ(53210, server.getListenAddresses()[0].second); - // As this is example address, the machine should not have it on - // any interface + // This address is rejected by the test socket requestor config = Element::fromJSON("{" "\"listen_on\": [" " {" - " \"address\": \"192.0.2.0\"," + " \"address\": \"192.0.2.2\"," " \"port\": 53210" " }" "]" diff --git a/src/lib/testutils/socket_request.h b/src/lib/testutils/socket_request.h index aea5667f8d..500705f874 100644 --- a/src/lib/testutils/socket_request.h +++ b/src/lib/testutils/socket_request.h @@ -36,12 +36,15 @@ namespace testutils { // TODO Docs class TestSocketRequestor : public isc::server_common::SocketRequestor, - public ::testing::Test { + virtual public ::testing::Test { protected: TestSocketRequestor(asiodns::DNSService& dnss, - server_common::portconfig::AddressList& store) : - last_token_(0), break_rollback_(false), dnss_(dnss), store_(store) + server_common::portconfig::AddressList& store, + uint16_t expect_port) : + last_token_(0), break_rollback_(false), dnss_(dnss), store_(store), + expect_port_(expect_port) {} + virtual ~ TestSocketRequestor() {} // Store the tokens as they go in and out std::vector released_tokens_; std::vector given_tokens_; @@ -70,7 +73,7 @@ protected: } const std::string proto(protocol == TCP ? "TCP" : "UDP"); size_t number = ++ last_token_; - EXPECT_EQ(5288, port); + EXPECT_EQ(expect_port_, port); EXPECT_EQ(DONT_SHARE, mode); EXPECT_EQ("dummy_app", name); const std::string token(proto + ":" + address + ":" + @@ -112,6 +115,7 @@ protected: private: asiodns::DNSService& dnss_; server_common::portconfig::AddressList& store_; + uint16_t expect_port_; }; } diff --git a/src/lib/testutils/srv_test.h b/src/lib/testutils/srv_test.h index c92e876669..c2624470dd 100644 --- a/src/lib/testutils/srv_test.h +++ b/src/lib/testutils/srv_test.h @@ -44,8 +44,11 @@ extern const unsigned int RA_FLAG; extern const unsigned int AD_FLAG; extern const unsigned int CD_FLAG; -// The base class for Auth and Recurse test case -class SrvTestBase : public ::testing::Test { +/// \brief The base class for Auth and Recurse test case +/// +/// The Test is inherited virtually because some tests are built of more +/// test-base-components, all of which need to inherit Test. +class SrvTestBase : virtual public ::testing::Test { protected: SrvTestBase(); virtual ~SrvTestBase();