def test_returns_proper_fqdn(self):
     """
     Return the proper FQDN of the host when it's resolvable both
     ways.
     """
     self.mock_getaddrinfo.return_value = (
         [0, 1, 2, 3, ['take_me', 'not_me']],)
     self.mock_gethostbyaddr.return_value = ['proper_FQDN']
     return_value = sanitize_host('erroneous_host')
     self.mock_getaddrinfo.assert_called_once_with(
         'erroneous_host', 443, socket.AF_INET, socket.SOCK_STREAM)
     self.mock_gethostbyaddr.assert_called_once_with('take_me')
     self.assertEqual(return_value, 'proper_FQDN')
 def test_returns_proper_fqdn(self):
     """
     Return the proper FQDN of the host when it's resolvable both
     ways.
     """
     self.mock_getaddrinfo.return_value = ([
         0, 1, 2, 3, ['take_me', 'not_me']
     ], )
     self.mock_gethostbyaddr.return_value = ['proper_FQDN']
     return_value = sanitize_host('erroneous_host')
     self.mock_getaddrinfo.assert_called_once_with('erroneous_host', 443,
                                                   socket.AF_INET,
                                                   socket.SOCK_STREAM)
     self.mock_gethostbyaddr.assert_called_once_with('take_me')
     self.assertEqual(return_value, 'proper_FQDN')
Beispiel #3
0
 def test_raises_error_on_hostnotfound(self):
     """
     Raise an error when the host is not resolvable.
     """
     self.mock_getaddrinfo.side_effect = socket.gaierror('error_message')
     return_value = None
     with self.assertRaises(CMDLineExit) as cm:
         return_value = sanitize_host('erroneous_host')
     self.assertIsNone(return_value)
     self.assertEqual(cm.exception.args[0],
                      'Could not resolve hostname \'afp\': error_message')
     self.mock_getaddrinfo.assert_called_once_with('erroneous_host', 443,
                                                   socket.AF_INET,
                                                   socket.SOCK_STREAM)
     self.mock_gethostbyaddr.assert_not_called()
 def test_raises_error_on_hostnotfound(self):
     """
     Raise an error when the host is not resolvable.
     """
     self.mock_getaddrinfo.side_effect = socket.gaierror('error_message')
     return_value = None
     with self.assertRaises(CMDLineExit) as cm:
         return_value = sanitize_host('erroneous_host')
     self.assertIsNone(return_value)
     self.assertEqual(
         cm.exception.args[0],
         'Could not resolve hostname \'erroneous_host\': error_message')
     self.mock_getaddrinfo.assert_called_once_with(
         'erroneous_host', 443, socket.AF_INET, socket.SOCK_STREAM)
     self.mock_gethostbyaddr.assert_not_called()
 def test_raises_error_on_reversenotfound(self):
     """
     Raise an error when the host is resolvable, but its reverse is
     not.
     """
     self.mock_getaddrinfo.return_value = (
         [0, 1, 2, 3, ['take_me', 'not_me']],)
     self.mock_gethostbyaddr.side_effect = socket.gaierror('error_message')
     return_value = None
     with self.assertRaises(CMDLineExit) as cm:
         return_value = sanitize_host('erroneous_host')
     self.assertIsNone(return_value)
     self.assertEqual(
         cm.exception.args[0],
         'DNS reverse lookup failed for IP take_me: error_message')
     self.mock_getaddrinfo.assert_called_once_with(
         'erroneous_host', 443, socket.AF_INET, socket.SOCK_STREAM)
     self.mock_gethostbyaddr.assert_called_once_with('take_me')
 def test_raises_error_on_reversenotfound(self):
     """
     Raise an error when the host is resolvable, but its reverse is
     not.
     """
     self.mock_getaddrinfo.return_value = ([
         0, 1, 2, 3, ['take_me', 'not_me']
     ], )
     self.mock_gethostbyaddr.side_effect = socket.gaierror('error_message')
     return_value = None
     with self.assertRaises(CMDLineExit) as cm:
         return_value = sanitize_host('erroneous_host')
     self.assertIsNone(return_value)
     self.assertEqual(
         cm.exception.args[0],
         'DNS reverse lookup failed for IP take_me: error_message')
     self.mock_getaddrinfo.assert_called_once_with('erroneous_host', 443,
                                                   socket.AF_INET,
                                                   socket.SOCK_STREAM)
     self.mock_gethostbyaddr.assert_called_once_with('take_me')