mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
fix dumper test cov
This commit is contained in:
parent
eef6522a5e
commit
793f5c5681
@ -30,7 +30,7 @@ def ttcpflow(client_conn=True, server_conn=True, messages=True, err=None):
|
||||
return f
|
||||
|
||||
|
||||
def twebsocketflow(messages=True, err=None) -> http.HTTPFlow:
|
||||
def twebsocketflow(messages=True, err=None, close_code=None, close_reason='') -> http.HTTPFlow:
|
||||
flow = http.HTTPFlow(tclient_conn(), tserver_conn())
|
||||
flow.request = http.Request(
|
||||
"example.com",
|
||||
@ -74,12 +74,18 @@ def twebsocketflow(messages=True, err=None) -> http.HTTPFlow:
|
||||
websocket.WebSocketMessage(Opcode.TEXT, True, b"hello text", 946681204),
|
||||
websocket.WebSocketMessage(Opcode.TEXT, False, b"it's me", 946681205),
|
||||
]
|
||||
if err is True:
|
||||
# ABNORMAL_CLOSURE
|
||||
flow.websocket.close_code = 1006
|
||||
|
||||
flow.websocket.close_reason = close_reason
|
||||
|
||||
if close_code is not None:
|
||||
flow.websocket.close_code = close_code
|
||||
else:
|
||||
# NORMAL_CLOSURE
|
||||
flow.websocket.close_code = 1000
|
||||
if err is True:
|
||||
# ABNORMAL_CLOSURE
|
||||
flow.websocket.close_code = 1006
|
||||
else:
|
||||
# NORMAL_CLOSURE
|
||||
flow.websocket.close_code = 1000
|
||||
|
||||
flow.reply = controller.DummyReply()
|
||||
return flow
|
||||
|
@ -232,10 +232,30 @@ def test_websocket():
|
||||
|
||||
d.websocket_end(f)
|
||||
assert "WebSocket connection closed by" in sio.getvalue()
|
||||
sio_err.truncate(0)
|
||||
|
||||
f = tflow.twebsocketflow(err=True)
|
||||
d.websocket_end(f)
|
||||
assert "Error in WebSocket" in sio_err.getvalue()
|
||||
assert "(reason:" not in sio_err.getvalue()
|
||||
sio_err.truncate(0)
|
||||
|
||||
f = tflow.twebsocketflow(err=True, close_reason='Some lame excuse')
|
||||
d.websocket_end(f)
|
||||
assert "Error in WebSocket" in sio_err.getvalue()
|
||||
assert "(reason: Some lame excuse)" in sio_err.getvalue()
|
||||
sio_err.truncate(0)
|
||||
|
||||
f = tflow.twebsocketflow(close_code=4000)
|
||||
d.websocket_end(f)
|
||||
assert "UNKNOWN_ERROR=4000" in sio_err.getvalue()
|
||||
assert "(reason:" not in sio_err.getvalue()
|
||||
sio_err.truncate(0)
|
||||
|
||||
f = tflow.twebsocketflow(close_code=4000, close_reason='I swear I had a reason')
|
||||
d.websocket_end(f)
|
||||
assert "UNKNOWN_ERROR=4000" in sio_err.getvalue()
|
||||
assert "(reason: I swear I had a reason)" in sio_err.getvalue()
|
||||
|
||||
|
||||
def test_http2():
|
||||
|
Loading…
Reference in New Issue
Block a user