MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_websocket

Function test_websocket

test/mitmproxy/addons/test_dumper.py:246–281  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

244
245
246def test_websocket():
247 sio = io.StringIO()
248 d = dumper.Dumper(sio)
249 with taddons.context(d) as ctx:
250 ctx.configure(d, flow_detail=3, showhost=True)
251 f = tflow.twebsocketflow()
252 d.websocket_message(f)
253 assert "it's me" in sio.getvalue()
254 sio.truncate(0)
255
256 d.websocket_end(f)
257 assert "WebSocket connection closed by" in sio.getvalue()
258 sio.truncate(0)
259
260 f = tflow.twebsocketflow(err=True)
261 d.websocket_end(f)
262 assert "Error in WebSocket" in sio.getvalue()
263 assert "(reason:" not in sio.getvalue()
264 sio.truncate(0)
265
266 f = tflow.twebsocketflow(err=True, close_reason="Some lame excuse")
267 d.websocket_end(f)
268 assert "Error in WebSocket" in sio.getvalue()
269 assert "(reason: Some lame excuse)" in sio.getvalue()
270 sio.truncate(0)
271
272 f = tflow.twebsocketflow(close_code=4000)
273 d.websocket_end(f)
274 assert "UNKNOWN_ERROR=4000" in sio.getvalue()
275 assert "(reason:" not in sio.getvalue()
276 sio.truncate(0)
277
278 f = tflow.twebsocketflow(close_code=4000, close_reason="I swear I had a reason")
279 d.websocket_end(f)
280 assert "UNKNOWN_ERROR=4000" in sio.getvalue()
281 assert "(reason: I swear I had a reason)" in sio.getvalue()
282
283
284def test_http_connect_error():

Callers

nothing calls this directly

Calls 5

websocket_messageMethod · 0.95
websocket_endMethod · 0.95
contextMethod · 0.80
getvalueMethod · 0.80
configureMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…