MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_inject

Function test_inject

test/mitmproxy/proxy/layers/test_tcp.py:128–151  ·  view source on GitHub ↗

inject data into an open connection.

(tctx)

Source from the content-addressed store, hash-verified

126
127
128def test_inject(tctx):
129 """inject data into an open connection."""
130 f = Placeholder(TCPFlow)
131
132 assert (
133 Playbook(tcp.TCPLayer(tctx))
134 << tcp.TcpStartHook(f)
135 >> TcpMessageInjected(f, TCPMessage(True, b"hello!"))
136 >> reply(to=-2)
137 << OpenConnection(tctx.server)
138 >> reply(None)
139 << tcp.TcpMessageHook(f)
140 >> reply()
141 << SendData(tctx.server, b"hello!")
142 # and the other way...
143 >> TcpMessageInjected(
144 f, TCPMessage(False, b"I have already done the greeting for you.")
145 )
146 << tcp.TcpMessageHook(f)
147 >> reply()
148 << SendData(tctx.client, b"I have already done the greeting for you.")
149 << None
150 )
151 assert len(f().messages) == 2

Callers

nothing calls this directly

Calls 8

TcpMessageInjectedClass · 0.90
TCPMessageClass · 0.90
OpenConnectionClass · 0.90
SendDataClass · 0.90
PlaceholderFunction · 0.85
PlaybookClass · 0.85
replyClass · 0.85
fFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…