From 7f86854fefe6f7d41801d1b2e7ee2beddc7ff6f7 Mon Sep 17 00:00:00 2001 From: Stuart Longland Date: Wed, 18 Aug 2021 08:18:37 +1000 Subject: [PATCH] broker tests: Test address with no port, hostname address. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former as per suggestion https://github.com/Yakifo/amqtt/pull/72#discussion_r690398056 Latter because I'm not sure how the `asyncio.create_server` and similar libraries react to being given a host name. (Maybe it does a reverse DNS look-up, maybe not… do users really want to trust that reverse DNS gets the right IP?) --- tests/test_broker.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_broker.py b/tests/test_broker.py index 00f0f919..ef66114c 100644 --- a/tests/test_broker.py +++ b/tests/test_broker.py @@ -20,6 +20,7 @@ EVENT_BROKER_MESSAGE_RECEIVED, ListenerType, ListenerConfig, + BrokerException, ) from amqtt.client import MQTTClient, ConnectException from amqtt.mqtt import ( @@ -103,6 +104,28 @@ def test_lc_decode_v6_addr(): assert lc.port == 1883 +def test_lc_decode_no_port(): + """ + Test an address without a port raises an error + """ + try: + ListenerConfig(ListenerType.TCP, bind="[::]") + assert False, "Should not have been accepted" + except BrokerException as e: + assert str(e) == "Invalid address given in bind value: '[::]'" + + +def test_lc_decode_hostname(): + """ + Test a hostname (not IP) raises an error + """ + try: + ListenerConfig(ListenerType.TCP, bind="localhost:1883") + assert False, "Should not have been accepted" + except BrokerException as e: + assert str(e) == "Invalid address given in bind value: 'localhost:1883'" + + @pytest.mark.asyncio async def test_start_stop(broker, mock_plugin_manager): mock_plugin_manager.assert_has_calls(