mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Resolving bug that prevents ssl_verify option for Unifi device_tracker (#9788)
* Added TODO to illustrate my intentions * Resolved linting issue * Resolved bool or file validation and updated tests The tests have been updated to include mocks to assert a temp ca cert exists as it should for the positive tests with an additional negative test for a file not existing being tested. * Resolved flake8 linting issues (test docstrings)
This commit is contained in:
parent
8f06b35dfc
commit
0de2266a72
@ -32,7 +32,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
|
||||
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): vol.Any(
|
||||
cv.boolean, cv.isfile)
|
||||
})
|
||||
|
||||
|
||||
|
@ -25,6 +25,32 @@ def mock_scanner():
|
||||
yield scanner
|
||||
|
||||
|
||||
@mock.patch('os.access', return_value=True)
|
||||
@mock.patch('os.path.isfile', mock.Mock(return_value=True))
|
||||
def test_config_valid_verify_ssl(hass, mock_scanner, mock_ctrl):
|
||||
"""Test the setup with a string for ssl_verify.
|
||||
|
||||
Representing the absolute path to a CA certificate bundle.
|
||||
"""
|
||||
config = {
|
||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_VERIFY_SSL: "/tmp/unifi.crt"
|
||||
})
|
||||
}
|
||||
result = unifi.get_scanner(hass, config)
|
||||
assert mock_scanner.return_value == result
|
||||
assert mock_ctrl.call_count == 1
|
||||
assert mock_ctrl.mock_calls[0] == \
|
||||
mock.call('localhost', 'foo', 'password', 8443,
|
||||
version='v4', site_id='default', ssl_verify="/tmp/unifi.crt")
|
||||
|
||||
assert mock_scanner.call_count == 1
|
||||
assert mock_scanner.call_args == mock.call(mock_ctrl.return_value)
|
||||
|
||||
|
||||
def test_config_minimal(hass, mock_scanner, mock_ctrl):
|
||||
"""Test the setup with minimal configuration."""
|
||||
config = {
|
||||
@ -86,6 +112,13 @@ def test_config_error():
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 'foo', # bad port!
|
||||
})
|
||||
with pytest.raises(vol.Invalid):
|
||||
unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_VERIFY_SSL: "dfdsfsdfsd", # Invalid ssl_verify (no file)
|
||||
})
|
||||
|
||||
|
||||
def test_config_controller_failed(hass, mock_ctrl, mock_scanner):
|
||||
|
Loading…
x
Reference in New Issue
Block a user