Skip to content

Commit

Permalink
broker tests: Test address with no port, hostname address.
Browse files Browse the repository at this point in the history
Former as per suggestion
Yakifo#72 (comment)

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?)
  • Loading branch information
sjlongland committed Aug 17, 2021
1 parent 7058139 commit 7f86854
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
EVENT_BROKER_MESSAGE_RECEIVED,
ListenerType,
ListenerConfig,
BrokerException,
)
from amqtt.client import MQTTClient, ConnectException
from amqtt.mqtt import (
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7f86854

Please sign in to comment.