def test_close_disconnect(ws_testdata): tctx, playbook, flow = ws_testdata assert (playbook << websocket.WebsocketStartHook(flow) >> reply() >> ConnectionClosed(tctx.server) << CloseConnection(tctx.server) << SendData(tctx.client, b"\x88\x02\x03\xe8") << CloseConnection( tctx.client) << websocket.WebsocketErrorHook(flow) >> reply() >> ConnectionClosed(tctx.client)) assert "ABNORMAL_CLOSURE" in flow.error.msg
def test_close_error(ws_testdata): tctx, playbook, flow = ws_testdata assert (playbook << websocket.WebsocketStartHook(flow) >> reply() >> DataReceived(tctx.server, b"\x88\x02\x0f\xa0") << SendData( tctx.server, masked(b"\x88\x02\x0f\xa0")) << CloseConnection( tctx.server) << SendData(tctx.client, b"\x88\x02\x0f\xa0") << CloseConnection( tctx.client) << websocket.WebsocketErrorHook(flow) >> reply()) assert "UNKNOWN_ERROR=4000" in flow.error.msg
def test_protocol_error(ws_testdata): tctx, playbook, flow = ws_testdata assert ( playbook << websocket.WebsocketStartHook(flow) >> reply() >> DataReceived(tctx.server, b"\x01\x03foo") >> DataReceived(tctx.server, b"\x02\x03bar") << SendData( tctx.server, masked( b"\x88/\x03\xeaexpected CONTINUATION, got <Opcode.BINARY: 2>")) << CloseConnection(tctx.server) << SendData( tctx.client, b"\x88/\x03\xeaexpected CONTINUATION, got <Opcode.BINARY: 2>") << CloseConnection( tctx.client) << websocket.WebsocketErrorHook(flow) >> reply()) assert not flow.websocket.messages