예제 #1
0
 def test_parseUnknownOpcode(self):
     """
     L{_parseFrames} raises a L{_WSException} error when the error uses an
     unknown opcode.
     """
     frame = [b"\x8f\x05"]
     error = self.assertRaises(_WSException, list, _parseFrames(frame))
     self.assertEqual("Unknown opcode 15 in frame", str(error))
예제 #2
0
 def test_parsePartialNoLength(self):
     """
     Partial frames are stored for later decoding.
     """
     frame = [b"\x81"]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 0)
     self.assertEqual(frame, [b"\x81"])
예제 #3
0
 def test_parseReservedFlag(self):
     """
     L{_parseFrames} raises a L{_WSException} error when the header uses a
     reserved flag.
     """
     frame = [b"\x72\x05"]
     error = self.assertRaises(_WSException, list, _parseFrames(frame))
     self.assertEqual("Reserved flag in frame (114)", str(error))
예제 #4
0
 def test_parsePartialTruncatedData(self):
     """
     Partial frames with full headers and partial data are stored for later
     decoding.
     """
     frame = [b"\x81\x05Hel"]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 0)
     self.assertEqual(frame, [b"\x81\x05Hel"])
예제 #5
0
 def test_parsePartialTruncatedLengthDouble(self):
     """
     Partial frames are stored for later decoding, even if they are marked
     as being extra-long.
     """
     frame = [b"\x81\xff"]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 0)
     self.assertEqual(frame, [b"\x81\xff"])
예제 #6
0
 def test_parsePartialTruncatedLengthInt(self):
     """
     Partial frames are stored for later decoding, even if they are cut on
     length boundaries.
     """
     frame = [b"\x81\xfe"]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 0)
     self.assertEqual(frame, [b"\x81\xfe"])
예제 #7
0
 def test_parseMaskedPartialText(self):
     """
     L{_parseFrames} stops parsing if a masked frame isn't long enough to
     contain the length of the text.
     """
     frame = [b"\x81\x827\xfa"]
     frames = list(_parseFrames(frame))
     self.assertEqual(len(frames), 0)
     self.assertEqual(frame, [b"\x81\x827\xfa"])
예제 #8
0
 def test_parseMaskedText(self):
     """
     A sample masked frame of "Hello" from HyBi-10, 4.7.
     """
     frame = [b"\x81\x857\xfa!=\x7f\x9fMQX"]
     frames = list(_parseFrames(frame))
     self.assertEqual(len(frames), 1)
     self.assertEqual(frames[0], (CONTROLS.TEXT, b"Hello", True))
     self.assertEqual(frame, [])
예제 #9
0
 def test_parseUnmaskedHugeText(self):
     """
     L{_parseFrames} handles frame with text longer than 64 kB.
     """
     frame = [b"\x81\x7f\x00\x00\x00\x00\x00\x01\x86\xa0", b"x" * 100000]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 1)
     self.assertEqual(frames[0], (CONTROLS.TEXT, b"x" * 100000, True))
     self.assertEqual(frame, [])
예제 #10
0
 def test_parseUnmaskedTextWithMaskNeeded(self):
     """
     L{_parseFrames} raises L{_WSException} if the frame is not masked and
     C{needMask} is set to C{True}.
     """
     frame = [b"\x81\x05Hello"]
     error = self.assertRaises(_WSException, list,
                               _parseFrames(frame, needMask=True))
     self.assertEqual("Received data not masked", str(error))
예제 #11
0
 def test_parseUnmaskedLargeText(self):
     """
     L{_parseFrames} handles frame with text longer than 125 bytes.
     """
     frame = [b"\x81\x7e\x00\xc8", b"x" * 200]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 1)
     self.assertEqual(frames[0], (CONTROLS.TEXT, b"x" * 200, True))
     self.assertEqual(frame, [])
예제 #12
0
 def test_parseUnmaskedText(self):
     """
     A sample unmasked frame of "Hello" from HyBi-10, 4.7.
     """
     frame = [b"\x81\x05Hello"]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 1)
     self.assertEqual(frames[0], (CONTROLS.TEXT, b"Hello", True))
     self.assertEqual(frame, [])
예제 #13
0
    def test_parsePong(self):
        """
        Pong packets are decoded.

        From HyBi-10, 4.7.
        """
        frame = [b"\x8a\x05Hello"]
        frames = list(_parseFrames(frame, needMask=False))
        self.assertEqual(len(frames), 1)
        self.assertEqual(frames[0], (CONTROLS.PONG, b"Hello", True))
        self.assertEqual(frame, [])
예제 #14
0
 def test_parseCloseReason(self):
     """
     A HyBi-07 close packet must have its first two bytes be a numeric
     error code, and may optionally include trailing text explaining why
     the connection was closed.
     """
     frame = [b"\x88\x0b\x03\xe8No reason"]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 1)
     self.assertEqual(frames[0], (CONTROLS.CLOSE,
                                  (STATUSES.NORMAL, b"No reason"), True))
     self.assertEqual(frame, [])
예제 #15
0
 def test_parseCloseEmpty(self):
     """
     A HyBi-07 close packet may have no body. In that case, it decodes with
     the generic error code 1000, and has no particular justification or
     error message.
     """
     frame = [b"\x88\x00"]
     frames = list(_parseFrames(frame, needMask=False))
     self.assertEqual(len(frames), 1)
     self.assertEqual(frames[0],
                      (CONTROLS.CLOSE, (STATUSES.NONE, b""), True))
     self.assertEqual(frame, [])
예제 #16
0
    def test_parseUnmaskedTextFragments(self):
        """
        Fragmented masked packets are handled.

        From HyBi-10, 4.7.
        """
        frame = [b"\x01\x03Hel\x80\x02lo"]
        frames = list(_parseFrames(frame, needMask=False))
        self.assertEqual(len(frames), 2)
        self.assertEqual(frames[0], (CONTROLS.TEXT, b"Hel", False))
        self.assertEqual(frames[1], (CONTROLS.CONTINUE, b"lo", True))
        self.assertEqual(frame, [])