kopia lustrzana https://github.com/Yakifo/amqtt
Fix #32
rodzic
ea62725868
commit
e9b806348e
|
@ -337,7 +337,7 @@ class Broker:
|
|||
except HBMQTTException as exc:
|
||||
self.logger.warn("[MQTT-3.1.0-1] %s: Can't read first packet an CONNECT: %s" %
|
||||
(format_client_message(address=remote_address, port=remote_port), exc))
|
||||
yield from writer.close()
|
||||
#yield from writer.close()
|
||||
self.logger.debug("Connection closed")
|
||||
return
|
||||
except MQTTException as me:
|
||||
|
|
|
@ -149,7 +149,6 @@ class MQTTClient:
|
|||
else:
|
||||
return (yield from self.reconnect())
|
||||
|
||||
@mqtt_connected
|
||||
@asyncio.coroutine
|
||||
def disconnect(self):
|
||||
"""
|
||||
|
|
|
@ -153,7 +153,7 @@ class BrokerProtocolHandler(ProtocolHandler):
|
|||
elif connect.password_flag and connect.password is None:
|
||||
error_msg = 'Invalid password %s' % (format_client_message(address=remote_address, port=remote_port))
|
||||
connack = ConnackPacket.build(0, BAD_USERNAME_PASSWORD) # [MQTT-3.2.2-4] session_parent=0
|
||||
elif connect.clean_session_flag is False and connect.payload.client_id is None:
|
||||
elif connect.clean_session_flag is False and (connect.payload.client_id is None or connect.payload.client_id == ""):
|
||||
error_msg = '[MQTT-3.1.3-8] [MQTT-3.1.3-9] %s: No client Id provided (cleansession=0)' % \
|
||||
format_client_message(address=remote_address, port=remote_port)
|
||||
connack = ConnackPacket.build(0, IDENTIFIER_REJECTED)
|
||||
|
|
|
@ -5,7 +5,7 @@ import unittest
|
|||
from unittest.mock import patch, call, MagicMock
|
||||
from hbmqtt.broker import *
|
||||
from hbmqtt.mqtt.constants import *
|
||||
from hbmqtt.client import MQTTClient
|
||||
from hbmqtt.client import MQTTClient, ConnectException
|
||||
|
||||
formatter = "[%(asctime)s] %(name)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
|
||||
logging.basicConfig(level=logging.DEBUG, format=formatter)
|
||||
|
@ -99,6 +99,34 @@ class BrokerTest(unittest.TestCase):
|
|||
if future.exception():
|
||||
raise future.exception()
|
||||
|
||||
@patch('hbmqtt.broker.PluginManager')
|
||||
def test_client_connect_clean_session_false(self, MockPluginManager):
|
||||
@asyncio.coroutine
|
||||
def test_coro():
|
||||
try:
|
||||
broker = Broker(test_config, plugin_namespace="hbmqtt.test.plugins")
|
||||
yield from broker.start()
|
||||
self.assertTrue(broker.transitions.is_started())
|
||||
client = MQTTClient(client_id="", config={'auto_reconnect': False})
|
||||
return_code=None
|
||||
try:
|
||||
yield from client.connect('mqtt://localhost/', cleansession=False)
|
||||
except ConnectException as ce:
|
||||
return_code = ce.return_code
|
||||
self.assertEqual(return_code, 0x02)
|
||||
self.assertNotIn(client.session.client_id, broker._sessions)
|
||||
yield from client.disconnect()
|
||||
yield from asyncio.sleep(0.1)
|
||||
yield from broker.shutdown()
|
||||
future.set_result(True)
|
||||
except Exception as ae:
|
||||
future.set_exception(ae)
|
||||
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
if future.exception():
|
||||
raise future.exception()
|
||||
|
||||
@patch('hbmqtt.broker.PluginManager')
|
||||
def test_client_subscribe(self, MockPluginManager):
|
||||
@asyncio.coroutine
|
||||
|
|
Ładowanie…
Reference in New Issue