Test mitmproxy in reverse proxy mode. - make sure that we connect to the right host - make sure that we respect keep_host_header - make sure that we include non-standard ports in the host header (#4280)
(tctx, keep_host_header)
| 141 | |
| 142 | @pytest.mark.parametrize("keep_host_header", [True, False]) |
| 143 | def test_reverse_proxy(tctx, keep_host_header): |
| 144 | """Test mitmproxy in reverse proxy mode. |
| 145 | |
| 146 | - make sure that we connect to the right host |
| 147 | - make sure that we respect keep_host_header |
| 148 | - make sure that we include non-standard ports in the host header (#4280) |
| 149 | """ |
| 150 | server = Placeholder(Server) |
| 151 | tctx.client.proxy_mode = ProxyMode.parse("reverse:http://localhost:8000") |
| 152 | tctx.options.connection_strategy = "lazy" |
| 153 | tctx.options.keep_host_header = keep_host_header |
| 154 | assert ( |
| 155 | Playbook(modes.ReverseProxy(tctx), hooks=False) |
| 156 | >> DataReceived(tctx.client, b"GET /foo HTTP/1.1\r\nHost: example.com\r\n\r\n") |
| 157 | << NextLayerHook(Placeholder(NextLayer)) |
| 158 | >> reply_next_layer(lambda ctx: http.HttpLayer(ctx, HTTPMode.transparent)) |
| 159 | << OpenConnection(server) |
| 160 | >> reply(None) |
| 161 | << SendData( |
| 162 | server, |
| 163 | b"GET /foo HTTP/1.1\r\n" |
| 164 | b"Host: " |
| 165 | + (b"example.com" if keep_host_header else b"localhost:8000") |
| 166 | + b"\r\n\r\n", |
| 167 | ) |
| 168 | >> DataReceived(server, b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n") |
| 169 | << SendData(tctx.client, b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n") |
| 170 | ) |
| 171 | assert server().address == ("localhost", 8000) |
| 172 | |
| 173 | |
| 174 | def test_reverse_dns(tctx): |
nothing calls this directly
no test coverage detected
searching dependent graphs…