@@ -459,3 +459,38 @@ def parse_frame(buf, cont=False):
459459 assert res , (Message (websocket .OPCODE_CLOSE , 0 , '' ), 0 )
460460 res = out ._buffer [1 ]
461461 assert res == (Message (websocket .OPCODE_TEXT , 'line1line2' , '' ), 10 )
462+
463+
464+ websocket_mask_data = bytearray (
465+ b'some very long data for masking by websocket' )
466+ websocket_mask_mask = b'1234'
467+ websocket_mask_masked = (b'B]^Q\x11 DVFH\x12 _[_U\x13 PPFR\x14 W]A\x14 \\ S@_X'
468+ b'\\ T\x14 SK\x13 CTP@[RYV@' )
469+
470+
471+ def test_websocket_mask_python ():
472+ ret = websocket ._websocket_mask_python (websocket_mask_mask ,
473+ websocket_mask_data )
474+ assert ret == websocket_mask_masked
475+
476+
477+ @pytest .mark .skipif (not hasattr (websocket , '_websocket_mask_cython' ),
478+ reason = 'Requires Cython' )
479+ def test_websocket_mask_cython ():
480+ ret = websocket ._websocket_mask_cython (websocket_mask_mask ,
481+ websocket_mask_data )
482+ assert ret == websocket_mask_masked
483+
484+
485+ def test_websocket_mask_python_empty ():
486+ ret = websocket ._websocket_mask_python (websocket_mask_mask ,
487+ bytearray ())
488+ assert ret == bytearray ()
489+
490+
491+ @pytest .mark .skipif (not hasattr (websocket , '_websocket_mask_cython' ),
492+ reason = 'Requires Cython' )
493+ def test_websocket_mask_cython_empty ():
494+ ret = websocket ._websocket_mask_cython (websocket_mask_mask ,
495+ bytearray ())
496+ assert ret == bytearray ()
0 commit comments