Be able to select mqtt:tls_version for Python < 3.6 (#6442)
* Be able to select tls_version * This test should always assert this value, not only in 3.6 * Disable linting on future property (py36) * Only allow TLS 1.0, 1.1 and 1.2 * Fix line length issue * Fix check config tests * Allow auto as a TLS version
This commit is contained in:
1 parent
0aa8933df6
commit
5183cb5903
3 files changed
+75
-3
No files matched your search
@@ -4,6 +4,7 @@ from collections import namedtuple, OrderedDict
|
||||
import unittest
|
||||
from unittest import mock
|
||||
import socket
|
||||
import ssl
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -409,6 +410,52 @@ def test_setup_uses_certificate_not_on_mqtts_port(hass):
|
||||
assert mock_MQTT.mock_calls[0][1][7] != mqttsCertificateBundle
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_without_tls_config_uses_tlsv1_under_python36(hass):
|
||||
"""Test setup defaults to TLSv1 under python3.6."""
|
||||
test_broker_cfg = {mqtt.DOMAIN: {mqtt.CONF_BROKER: 'test-broker'}}
|
||||
|
||||
with mock.patch('homeassistant.components.mqtt.MQTT') as mock_MQTT:
|
||||
yield from async_setup_component(hass, mqtt.DOMAIN, test_broker_cfg)
|
||||
|
||||
assert mock_MQTT.called
|
||||
|
||||
import sys
|
||||
if sys.hexversion >= 0x03060000:
|
||||
expectedTlsVersion = ssl.PROTOCOL_TLS # pylint: disable=no-member
|
||||
else:
|
||||
expectedTlsVersion = ssl.PROTOCOL_TLSv1
|
||||
|
||||
assert mock_MQTT.mock_calls[0][1][14] == expectedTlsVersion
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_with_tls_config_uses_tls_version1_2(hass):
|
||||
"""Test setup uses specified TLS version."""
|
||||
test_broker_cfg = {mqtt.DOMAIN: {mqtt.CONF_BROKER: 'test-broker',
|
||||
'tls_version': '1.2'}}
|
||||
|
||||
with mock.patch('homeassistant.components.mqtt.MQTT') as mock_MQTT:
|
||||
yield from async_setup_component(hass, mqtt.DOMAIN, test_broker_cfg)
|
||||
|
||||
assert mock_MQTT.called
|
||||
|
||||
assert mock_MQTT.mock_calls[0][1][14] == ssl.PROTOCOL_TLSv1_2
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_with_tls_config_of_v1_under_python36_only_uses_v1(hass):
|
||||
"""Test setup uses TLSv1.0 if explicitly chosen."""
|
||||
test_broker_cfg = {mqtt.DOMAIN: {mqtt.CONF_BROKER: 'test-broker',
|
||||
'tls_version': '1.0'}}
|
||||
|
||||
with mock.patch('homeassistant.components.mqtt.MQTT') as mock_MQTT:
|
||||
yield from async_setup_component(hass, mqtt.DOMAIN, test_broker_cfg)
|
||||
|
||||
assert mock_MQTT.called
|
||||
assert mock_MQTT.mock_calls[0][1][14] == ssl.PROTOCOL_TLSv1
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_birth_message(hass):
|
||||
"""Test sending birth message."""
|
||||
|
||||
@@ -108,6 +108,7 @@ class TestCheckConfig(unittest.TestCase):
|
||||
'protocol': '3.1.1',
|
||||
'discovery': False,
|
||||
'discovery_prefix': 'homeassistant',
|
||||
'tls_version': 'auto',
|
||||
},
|
||||
'light': []},
|
||||
res['components']
|
||||
|
||||
Reference in new issue
Block a user