def test_auto_ping(self): self.protocol.autoPingInterval = 1 self.protocol.websocket_protocols = [Mock()] self.protocol.websocket_extensions = [] self.protocol._onOpen = lambda: None self.protocol._wskey = '0' * 24 self.protocol.peer = Mock() # usually provided by the Twisted or asyncio specific # subclass, but we're testing the parent here... self.protocol._onConnect = Mock() self.protocol._closeConnection = Mock() # set up a connection self.protocol._actuallyStartHandshake( ConnectingRequest( host="example.com", port=80, resource="/ws", )) key = self.protocol.websocket_key + WebSocketProtocol._WS_MAGIC self.protocol.data = (b"HTTP/1.1 101 Switching Protocols\x0d\x0a" b"Upgrade: websocket\x0d\x0a" b"Connection: upgrade\x0d\x0a" b"Sec-Websocket-Accept: " + b64encode(sha1(key).digest()) + b"\x0d\x0a\x0d\x0a") self.protocol.processHandshake() self.assertTrue(self.protocol.autoPingPendingCall is not None)
def onConnecting(self, transport_details): if self.debug: log.msg( "Connecting; transport details: {}".format(transport_details)) auth_header = encode_http_authorization_header(self.factory.name, self.factory.password) return ConnectingRequest(host=self.factory.host, port=self.factory.port, resource=self.factory.resource, headers={"Authorization": auth_header}, useragent=self.factory.useragent, origin=self.factory.origin, protocols=self.factory.protocols)
def test_str_connecting(self): req = ConnectingRequest(host="example.com", port="1234", resource="/ws") # we can str() this and it doesn't fail str(req)
def onConnecting(self, transport_details): return ConnectingRequest( host="example.com", port=443, resource="/ws", )