Parcourir la source

added tests on port string validity

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac221b@2465 e5f2f494-b856-4b98-b285-d166d9295462
JINMEI Tatuya il y a 15 ans
Parent
commit
4a77769856

+ 2 - 3
src/bin/auth/asio_link.cc

@@ -510,9 +510,8 @@ IOServiceImpl::IOServiceImpl(AuthSrv* auth_server, const char* const address,
 
 
     try {
     try {
         portnum = boost::lexical_cast<uint16_t>(port);
         portnum = boost::lexical_cast<uint16_t>(port);
-    } catch (const std::exception& ex) {
-        isc_throw(FatalError, "[b10-auth] Invalid port number '"
-                              << port << "'");
+    } catch (const boost::bad_lexical_cast& ex) {
+        isc_throw(IOError, "[b10-auth] Invalid port number '" << port << "'");
     }
     }
 
 
     if (address != NULL) {
     if (address != NULL) {

+ 1 - 1
src/bin/auth/asio_link.h

@@ -390,7 +390,7 @@ public:
     /// \brief The constructor.  Currently very specific to the authoritative
     /// \brief The constructor.  Currently very specific to the authoritative
     /// server implementation.
     /// server implementation.
     IOService(AuthSrv* auth_server, const char* const address,
     IOService(AuthSrv* auth_server, const char* const address,
-              const char* port, bool use_ipv4, bool use_ipv6);
+              const char* const port, bool use_ipv4, bool use_ipv6);
     /// \brief The destructor.
     /// \brief The destructor.
     ~IOService();
     ~IOService();
     //@}
     //@}

+ 7 - 0
src/bin/auth/tests/asio_link_unittest.cc

@@ -89,6 +89,13 @@ TEST(IOSocketTest, dummySockets) {
     EXPECT_EQ(-1, IOSocket::getDummyTCPSocket().getNative());
     EXPECT_EQ(-1, IOSocket::getDummyTCPSocket().getNative());
 }
 }
 
 
+TEST(IOServiceTest, badPort) {
+    EXPECT_THROW(IOService(NULL, NULL, "65536", true, false), IOError);
+    EXPECT_THROW(IOService(NULL, NULL, "5300.0", true, false), IOError);
+    EXPECT_THROW(IOService(NULL, NULL, "-1", true, false), IOError);
+    EXPECT_THROW(IOService(NULL, NULL, "domain", true, false), IOError);
+}
+
 struct addrinfo*
 struct addrinfo*
 resolveAddress(const int family, const int sock_type, const int protocol) {
 resolveAddress(const int family, const int sock_type, const int protocol) {
     const char* const addr = (family == AF_INET6) ?
     const char* const addr = (family == AF_INET6) ?