Browse 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 15 years ago
parent
commit
4a77769856
3 changed files with 10 additions and 4 deletions
  1. 2 3
      src/bin/auth/asio_link.cc
  2. 1 1
      src/bin/auth/asio_link.h
  3. 7 0
      src/bin/auth/tests/asio_link_unittest.cc

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

@@ -510,9 +510,8 @@ IOServiceImpl::IOServiceImpl(AuthSrv* auth_server, const char* const address,
 
     try {
         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) {

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

@@ -390,7 +390,7 @@ public:
     /// \brief The constructor.  Currently very specific to the authoritative
     /// server implementation.
     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.
     ~IOService();
     //@}

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

@@ -89,6 +89,13 @@ TEST(IOSocketTest, dummySockets) {
     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*
 resolveAddress(const int family, const int sock_type, const int protocol) {
     const char* const addr = (family == AF_INET6) ?