Add ssl_verify option to imap integration (#93811)
* Add ssl_verify option to imap integration * Add test
This commit is contained in:
parent
46d8885023
commit
1e0770ff8a
5 changed files with 89 additions and 12 deletions
|
@ -533,12 +533,14 @@ async def test_import_flow_connection_error(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize("cipher_list", ["python_default", "modern", "intermediate"])
|
||||
async def test_config_flow_with_cipherlist(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock, cipher_list: str
|
||||
@pytest.mark.parametrize("verify_ssl", [False, True])
|
||||
async def test_config_flow_with_cipherlist_and_ssl_verify(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock, cipher_list: str, verify_ssl: True
|
||||
) -> None:
|
||||
"""Test with alternate cipherlist."""
|
||||
"""Test with alternate cipherlist or disabled ssl verification."""
|
||||
config = MOCK_CONFIG.copy()
|
||||
config["ssl_cipher_list"] = cipher_list
|
||||
config["verify_ssl"] = verify_ssl
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||
|
@ -562,3 +564,49 @@ async def test_config_flow_with_cipherlist(
|
|||
assert result2["title"] == "email@email.com"
|
||||
assert result2["data"] == config
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_config_flow_from_with_advanced_settings(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||
) -> None:
|
||||
"""Test if advanced settings show correctly."""
|
||||
config = MOCK_CONFIG.copy()
|
||||
config["ssl_cipher_list"] = "python_default"
|
||||
config["verify_ssl"] = True
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||
)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.imap.config_flow.connect_to_server",
|
||||
side_effect=asyncio.TimeoutError,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["errors"]["base"] == "cannot_connect"
|
||||
assert "ssl_cipher_list" in result2["data_schema"].schema
|
||||
|
||||
config["ssl_cipher_list"] = "modern"
|
||||
with patch(
|
||||
"homeassistant.components.imap.config_flow.connect_to_server"
|
||||
) as mock_client:
|
||||
mock_client.return_value.search.return_value = (
|
||||
"OK",
|
||||
[b""],
|
||||
)
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"], config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "email@email.com"
|
||||
assert result3["data"] == config
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue