Esempio n. 1
0
 def test_controlFrames(self):
     """
     L{WebSocketsProtocolWrapper} doesn't forward data from control frames
     to the underlying protocol.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.PING, True, mask="abcd"))
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.PONG, True, mask="abcd"))
     self.protocol.dataReceived(
         _makeFrame("", CONTROLS.CLOSE, True, mask="abcd"))
     self.assertEqual("", self.accumulatingProtocol.data)
Esempio n. 2
0
 def test_controlFrames(self):
     """
     L{WebSocketsProtocolWrapper} doesn't forward data from control frames
     to the underlying protocol.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.PING, True, mask="abcd"))
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.PONG, True, mask="abcd"))
     self.protocol.dataReceived(
         _makeFrame("", CONTROLS.CLOSE, True, mask="abcd"))
     self.assertEqual("", self.accumulatingProtocol.data)
Esempio n. 3
0
 def test_makeNonFinFrame(self):
     """
     L{_makeFrame} can build fragmented frames.
     """
     frame = "\x01\x05Hello"
     buf = _makeFrame("Hello", CONTROLS.TEXT, False)
     self.assertEqual(frame, buf)
Esempio n. 4
0
 def test_makeMaskedFrame(self):
     """
     L{_makeFrame} can build masked frames.
     """
     frame = "\x81\x857\xfa!=\x7f\x9fMQX"
     buf = _makeFrame("Hello", CONTROLS.TEXT, True, mask="7\xfa!=")
     self.assertEqual(frame, buf)
Esempio n. 5
0
 def test_makeHello(self):
     """
     L{_makeFrame} makes valid HyBi-07 packets.
     """
     frame = "\x81\x05Hello"
     buf = _makeFrame("Hello", CONTROLS.TEXT, True)
     self.assertEqual(frame, buf)
Esempio n. 6
0
 def test_makeMaskedFrame(self):
     """
     L{_makeFrame} can build masked frames.
     """
     frame = "\x81\x857\xfa!=\x7f\x9fMQX"
     buf = _makeFrame("Hello", CONTROLS.TEXT, True, mask="7\xfa!=")
     self.assertEqual(frame, buf)
Esempio n. 7
0
 def test_makeHello(self):
     """
     L{_makeFrame} makes valid HyBi-07 packets.
     """
     frame = "\x81\x05Hello"
     buf = _makeFrame("Hello", CONTROLS.TEXT, True)
     self.assertEqual(frame, buf)
Esempio n. 8
0
 def test_makeNonFinFrame(self):
     """
     L{_makeFrame} can build fragmented frames.
     """
     frame = "\x01\x05Hello"
     buf = _makeFrame("Hello", CONTROLS.TEXT, False)
     self.assertEqual(frame, buf)
Esempio n. 9
0
 def test_dataReceived(self):
     """
     L{WebSocketsProtocolWrapper.dataReceived} forwards frame content to the
     underlying protocol.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.TEXT, True, mask="abcd"))
     self.assertEqual("Hello", self.accumulatingProtocol.data)
Esempio n. 10
0
 def test_makeHugeFrame(self):
     """
     L{_makeFrame} prefixes the payload by the length on 8 bytes if the
     payload is more than 64 kB.
     """
     frame = "\x81\x7f\x00\x00\x00\x00\x00\x01\x86\xa0" + "x" * 100000
     buf = _makeFrame("x" * 100000, CONTROLS.TEXT, True)
     self.assertEqual(frame, buf)
Esempio n. 11
0
 def test_makeLargeFrame(self):
     """
     L{_makeFrame} prefixes the payload by the length on 2 bytes if the
     payload is more than 125 bytes.
     """
     frame = "\x81\x7e\x00\xc8" + "x" * 200
     buf = _makeFrame("x" * 200, CONTROLS.TEXT, True)
     self.assertEqual(frame, buf)
Esempio n. 12
0
 def test_makeLargeFrame(self):
     """
     L{_makeFrame} prefixes the payload by the length on 2 bytes if the
     payload is more than 125 bytes.
     """
     frame = "\x81\x7e\x00\xc8" + "x" * 200
     buf = _makeFrame("x" * 200, CONTROLS.TEXT, True)
     self.assertEqual(frame, buf)
Esempio n. 13
0
 def test_makeHugeFrame(self):
     """
     L{_makeFrame} prefixes the payload by the length on 8 bytes if the
     payload is more than 64 kB.
     """
     frame = "\x81\x7f\x00\x00\x00\x00\x00\x01\x86\xa0" + "x" * 100000
     buf = _makeFrame("x" * 100000, CONTROLS.TEXT, True)
     self.assertEqual(frame, buf)
Esempio n. 14
0
 def test_dataReceived(self):
     """
     L{WebSocketsProtocolWrapper.dataReceived} forwards frame content to the
     underlying protocol.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.TEXT, True, mask="abcd"))
     self.assertEqual("Hello", self.accumulatingProtocol.data)
Esempio n. 15
0
 def test_ping(self):
     """
     When a C{PING} frame is received, the frame is resent with a C{PONG},
     and the application receiver is notified about it.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.PING, True, mask="abcd"))
     self.assertEqual("\x8a\x05Hello", self.transport.value())
     self.assertEqual([(CONTROLS.PING, "Hello", True)],
                      self.receiver.received)
Esempio n. 16
0
 def test_frameReceived(self):
     """
     L{WebSocketsProtocol.dataReceived} translates bytes into frames, and
     then write it back encoded into frames.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.TEXT, True, mask="abcd"))
     self.assertEqual("\x81\x05Hello", self.transport.value())
     self.assertEqual([(CONTROLS.TEXT, "Hello", True)],
                      self.receiver.received)
Esempio n. 17
0
 def test_ping(self):
     """
     When a C{PING} frame is received, the frame is resent with a C{PONG},
     and the application receiver is notified about it.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.PING, True, mask="abcd"))
     self.assertEqual("\x8a\x05Hello", self.transport.value())
     self.assertEqual([(CONTROLS.PING, "Hello", True)],
                      self.receiver.received)
Esempio n. 18
0
 def test_frameReceived(self):
     """
     L{WebSocketsProtocol.dataReceived} translates bytes into frames, and
     then write it back encoded into frames.
     """
     self.protocol.dataReceived(
         _makeFrame("Hello", CONTROLS.TEXT, True, mask="abcd"))
     self.assertEqual("\x81\x05Hello", self.transport.value())
     self.assertEqual([(CONTROLS.TEXT, "Hello", True)],
                      self.receiver.received)
Esempio n. 19
0
    def test_close(self):
        """
        When a C{CLOSE} frame is received, the protocol closes the connection
        and logs a message.
        """
        loggedMessages = []

        def logConnectionLostMsg(eventDict):
            loggedMessages.append(log.textFromEventDict(eventDict))

        log.addObserver(logConnectionLostMsg)

        self.protocol.dataReceived(
            _makeFrame("", CONTROLS.CLOSE, True, mask="abcd"))
        self.assertFalse(self.transport.connected)
        self.assertEqual(["Closing connection: <STATUSES=NONE>"],
                         loggedMessages)
Esempio n. 20
0
    def test_close(self):
        """
        When a C{CLOSE} frame is received, the protocol closes the connection
        and logs a message.
        """
        loggedMessages = []

        def logConnectionLostMsg(eventDict):
            loggedMessages.append(log.textFromEventDict(eventDict))

        log.addObserver(logConnectionLostMsg)

        self.protocol.dataReceived(
            _makeFrame("", CONTROLS.CLOSE, True, mask="abcd"))
        self.assertFalse(self.transport.connected)
        self.assertEqual(["Closing connection: <STATUSES=NONE>"],
                         loggedMessages)