def test_switch_to_ssl(self): """Switch the socket to use SSL""" args = { 'ca': os.path.join(tests.SSL_DIR, 'tests_CA_cert.pem'), 'cert': os.path.join(tests.SSL_DIR, 'tests_client_cert.pem'), 'key': os.path.join(tests.SSL_DIR, 'tests_client_key.pem'), } self.assertRaises(errors.InterfaceError, self.cnx.switch_to_ssl, **args) # Handshake failure try: host = self._host.split('%')[0] network.inet_pton(socket.AF_INET6, host) family = socket.AF_INET6 except socket.error: family = socket.AF_INET (family, socktype, proto, canonname, sockaddr) = socket.getaddrinfo(self._host, self._port, family, socket.SOCK_STREAM)[0] sock = socket.socket(family, socktype, proto) sock.settimeout(4) sock.connect(sockaddr) self.cnx.sock = sock self.assertRaises(errors.InterfaceError, self.cnx.switch_to_ssl, **args)
def test_switch_to_ssl(self): """Switch the socket to use SSL""" if not tests.SSL_AVAILABLE: tests.MESSAGES['WARNINGS'].append( "Could not test switch to SSL. Make sure Python supports SSL.") return args = { 'ca': os.path.join(tests.SSL_DIR, 'tests_CA_cert.pem'), 'cert': os.path.join(tests.SSL_DIR, 'tests_client_cert.pem'), 'key': os.path.join(tests.SSL_DIR, 'tests_client_key.pem'), } self.assertRaises(errors.InterfaceError, self.cnx.switch_to_ssl, **args) # Handshake failure try: (host,) = self._host.split('%') network.inet_pton(socket.AF_INET6, host) family = socket.AF_INET6 except socket.error: family = socket.AF_INET (family, socktype, proto, canonname, sockaddr) = socket.getaddrinfo( self._host, self._port, family, socket.SOCK_STREAM)[0] sock = socket.socket(family, socktype, proto) sock.settimeout(4) sock.connect(sockaddr) self.cnx.sock = sock self.assertRaises(errors.InterfaceError, self.cnx.switch_to_ssl, **args)
def test_inet_pton(self): """Define inet_pton""" if os.name == 'nt': self.assertTrue(hasattr(network.inet_pton, '__call__')) else: self.assertEqual(socket.inet_pton, network.inet_pton) cases = [ ('::1', socket.AF_INET6, False), ('127.0.0.1', socket.AF_INET, False), ('2001::14:06:77', socket.AF_INET6, False), ('xx:00:xx', socket.AF_INET6, True), ] for addr, family, should_raise in cases: try: network.inet_pton(family, addr) except socket.error, err: if not should_raise: self.fail('%s incorrectly raised socket.error' % addr) else: if should_raise: self.fail('%s should have raised socket.error' % addr)