(caplog_async, monkeypatch)
| 276 | |
| 277 | |
| 278 | async def test_dns(caplog_async, monkeypatch) -> None: |
| 279 | monkeypatch.setattr( |
| 280 | mitmproxy_rs.dns.DnsResolver, "lookup_ipv4", lambda _, __: lookup_ipv4() |
| 281 | ) |
| 282 | |
| 283 | caplog_async.set_level("INFO") |
| 284 | ps = Proxyserver() |
| 285 | with taddons.context(ps, dns_resolver.DnsResolver()) as tctx: |
| 286 | tctx.configure( |
| 287 | ps, |
| 288 | mode=["dns@127.0.0.1:0"], |
| 289 | ) |
| 290 | assert await ps.setup_servers() |
| 291 | ps.running() |
| 292 | await caplog_async.await_log("DNS server listening at") |
| 293 | assert ps.servers |
| 294 | dns_addr = ps.servers["dns@127.0.0.1:0"].listen_addrs[0] |
| 295 | s = await mitmproxy_rs.udp.open_udp_connection(*dns_addr) |
| 296 | req = tdnsreq() |
| 297 | s.write(req.packed) |
| 298 | resp = dns.DNSMessage.unpack(await s.read(65535)) |
| 299 | assert req.id == resp.id and "8.8.8.8" in str(resp) |
| 300 | assert len(ps.connections) == 1 |
| 301 | s.write(req.packed) |
| 302 | resp = dns.DNSMessage.unpack(await s.read(65535)) |
| 303 | assert req.id == resp.id and "8.8.8.8" in str(resp) |
| 304 | assert len(ps.connections) == 1 |
| 305 | req.id = req.id + 1 |
| 306 | s.write(req.packed) |
| 307 | resp = dns.DNSMessage.unpack(await s.read(65535)) |
| 308 | assert req.id == resp.id and "8.8.8.8" in str(resp) |
| 309 | assert len(ps.connections) == 1 |
| 310 | (dns_conn,) = ps.connections.values() |
| 311 | assert isinstance(dns_conn.layer, layers.DNSLayer) |
| 312 | assert len(dns_conn.layer.flows) == 2 |
| 313 | |
| 314 | s.write(b"\x00") |
| 315 | await caplog_async.await_log("sent an invalid message") |
| 316 | tctx.configure(ps, server=False) |
| 317 | await caplog_async.await_log("stopped") |
| 318 | |
| 319 | s.close() |
| 320 | await s.wait_closed() |
| 321 | await _wait_for_connection_closes(ps) |
| 322 | |
| 323 | |
| 324 | def test_validation_no_transparent(monkeypatch): |
nothing calls this directly
no test coverage detected
searching dependent graphs…