mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Use bundled certificates if port matches mqtts (#6429)
* Use bundled certificates if port matches mqtts * Move import requests.certs to top, since it's used in more places * Add happy and non-happy path tests for default certificate bundle on mqtts port
This commit is contained in:
committed by
Paulus Schoutsen
parent
eaaa0442e2
commit
1b23b32817
@@ -380,6 +380,40 @@ def test_setup_fails_if_no_connect_broker(hass):
|
||||
assert not result
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_uses_certificate_on_mqtts_port(hass):
|
||||
"""Test setup uses bundled certificates when mqtts port is requested."""
|
||||
test_broker_cfg = {mqtt.DOMAIN: {mqtt.CONF_BROKER: 'test-broker',
|
||||
'port': 8883}}
|
||||
|
||||
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][2] == 8883
|
||||
|
||||
import requests.certs
|
||||
expectedCertificate = requests.certs.where()
|
||||
assert mock_MQTT.mock_calls[0][1][7] == expectedCertificate
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_uses_certificate_not_on_mqtts_port(hass):
|
||||
"""Test setup doesn't use bundled certificates when not mqtts port."""
|
||||
test_broker_cfg = {mqtt.DOMAIN: {mqtt.CONF_BROKER: 'test-broker',
|
||||
'port': 1883}}
|
||||
|
||||
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][2] == 1883
|
||||
|
||||
import requests.certs
|
||||
mqttsCertificateBundle = requests.certs.where()
|
||||
assert mock_MQTT.mock_calls[0][1][7] != mqttsCertificateBundle
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_birth_message(hass):
|
||||
"""Test sending birth message."""
|
||||
|
||||
Reference in New Issue
Block a user