diff --git a/tests/mosquitto.org.crt b/tests/mosquitto.org.crt deleted file mode 100644 index b8535e8..0000000 --- a/tests/mosquitto.org.crt +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC8DCCAlmgAwIBAgIJAOD63PlXjJi8MA0GCSqGSIb3DQEBBQUAMIGQMQswCQYD -VQQGEwJHQjEXMBUGA1UECAwOVW5pdGVkIEtpbmdkb20xDjAMBgNVBAcMBURlcmJ5 -MRIwEAYDVQQKDAlNb3NxdWl0dG8xCzAJBgNVBAsMAkNBMRYwFAYDVQQDDA1tb3Nx -dWl0dG8ub3JnMR8wHQYJKoZIhvcNAQkBFhByb2dlckBhdGNob28ub3JnMB4XDTEy -MDYyOTIyMTE1OVoXDTIyMDYyNzIyMTE1OVowgZAxCzAJBgNVBAYTAkdCMRcwFQYD -VQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwGA1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1v -c3F1aXR0bzELMAkGA1UECwwCQ0ExFjAUBgNVBAMMDW1vc3F1aXR0by5vcmcxHzAd -BgkqhkiG9w0BCQEWEHJvZ2VyQGF0Y2hvby5vcmcwgZ8wDQYJKoZIhvcNAQEBBQAD -gY0AMIGJAoGBAMYkLmX7SqOT/jJCZoQ1NWdCrr/pq47m3xxyXcI+FLEmwbE3R9vM -rE6sRbP2S89pfrCt7iuITXPKycpUcIU0mtcT1OqxGBV2lb6RaOT2gC5pxyGaFJ+h -A+GIbdYKO3JprPxSBoRponZJvDGEZuM3N7p3S/lRoi7G5wG5mvUmaE5RAgMBAAGj -UDBOMB0GA1UdDgQWBBTad2QneVztIPQzRRGj6ZHKqJTv5jAfBgNVHSMEGDAWgBTa -d2QneVztIPQzRRGj6ZHKqJTv5jAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUA -A4GBAAqw1rK4NlRUCUBLhEFUQasjP7xfFqlVbE2cRy0Rs4o3KS0JwzQVBwG85xge -REyPOFdGdhBY2P1FNRy0MDr6xr+D2ZOwxs63dG1nnAnWZg7qwoLgpZ4fESPD3PkA -1ZgKJc2zbSQ9fCPxt2W3mdVav66c6fsb7els2W2Iz7gERJSX ------END CERTIFICATE----- diff --git a/tests/test_client.py b/tests/test_client.py index cdc3f8b..72d333f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -5,6 +5,9 @@ import unittest import asyncio import os import logging +import urllib.request +import tempfile +import shutil from hbmqtt.client import MQTTClient, ConnectException from hbmqtt.broker import Broker from hbmqtt.mqtt.constants import QOS_0, QOS_1, QOS_2 @@ -43,8 +46,15 @@ class MQTTClientTest(unittest.TestCase): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) + self.temp_dir = tempfile.mkdtemp(prefix='hbmqtt-test-') + url = "http://test.mosquitto.org/ssl/mosquitto.org.crt" + self.ca_file = os.path.join(self.temp_dir, 'mosquitto.org.crt') + urllib.request.urlretrieve(url, self.ca_file) + log.info("stored mosquitto cert at %s" % self.ca_file) + def tearDown(self): self.loop.close() + shutil.rmtree(self.temp_dir) def test_connect_tcp(self): @asyncio.coroutine @@ -68,8 +78,7 @@ class MQTTClientTest(unittest.TestCase): def test_coro(): try: client = MQTTClient(config={'check_hostname': False}) - ca = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mosquitto.org.crt') - yield from client.connect('mqtts://test.mosquitto.org/', cafile=ca) + yield from client.connect('mqtts://test.mosquitto.org/', cafile=self.ca_file) self.assertIsNotNone(client.session) yield from client.disconnect() future.set_result(True) @@ -115,7 +124,6 @@ class MQTTClientTest(unittest.TestCase): self.loop.run_until_complete(test_coro()) if future.exception(): raise future.exception() - raise future.exception() def test_reconnect_ws_retain_username_password(self): @asyncio.coroutine @@ -148,8 +156,7 @@ class MQTTClientTest(unittest.TestCase): broker = Broker(broker_config, plugin_namespace="hbmqtt.test.plugins") yield from broker.start() client = MQTTClient() - ca = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mosquitto.org.crt') - yield from client.connect('ws://127.0.0.1:8081/', cafile=ca) + yield from client.connect('ws://127.0.0.1:8081/', cafile=self.ca_file) self.assertIsNotNone(client.session) yield from client.disconnect() yield from broker.shutdown()