fix: update conn and transport for security

This commit is contained in:
Akash Mondal
2025-06-14 19:51:13 +00:00
committed by lla-dane
parent ce76641ef5
commit 45c5f16379
7 changed files with 197 additions and 93 deletions

View File

@ -36,8 +36,8 @@ class MockResourceScope:
self.memory_reserved = max(0, self.memory_reserved - size)
class TestQUICConnectionEnhanced:
"""Enhanced test suite for QUIC connection functionality."""
class TestQUICConnection:
"""Test suite for QUIC connection functionality."""
@pytest.fixture
def mock_quic_connection(self):
@ -58,10 +58,13 @@ class TestQUICConnectionEnhanced:
return MockResourceScope()
@pytest.fixture
def quic_connection(self, mock_quic_connection, mock_resource_scope):
def quic_connection(
self, mock_quic_connection: Mock, mock_resource_scope: MockResourceScope
):
"""Create test QUIC connection with enhanced features."""
private_key = create_new_key_pair().private_key
peer_id = ID.from_pubkey(private_key.get_public_key())
mock_security_manager = Mock()
return QUICConnection(
quic_connection=mock_quic_connection,
@ -72,6 +75,7 @@ class TestQUICConnectionEnhanced:
maddr=Multiaddr("/ip4/127.0.0.1/udp/4001/quic"),
transport=Mock(),
resource_scope=mock_resource_scope,
security_manager=mock_security_manager,
)
@pytest.fixture
@ -267,7 +271,9 @@ class TestQUICConnectionEnhanced:
await quic_connection.start()
@pytest.mark.trio
async def test_connection_connect_with_nursery(self, quic_connection):
async def test_connection_connect_with_nursery(
self, quic_connection: QUICConnection
):
"""Test connection establishment with nursery."""
quic_connection._started = True
quic_connection._established = True
@ -277,7 +283,9 @@ class TestQUICConnectionEnhanced:
quic_connection, "_start_background_tasks", new_callable=AsyncMock
) as mock_start_tasks:
with patch.object(
quic_connection, "verify_peer_identity", new_callable=AsyncMock
quic_connection,
"_verify_peer_identity_with_security",
new_callable=AsyncMock,
) as mock_verify:
async with trio.open_nursery() as nursery:
await quic_connection.connect(nursery)

View File

@ -66,7 +66,8 @@ Focused tests covering essential functionality required for QUIC transport.
# for addr_str in invalid_addrs:
# maddr = Multiaddr(addr_str)
# assert not is_quic_multiaddr(maddr), f"Should not detect {addr_str} as QUIC"
# assert not is_quic_multiaddr(maddr),
# f"Should not detect {addr_str} as QUIC"
# def test_malformed_multiaddrs(self):
# """Test malformed multiaddrs don't crash."""