Skip to content

Commit c4491d2

Browse files
committed
Add regression test for TCP kill behavior
1 parent d9d5878 commit c4491d2

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

test/mitmproxy/proxy/layers/test_tcp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,31 @@ def test_inject(tctx):
149149
<< None
150150
)
151151
assert len(f().messages) == 2
152+
153+
154+
155+
def test_kill_closes_connection_when_flow_not_live(tctx):
156+
"""If a TCP flow is marked not live, the layer should close rather than relay data."""
157+
158+
def mark_flow_dead(flow: TCPFlow) -> None:
159+
flow.live = False
160+
161+
f = Placeholder(TCPFlow)
162+
163+
assert (
164+
Playbook(tcp.TCPLayer(tctx))
165+
<< tcp.TcpStartHook(f)
166+
>> reply()
167+
<< OpenConnection(tctx.server)
168+
>> reply(None)
169+
>> DataReceived(tctx.client, b"terminate")
170+
<< tcp.TcpMessageHook(f)
171+
>> reply(side_effect=mark_flow_dead)
172+
<< CloseConnection(tctx.server, half_close=True)
173+
<< None
174+
)
175+
176+
flow = f()
177+
assert flow is not None
178+
assert flow.live is False
179+
assert flow.messages[-1].content == b"terminate"

0 commit comments

Comments
 (0)