allow connections with username only

Section [MQTT-3.1.2-22] of the MQTT 3.1.1 only says that a password cannot be
given without a user. The reverse should be allowed. Fixes #79.
pull/113/head
Rémi Cardona 2022-03-03 19:50:59 +01:00 zatwierdzone przez Florian Ludwig
rodzic f71b99b086
commit a3f982c4d2
2 zmienionych plików z 11 dodań i 2 usunięć

Wyświetl plik

@ -163,8 +163,6 @@ class BrokerProtocolHandler(ProtocolHandler):
) # [MQTT-3.2.2-4] session_parent=0
elif not connect.username_flag and connect.password_flag:
connack = ConnackPacket.build(0, BAD_USERNAME_PASSWORD) # [MQTT-3.1.2-22]
elif connect.username_flag and not connect.password_flag:
connack = ConnackPacket.build(0, BAD_USERNAME_PASSWORD) # [MQTT-3.1.2-22]
elif connect.username_flag and connect.username is None:
error_msg = "Invalid username from %s" % (
format_client_message(address=remote_address, port=remote_port)

Wyświetl plik

@ -111,6 +111,17 @@ async def test_connect_ws_secure():
await broker.shutdown()
@pytest.mark.asyncio
async def test_connect_username_without_password():
broker = Broker(broker_config, plugin_namespace="amqtt.test.plugins")
await broker.start()
client = MQTTClient()
await client.connect("mqtt://alice@127.0.0.1/")
assert client.session is not None
await client.disconnect()
await broker.shutdown()
@pytest.mark.asyncio
async def test_ping():
broker = Broker(broker_config, plugin_namespace="amqtt.test.plugins")