This commit is contained in:
kstyagi23
2026-09-05 06:07:25 +05:30
commit 07b953fed2
22 changed files with 5899 additions and 0 deletions
+31
View File
@@ -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)