]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[805] Make the auth tests pass
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Fri, 23 Dec 2011 13:46:02 +0000 (14:46 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Fri, 23 Dec 2011 13:46:02 +0000 (14:46 +0100)
We need to fake the SocketRequestor in them. This also asked for little
update of the general base for socket requesting tests.

src/bin/auth/tests/auth_srv_unittest.cc
src/bin/auth/tests/config_unittest.cc
src/lib/server_common/tests/portconfig_unittest.cc
src/lib/testutils/portconfig.h
src/lib/testutils/socket_request.h
src/lib/testutils/srv_test.h

index ac25cd60d991492e0c071a60257a1b38459de0f0..d3d9b0af0c0dc7ca8120b868b35ea95fa77b40b2 100644 (file)
@@ -41,6 +41,7 @@
 #include <testutils/dnsmessage_test.h>
 #include <testutils/srv_test.h>
 #include <testutils/portconfig.h>
+#include <testutils/socket_request.h>
 
 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<uint8_t> 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");
 }
 
 }
index dadb0ee39019aa5301b817da0e583ad3dc0e8374..90048ac5f75b10481a066e7b6c66ca284741263b 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <testutils/mockups.h>
 #include <testutils/portconfig.h>
+#include <testutils/socket_request.h>
 
 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) {
index 7e3ec1f2a1feca9cf7f22ff8378972665662e9b3..9e6ad460e534cd824fcf33fe254f321bb3f75065 100644 (file)
@@ -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));
index 8e61ffc2d258a29f4a99b4dd6651a88ff5dd8401..a4dc2bd6bdfb76f90ddea5fdce8623642e70bad8 100644 (file)
@@ -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"
                                "   }"
                                "]"
index aea5667f8d5fc88303c5b8a7bdf17866617c4375..500705f874975e4fadab9bffb3df25aafc78fde4 100644 (file)
@@ -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<std::string> released_tokens_;
     std::vector<std::string> 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_;
 };
 
 }
index c92e87666979cf26ab53bfe1fe108efd153cee8b..c2624470dd9f4b4937e0b401394bb71be0e273c0 100644 (file)
@@ -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();