| 404 | assert nl._next_layer(m.context, http_get, b"").flow is not None |
| 405 | |
| 406 | def test_next_layer(self, monkeypatch, caplog): |
| 407 | caplog.set_level(logging.DEBUG) |
| 408 | nl = NextLayer() |
| 409 | |
| 410 | with taddons.context(nl) as tctx: |
| 411 | m = MagicMock() |
| 412 | m.context = Context( |
| 413 | Client(peername=("192.168.0.42", 51234), sockname=("0.0.0.0", 8080)), |
| 414 | tctx.options, |
| 415 | ) |
| 416 | m.context.layers = [modes.TransparentProxy(m.context)] |
| 417 | m.context.server.address = ("example.com", 42) |
| 418 | tctx.configure(nl, ignore_hosts=["example.com"]) |
| 419 | |
| 420 | m.layer = preexisting = object() |
| 421 | nl.next_layer(m) |
| 422 | assert m.layer is preexisting |
| 423 | |
| 424 | m.layer = None |
| 425 | monkeypatch.setattr(m, "data_client", lambda: http_get) |
| 426 | nl.next_layer(m) |
| 427 | assert m.layer |
| 428 | |
| 429 | m.layer = None |
| 430 | monkeypatch.setattr( |
| 431 | m, "data_client", lambda: client_hello_with_extensions[:-5] |
| 432 | ) |
| 433 | nl.next_layer(m) |
| 434 | assert not m.layer |
| 435 | assert "Deferring layer decision" in caplog.text |
| 436 | |
| 437 | |
| 438 | @dataclass |