Closed mikenerone closed 4 years ago
On a related note, this test always passes:
def test_connect_tcp_secure(self):
async def test_coro():
async with open_mqttclient(config={"check_hostname": False}) as client:
ca = os.path.join(os.path.dirname(os.path.realpath(__file__)), "mosquitto.org.crt")
await client.connect("mqtts://test.mosquitto.org/", cafile=ca)
self.assertIsNotNone(client.session)
try:
anyio.run(test_coro)
except ConnectException:
log.error("Broken by server")
It always passes because at client.py:703
, _connect_coro()
catches the SSL failures and raises a ConnectException
instead, which the test then ignores (only logging it). In fact, it passes even thought the SSL validation actually fails currently (I suspect the CA file is outdated, but I didn't dig into it).
I'm not sure how you'd want to fix this one within the bowels of _connect_coro()
, so I won't try, but if fixed it would have caught this situation. A few of the other tests have the same problem, as well.
Any attempt to connect to a broker with an mqtts:// URI fails with a stack trace similar to:
The cause is that SSL negotiation is initiated twice in
MQTTClient._connect_coro
, once duringanyio.connect_tcp()
(L655) becauseautostart_tls=True
is in**kwargs
, and then again explicitly viaconn.start_tls()
at L659. I'll have a fix PR shortly (or perhaps tomorrow if I get too sleepy :D).