__init__
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.pinned_transport import PinnedAddressBook, PinnedNetworkBackend
|
||||
|
||||
|
||||
def test_pinned_backend_dials_the_validated_address_not_hostname(monkeypatch) -> None:
|
||||
address_book = PinnedAddressBook()
|
||||
address_book.pin("example.com", 443, ["93.184.216.34"])
|
||||
backend = PinnedNetworkBackend(address_book)
|
||||
called: dict[str, object] = {}
|
||||
|
||||
class StubBackend:
|
||||
def connect_tcp(self, host, port, **kwargs):
|
||||
called["host"] = host
|
||||
called["port"] = port
|
||||
return object()
|
||||
|
||||
monkeypatch.setattr(backend, "_backend", StubBackend())
|
||||
|
||||
backend.connect_tcp("example.com", 443)
|
||||
|
||||
assert called == {"host": "93.184.216.34", "port": 443}
|
||||
|
||||
|
||||
def test_pinned_backend_rejects_unvalidated_host() -> None:
|
||||
backend = PinnedNetworkBackend(PinnedAddressBook())
|
||||
|
||||
with pytest.raises(Exception, match="No validated address"):
|
||||
backend.connect_tcp("example.com", 443)
|
||||
Reference in New Issue
Block a user