class ObservableHttpsServer(ObservableHttpServer): def __init__(self, *args, **kwargs): self._keyfile = kwargs.pop('keyfile') self._certfile = kwargs.pop('certfile') ObservableHttpServer.__init__(self, *args, **kwargs) def startServer(self): """Starts server, When running a https server on port 443, this method should be called by the root user. In other cases it will be started when initializing all observers, see observer_init() """ self._httpsserver = HttpsServer( reactor=self._reactor, port=self._port, generatorFactory=self._connect, timeout=self._timeout, prio=self._prio, sok=self._sok, keyfile=self._keyfile, certfile=self._certfile, maxConnections=self._maxConnections, errorHandler=self._error, compressResponse=self._compressResponse, bindAddress=self._bindAddress ) self._httpsserver.listen() self._started = True
def testConnect(self): self.req = False serverResponse = 'Hello World' def onRequest(**kwargs): yield 'HTTP/1.0 200 OK\r\n\r\n' + serverResponse self.req = True port = PortNumberGenerator.next() with Reactor() as reactor: try: server = HttpsServer(reactor, port, onRequest, keyfile='ssl/server.pkey', certfile='ssl/server.cert') server.listen() p = Popen('wget -O - --no-check-certificate --quiet https://localhost:%s' % port, shell=True, stdout=PIPE) popenStdout = [] def readPopenStdout(): popenStdout.append(p.stdout.read()) reactor.addReader(p.stdout, readPopenStdout) while not self.req: reactor.step() reactor.step() self.assertEquals(1, len(popenStdout)) self.assertEquals(serverResponse, popenStdout[0]) finally: server.shutdown() # cleanup reactor.removeReader(p.stdout)
class ObservableHttpsServer(ObservableHttpServer): def __init__(self, *args, **kwargs): self._keyfile = kwargs.pop('keyfile') self._certfile = kwargs.pop('certfile') ObservableHttpServer.__init__(self, *args, **kwargs) def startServer(self): """Starts server, When running a https server on port 443, this method should be called by the root user. In other cases it will be started when initializing all observers, see observer_init() """ self._httpsserver = HttpsServer( reactor=self._reactor, port=self._port, generatorFactory=self._connect, timeout=self._timeout, prio=self._prio, sok=self._sok, keyfile=self._keyfile, certfile=self._certfile, maxConnections=self._maxConnections, errorHandler=self._error, compressResponse=self._compressResponse, bindAddress=self._bindAddress) self._httpsserver.listen() self._started = True
def testConnectBindAddress(self): reactor = CallTrace() port = PortNumberGenerator.next() server = HttpsServer(reactor, port, lambda **kwargs: None, bindAddress='127.0.0.1', keyfile='ssl/server.pkey', certfile='ssl/server.cert') server.listen() self.assertEquals(('127.0.0.1', port), server._sok.getsockname())