Noise: add noise option in the factories and tests

This commit is contained in:
mhchia
2020-02-19 23:15:03 +08:00
parent 1d2a976597
commit 13e8f496a7
21 changed files with 331 additions and 212 deletions

View File

@ -6,6 +6,7 @@ import pytest
import trio
from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr
from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID
from libp2p.tools.factories import HostFactory
from libp2p.tools.interop.envs import GO_BIN_PATH
from libp2p.tools.interop.process import BaseInteractiveProcess
@ -20,10 +21,10 @@ class EchoProcess(BaseInteractiveProcess):
_peer_info: PeerInfo
def __init__(
self, port: int, is_secure: bool, destination: Multiaddr = None
self, port: int, security_protocol: TProtocol, destination: Multiaddr = None
) -> None:
args = [f"-l={port}"]
if not is_secure:
if security_protocol == PLAINTEXT_PROTOCOL_ID:
args.append("-insecure")
if destination is not None:
args.append(f"-d={str(destination)}")
@ -61,9 +62,11 @@ class EchoProcess(BaseInteractiveProcess):
@pytest.mark.trio
async def test_insecure_conn_py_to_go(is_host_secure):
async with HostFactory.create_batch_and_listen(is_host_secure, 1) as hosts:
go_proc = EchoProcess(get_unused_tcp_port(), is_host_secure)
async def test_insecure_conn_py_to_go(security_protocol):
async with HostFactory.create_batch_and_listen(
1, security_protocol=security_protocol
) as hosts:
go_proc = EchoProcess(get_unused_tcp_port(), security_protocol)
await go_proc.start()
host = hosts[0]
@ -78,8 +81,10 @@ async def test_insecure_conn_py_to_go(is_host_secure):
@pytest.mark.trio
async def test_insecure_conn_go_to_py(is_host_secure):
async with HostFactory.create_batch_and_listen(is_host_secure, 1) as hosts:
async def test_insecure_conn_go_to_py(security_protocol):
async with HostFactory.create_batch_and_listen(
1, security_protocol=security_protocol
) as hosts:
host = hosts[0]
expected_data = "Hello, world!\n"
reply_data = "Replyooo!\n"
@ -94,6 +99,6 @@ async def test_insecure_conn_go_to_py(is_host_secure):
host.set_stream_handler(ECHO_PROTOCOL_ID, _handle_echo)
py_maddr = host.get_addrs()[0]
go_proc = EchoProcess(get_unused_tcp_port(), is_host_secure, py_maddr)
go_proc = EchoProcess(get_unused_tcp_port(), security_protocol, py_maddr)
await go_proc.start()
await event_handler_finished.wait()