File tree Expand file tree Collapse file tree
test/mitmproxy/proxy/layers Expand file tree Collapse file tree Original file line number Diff line number Diff 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"
You can’t perform that action at this time.
0 commit comments