From 16b6245f447b8a706f2bf4c5c91b39d56d97f93f Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 11 Aug 2019 14:09:26 -0700 Subject: [PATCH] test describe_inbound, format IPv6 better --- src/wormhole/_dilation/connector.py | 4 +++- src/wormhole/test/dilate/test_connector.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/wormhole/_dilation/connector.py b/src/wormhole/_dilation/connector.py index 2ff6ae0..320ae43 100644 --- a/src/wormhole/_dilation/connector.py +++ b/src/wormhole/_dilation/connector.py @@ -419,8 +419,10 @@ class OutboundConnectionFactory(ClientFactory, object): def describe_inbound(addr): if isinstance(addr, HostnameAddress): return "<-tcp:%s:%d" % (addr.hostname, addr.port) - elif isinstance(addr, (IPv4Address, IPv6Address)): + elif isinstance(addr, IPv4Address): return "<-tcp:%s:%d" % (addr.host, addr.port) + elif isinstance(addr, IPv6Address): + return "<-tcp:[%s]:%d" % (addr.host, addr.port) return "<-%r" % addr @attrs(repr=False) diff --git a/src/wormhole/test/dilate/test_connector.py b/src/wormhole/test/dilate/test_connector.py index accef38..9c4134e 100644 --- a/src/wormhole/test/dilate/test_connector.py +++ b/src/wormhole/test/dilate/test_connector.py @@ -5,7 +5,7 @@ from zope.interface import alsoProvides from twisted.trial import unittest from twisted.internet.task import Clock from twisted.internet.defer import Deferred -from twisted.internet.address import IPv4Address +from twisted.internet.address import IPv4Address, IPv6Address, HostnameAddress from ...eventual import EventualQueue from ..._interfaces import IDilationManager, IDilationConnector from ..._hints import DirectTCPV1Hint, RelayV1Hint, TorTCPV1Hint @@ -15,6 +15,7 @@ from ..._dilation.connection import KCM from ..._dilation.connector import (Connector, build_sided_relay_handshake, build_noise, + describe_inbound, OutboundConnectionFactory, InboundConnectionFactory, PROLOGUE_LEADER, PROLOGUE_FOLLOWER, @@ -461,3 +462,13 @@ class Race(unittest.TestCase): self.assertEqual(h.manager.mock_calls, [mock.call.connector_connection_made(p1)]) c.stop() + +class Describe(unittest.TestCase): + def test_describe_inbound(self): + self.assertEqual(describe_inbound(HostnameAddress("example.com", 1234)), + "<-tcp:example.com:1234") + self.assertEqual(describe_inbound(IPv4Address("TCP", "1.2.3.4", 1234)), + "<-tcp:1.2.3.4:1234") + self.assertEqual(describe_inbound(IPv6Address("TCP", "::1", 1234)), + "<-tcp:[::1]:1234") + self.assertEqual(describe_inbound("none-of-the-above"), "<-'none-of-the-above'")