MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_close_normal

Function test_close_normal

test/mitmproxy/proxy/layers/test_websocket.py:350–374  ·  view source on GitHub ↗
(ws_testdata)

Source from the content-addressed store, hash-verified

348
349
350def test_close_normal(ws_testdata):
351 tctx, playbook, flow = ws_testdata
352 masked_close = Placeholder(bytes)
353 close = Placeholder(bytes)
354 assert (
355 playbook
356 << websocket.WebsocketStartHook(flow)
357 >> reply()
358 >> DataReceived(tctx.client, masked_bytes(b"\x88\x00"))
359 << SendData(tctx.server, masked_close)
360 << CloseConnection(tctx.server)
361 << SendData(tctx.client, close)
362 << CloseConnection(tctx.client)
363 << websocket.WebsocketEndHook(flow)
364 >> reply()
365 )
366 # wsproto currently handles this inconsistently, see
367 # https://github.com/python-hyper/wsproto/pull/153/files
368 assert masked_close() == masked(b"\x88\x02\x03\xe8") or masked_close() == masked(
369 b"\x88\x00"
370 )
371 assert close() == b"\x88\x02\x03\xe8" or close() == b"\x88\x00"
372
373 assert flow.websocket.close_code == 1005
374 assert not flow.live
375
376
377def test_close_disconnect(ws_testdata):

Callers

nothing calls this directly

Calls 7

PlaceholderFunction · 0.90
replyClass · 0.90
DataReceivedClass · 0.90
SendDataClass · 0.90
CloseConnectionClass · 0.90
masked_bytesFunction · 0.85
maskedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…