Browse Source

[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.
Michal 'vorner' Vaner 13 years ago
parent
commit
6d541b2ace

+ 16 - 1
src/bin/auth/tests/auth_srv_unittest.cc

@@ -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");
 }
 
 }

+ 4 - 1
src/bin/auth/tests/config_unittest.cc

@@ -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) {

+ 1 - 1
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));

+ 2 - 3
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"
                                "   }"
                                "]"

+ 8 - 4
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<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_;
 };
 
 }

+ 5 - 2
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();