Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download mosquitto certificate on the fly #232

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[bdist_wheel]
python-tag = py34.py35
python-tag = py36.py37
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setup(
name="hbmqtt",
version=get_version(),
description="MQTT client/broker using Python 3.4 asyncio library",
description="MQTT client/broker using Python asyncio",
author="Nicolas Jouanin",
author_email='[email protected]',
url="https://github.com/beerfactory/hbmqtt",
Expand All @@ -30,9 +30,8 @@
'Operating System :: POSIX',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Communications',
'Topic :: Internet'
],
Expand Down
18 changes: 0 additions & 18 deletions tests/mosquitto.org.crt

This file was deleted.

17 changes: 12 additions & 5 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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
Expand Down Expand Up @@ -43,8 +46,15 @@ def setUp(self):
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
Expand All @@ -68,8 +78,7 @@ def test_connect_tcp_secure(self):
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)
Expand Down Expand Up @@ -115,7 +124,6 @@ def test_coro():
self.loop.run_until_complete(test_coro())
if future.exception():
raise future.exception()
raise future.exception()
HerrMuellerluedenscheid marked this conversation as resolved.
Show resolved Hide resolved

def test_reconnect_ws_retain_username_password(self):
@asyncio.coroutine
Expand Down Expand Up @@ -148,8 +156,7 @@ def test_coro():
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()
Expand Down
2 changes: 0 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ ignore =

[tox]
envlist =
py34,
py35,
py36,
py37,
coverage,
Expand Down