MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / test_upstream_https

Function test_upstream_https

test/mitmproxy/proxy/layers/test_modes.py:46–139  ·  view source on GitHub ↗

Test mitmproxy in HTTPS upstream mode with another mitmproxy instance upstream. In other words: mitmdump --mode upstream:https://localhost:8081 --ssl-insecure mitmdump -p 8081 curl -x localhost:8080 -k http://example.com

(tctx)

Source from the content-addressed store, hash-verified

44
45
46def test_upstream_https(tctx):
47 """
48 Test mitmproxy in HTTPS upstream mode with another mitmproxy instance upstream.
49 In other words:
50
51 mitmdump --mode upstream:https://localhost:8081 --ssl-insecure
52 mitmdump -p 8081
53 curl -x localhost:8080 -k http://example.com
54 """
55 tctx1 = Context(
56 Client(
57 peername=("client", 1234),
58 sockname=("127.0.0.1", 8080),
59 timestamp_start=1605699329,
60 state=ConnectionState.OPEN,
61 ),
62 copy.deepcopy(tctx.options),
63 )
64 tctx1.client.proxy_mode = ProxyMode.parse(
65 "upstream:https://example.mitmproxy.org:8081"
66 )
67 tctx2 = Context(
68 Client(
69 peername=("client", 4321),
70 sockname=("127.0.0.1", 8080),
71 timestamp_start=1605699329,
72 state=ConnectionState.OPEN,
73 ),
74 copy.deepcopy(tctx.options),
75 )
76 assert tctx2.client.proxy_mode == ProxyMode.parse("regular")
77 del tctx
78
79 proxy1 = Playbook(modes.HttpUpstreamProxy(tctx1), hooks=False)
80 proxy2 = Playbook(modes.HttpProxy(tctx2), hooks=False)
81
82 upstream = Placeholder(Server)
83 server = Placeholder(Server)
84 clienthello = Placeholder(bytes)
85 serverhello = Placeholder(bytes)
86 request = Placeholder(bytes)
87 tls_finished = Placeholder(bytes)
88 response = Placeholder(bytes)
89
90 assert (
91 proxy1
92 >> DataReceived(
93 tctx1.client,
94 b"GET http://example.com/ HTTP/1.1\r\nHost: example.com\r\n\r\n",
95 )
96 << NextLayerHook(Placeholder(NextLayer))
97 >> reply_next_layer(lambda ctx: http.HttpLayer(ctx, HTTPMode.upstream))
98 << OpenConnection(upstream)
99 >> reply(None)
100 << TlsStartServerHook(Placeholder())
101 >> reply_tls_start_server(alpn=b"http/1.1")
102 << SendData(upstream, clienthello)
103 )

Callers

nothing calls this directly

Calls 15

ContextClass · 0.90
ClientClass · 0.90
PlaybookClass · 0.90
PlaceholderFunction · 0.90
DataReceivedClass · 0.90
NextLayerHookClass · 0.90
reply_next_layerFunction · 0.90
OpenConnectionClass · 0.90
replyClass · 0.90
TlsStartServerHookClass · 0.90
reply_tls_start_serverFunction · 0.90
SendDataClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…