Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_init_connector(test_endpoint, multiplexer_client, multiplexer_server):
"""Test and init a connector."""
assert not test_endpoint
connector = Connector("127.0.0.1", "8822")
multiplexer_client._new_connections = connector.handler
channel = await multiplexer_server.create_channel(IP_ADDR)
await asyncio.sleep(0.1)
assert test_endpoint
test_connection = test_endpoint[0]
await channel.write(b"Hallo")
data = await test_connection.reader.read(1024)
assert data == b"Hallo"
test_connection.close.set()
async def test_init_client_peer(peer_listener, peer_manager, test_endpoint):
"""Test setup of ClientPeer."""
client = ClientPeer("127.0.0.1", "8893")
connector = Connector("127.0.0.1", "8822")
assert not client.is_connected
assert not peer_manager.peer_available("localhost")
valid = datetime.utcnow() + timedelta(days=1)
aes_key = os.urandom(32)
aes_iv = os.urandom(16)
hostname = "localhost"
fernet_token = create_peer_config(valid.timestamp(), hostname, aes_key, aes_iv)
await client.start(connector, fernet_token, aes_key, aes_iv)
await asyncio.sleep(0.1)
assert peer_manager.peer_available("localhost")
assert client.is_connected
assert client._multiplexer._throttling is None
async def test_fernet_token_date(peer_listener, peer_manager, test_endpoint):
"""Test fernet token created by server as invalid."""
client = ClientPeer("127.0.0.1", "8893")
connector = Connector("127.0.0.1", "8822")
assert not peer_manager.peer_available("localhost")
valid = timedelta(days=-1)
aes_key = os.urandom(32)
aes_iv = os.urandom(16)
hostname = "localhost"
fernet_token = server.generate_client_token(
FERNET_TOKENS, valid, hostname, aes_key, aes_iv
)
with pytest.raises(SniTunConnectionError):
await client.start(connector, fernet_token, aes_key, aes_iv)
await asyncio.sleep(0.1)
assert not peer_manager.peer_available("localhost")
async def test_init_connector_whitelist(
test_endpoint, multiplexer_client, multiplexer_server
):
"""Test and init a connector with whitelist."""
assert not test_endpoint
connector = Connector("127.0.0.1", "8822", True)
multiplexer_client._new_connections = connector.handler
connector.whitelist.add(IP_ADDR)
assert IP_ADDR in connector.whitelist
channel = await multiplexer_server.create_channel(IP_ADDR)
await asyncio.sleep(0.1)
assert test_endpoint
test_connection = test_endpoint[0]
await channel.write(b"Hallo")
data = await test_connection.reader.read(1024)
assert data == b"Hallo"
test_connection.close.set()
async def start(self, whitelist: bool = False) -> None:
"""Start internal server."""
await self._site.start()
host, port = self._socket.getsockname()[:2]
self._connector = Connector(host, port, whitelist)
_LOGGER.info("AioHTTP snitun client started on %s:%s", host, port)