Exemple #1
0
    def setUp(self):
        t = FakeTransport()
        f = WebSocketServerFactory()
        f.log = txaio.make_logger()
        p = WebSocketServerProtocol()
        p.log = txaio.make_logger()
        p.factory = f
        p.transport = t

        p._connectionMade()
        p.state = p.STATE_OPEN
        p.websocket_version = 18

        self.protocol = p
        self.transport = t
        def setUp(self):
            from autobahn.twisted.websocket import WebSocketServerProtocol
            from autobahn.twisted.websocket import WebSocketServerFactory
            t = FakeTransport()
            f = WebSocketServerFactory()
            p = WebSocketServerProtocol()
            p.factory = f
            p.transport = t

            p._connectionMade()
            p.state = p.STATE_OPEN
            p.websocket_version = 18

            self.protocol = p
            self.transport = t
    def setUp(self):
        t = FakeTransport()
        f = WebSocketServerFactory()
        p = WebSocketServerProtocol()
        p.factory = f
        p.transport = t

        p._connectionMade()
        p.state = p.STATE_OPEN
        p.websocket_version = 18

        self.protocol = p
        self.transport = t
    def test_handshake_fails(self):
        """
        A handshake from a client only supporting Hixie-76 will fail.
        """
        from autobahn.twisted.websocket import WebSocketServerFactory
        from autobahn.twisted.websocket import WebSocketServerProtocol

        t = FakeTransport()
        f = WebSocketServerFactory()
        p = WebSocketServerProtocol()
        p.factory = f
        p.transport = t

        # from http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
        http_request = b"GET /demo HTTP/1.1\r\nHost: example.com\r\nConnection: Upgrade\r\nSec-WebSocket-Key2: 12998 5 Y3 1  .P00\r\nSec-WebSocket-Protocol: sample\r\nUpgrade: WebSocket\r\nSec-WebSocket-Key1: 4 @1  46546xW%0l 1 5\r\nOrigin: http://example.com\r\n\r\n^n:ds[4U"

        p._connectionMade()
        p.data = http_request
        p.processHandshake()
        self.assertIn(b"HTTP/1.1 400", t._written)
        self.assertIn(b"Hixie76 protocol not supported", t._written)