Skip to content

Commit 9506041

Browse files
acul71cursoragent
andcommitted
fix: resolve lint/test blockers and format TLS regression tests
Build RTCIceServer objects in WebRTC helpers to satisfy mypy, use a valid generated certhash in the webrtc-direct multiaddr test, and apply ruff parenthesized with-statement formatting in TLS regression tests. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ffbb00c commit 9506041

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

libp2p/transport/webrtc/_aiortc_helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from aiortc import (
2121
RTCConfiguration,
22+
RTCIceServer,
2223
RTCPeerConnection,
2324
)
2425
from aiortc.rtcdtlstransport import RTCCertificate
@@ -69,7 +70,10 @@ async def create_peer_connection(
6970
:param ice_servers: Optional STUN/TURN server URLs.
7071
:returns: A new peer connection.
7172
"""
72-
config = RTCConfiguration(iceServers=list(ice_servers) if ice_servers else [])
73+
ice_server_list = (
74+
[RTCIceServer(urls=[url]) for url in ice_servers] if ice_servers else []
75+
)
76+
config = RTCConfiguration(iceServers=ice_server_list)
7377
pc = RTCPeerConnection(configuration=config)
7478
# Replace aiortc's auto-generated cert. Must use the mangled name —
7579
# aiortc reads only `self.__certificates`, which mangles to this.

tests/core/security/tls/test_tls.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ async def test_secure_inbound_rejects_missing_client_certificate() -> None:
3636
mock_conn = MagicMock()
3737
mock_rw = _mock_tls_reader_writer_no_cert()
3838

39-
with patch(
40-
"libp2p.security.tls.transport.TLSReadWriter", return_value=mock_rw
41-
), pytest.raises(TLSHandshakeFailure, match="no client certificate"):
39+
with (
40+
patch("libp2p.security.tls.transport.TLSReadWriter", return_value=mock_rw),
41+
pytest.raises(TLSHandshakeFailure, match="no client certificate"),
42+
):
4243
await transport.secure_inbound(mock_conn)
4344

4445

@@ -49,9 +50,7 @@ async def test_upgrader_rejects_missing_client_certificate(nursery) -> None:
4950
upgrader = TransportUpgrader(sec_opt, default_mplex_muxer_transport_factory())
5051
mock_rw = _mock_tls_reader_writer_no_cert()
5152

52-
with patch(
53-
"libp2p.security.tls.transport.TLSReadWriter", return_value=mock_rw
54-
):
53+
with patch("libp2p.security.tls.transport.TLSReadWriter", return_value=mock_rw):
5554
async with raw_conn_factory(nursery) as (_local_conn, remote_conn):
5655
with pytest.raises(SecurityUpgradeFailure):
5756
await upgrader.upgrade_security(remote_conn, False)

tests/core/transport/webrtc/test_multiaddr_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def test_valid_ipv4_webrtc_direct(self):
2323
assert is_webrtc_direct_multiaddr(maddr)
2424

2525
def test_valid_ipv4_with_certhash(self):
26+
cert = WebRTCCertificate.generate()
27+
certhash = cert.fingerprint_to_multibase()
2628
maddr = Multiaddr(
27-
"/ip4/192.168.1.1/udp/4001/webrtc-direct/certhash/uEiBkEKoo3S"
29+
f"/ip4/192.168.1.1/udp/4001/webrtc-direct/certhash/{certhash}"
2830
)
2931
assert is_webrtc_direct_multiaddr(maddr)
3032

0 commit comments

Comments
 (0)