예제 #1
0
 def test_ssl(self):
     'Test serving over SSL'
     s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
     s.bind(('localhost', 0))
     address = s.getsockname()[0]
     with TemporaryDirectory('srv-test-ssl') as tdir:
         cert_file, key_file, ca_file = map(lambda x: os.path.join(tdir, x),
                                            'cka')
         create_server_cert(address,
                            ca_file,
                            cert_file,
                            key_file,
                            key_size=1024)
         ctx = ssl.create_default_context(cafile=ca_file)
         with TestServer(lambda data: (data.path[0] + data.read()),
                         ssl_certfile=cert_file,
                         ssl_keyfile=key_file) as server:
             conn = httplib.HTTPSConnection(server.address[0],
                                            server.address[1],
                                            strict=True,
                                            context=ctx)
             conn.request('GET', '/test', 'body')
             r = conn.getresponse()
             self.ae(r.status, httplib.OK)
             self.ae(r.read(), b'testbody')
             cert = conn.sock.getpeercert()
             subject = dict(x[0] for x in cert['subject'])
             self.ae(subject['commonName'], address)
예제 #2
0
 def test_ssl(self):
     'Test serving over SSL'
     address = '127.0.0.1'
     with TemporaryDirectory('srv-test-ssl') as tdir:
         cert_file, key_file, ca_file = map(lambda x: os.path.join(tdir, x),
                                            'cka')
         create_server_cert(address,
                            ca_file,
                            cert_file,
                            key_file,
                            key_size=1024)
         ctx = ssl.create_default_context(cafile=ca_file)
         with TestServer(lambda data:
                         (data.path[0] + data.read().decode('utf-8')),
                         ssl_certfile=cert_file,
                         ssl_keyfile=key_file,
                         listen_on=address,
                         port=0) as server:
             conn = http_client.HTTPSConnection(address,
                                                server.address[1],
                                                context=ctx)
             conn.request('GET', '/test', 'body')
             r = conn.getresponse()
             self.ae(r.status, http_client.OK)
             self.ae(r.read(), b'testbody')
             cert = conn.sock.getpeercert()
             subject = dict(x[0] for x in cert['subject'])
             self.ae(subject['commonName'], address)
예제 #3
0
파일: loop.py 프로젝트: Mymei2/calibre
 def test_ssl(self):
     'Test serving over SSL'
     address = '127.0.0.1'
     with TemporaryDirectory('srv-test-ssl') as tdir:
         cert_file, key_file, ca_file = map(lambda x:os.path.join(tdir, x), 'cka')
         create_server_cert(address, ca_file, cert_file, key_file, key_size=1024)
         ctx = ssl.create_default_context(cafile=ca_file)
         with TestServer(lambda data:(data.path[0] + data.read()), ssl_certfile=cert_file, ssl_keyfile=key_file, listen_on=address, port=0) as server:
             conn = httplib.HTTPSConnection(address, server.address[1], strict=True, context=ctx)
             conn.request('GET', '/test', 'body')
             r = conn.getresponse()
             self.ae(r.status, httplib.OK)
             self.ae(r.read(), b'testbody')
             cert = conn.sock.getpeercert()
             subject = dict(x[0] for x in cert['subject'])
             self.ae(subject['commonName'], address)
예제 #4
0
파일: loop.py 프로젝트: x007007007/calibre
 def test_ssl(self):
     'Test serving over SSL'
     s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
     s.bind(('localhost', 1338 if is_travis else 0))
     address = s.getsockname()[0]
     with TemporaryDirectory('srv-test-ssl') as tdir:
         cert_file, key_file, ca_file = map(lambda x:os.path.join(tdir, x), 'cka')
         create_server_cert(address, ca_file, cert_file, key_file, key_size=1024)
         ctx = ssl.create_default_context(cafile=ca_file)
         with TestServer(lambda data:(data.path[0] + data.read()), ssl_certfile=cert_file, ssl_keyfile=key_file) as server:
             conn = httplib.HTTPSConnection(server.address[0], server.address[1], strict=True, context=ctx)
             conn.request('GET', '/test', 'body')
             r = conn.getresponse()
             self.ae(r.status, httplib.OK)
             self.ae(r.read(), b'testbody')
             cert = conn.sock.getpeercert()
             subject = dict(x[0] for x in cert['subject'])
             self.ae(subject['commonName'], address)
예제 #5
0
파일: loop.py 프로젝트: ZRhinoceros/calibre
 def test_ssl(self):
     "Test serving over SSL"
     s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
     s.bind(("localhost", 0))
     address = s.getsockname()[0]
     with TemporaryDirectory("srv-test-ssl") as tdir:
         cert_file, key_file, ca_file = map(lambda x: os.path.join(tdir, x), "cka")
         create_server_cert(address, ca_file, cert_file, key_file, key_size=1024)
         ctx = ssl.create_default_context(cafile=ca_file)
         with TestServer(
             lambda data: (data.path[0] + data.read()), ssl_certfile=cert_file, ssl_keyfile=key_file
         ) as server:
             conn = httplib.HTTPSConnection(server.address[0], server.address[1], strict=True, context=ctx)
             conn.request("GET", "/test", "body")
             r = conn.getresponse()
             self.ae(r.status, httplib.OK)
             self.ae(r.read(), b"testbody")
             cert = conn.sock.getpeercert()
             subject = dict(x[0] for x in cert["subject"])
             self.ae(subject["commonName"], address)