-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cipher list option to IMAP config flow (#91896)
* Add cipher list option to IMAP config flow * Use client_context to get the ssl_context * Formatting * Add ssl error no make error handling more specific * Make ssl_ciper_list an advanced option
- Loading branch information
Showing
6 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Test the imap config flow.""" | ||
import asyncio | ||
import ssl | ||
from unittest.mock import AsyncMock, patch | ||
|
||
from aioimaplib import AioImapException | ||
|
@@ -113,10 +114,16 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None: | |
|
||
|
||
@pytest.mark.parametrize( | ||
"exc", | ||
[asyncio.TimeoutError, AioImapException("")], | ||
("exc", "error"), | ||
[ | ||
(asyncio.TimeoutError, "cannot_connect"), | ||
(AioImapException(""), "cannot_connect"), | ||
(ssl.SSLError, "ssl_error"), | ||
], | ||
) | ||
async def test_form_cannot_connect(hass: HomeAssistant, exc: Exception) -> None: | ||
async def test_form_cannot_connect( | ||
hass: HomeAssistant, exc: Exception, error: str | ||
) -> None: | ||
"""Test we handle cannot connect error.""" | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER} | ||
|
@@ -131,7 +138,7 @@ async def test_form_cannot_connect(hass: HomeAssistant, exc: Exception) -> None: | |
) | ||
|
||
assert result2["type"] == FlowResultType.FORM | ||
assert result2["errors"] == {"base": "cannot_connect"} | ||
assert result2["errors"] == {"base": error} | ||
|
||
# make sure we do not lose the user input if somethings gets wrong | ||
assert { | ||
|
@@ -455,3 +462,35 @@ async def test_import_flow_connection_error(hass: HomeAssistant) -> None: | |
|
||
assert result["type"] == FlowResultType.ABORT | ||
assert result["reason"] == "cannot_connect" | ||
|
||
|
||
@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 | ||
) -> None: | ||
"""Test with alternate cipherlist.""" | ||
config = MOCK_CONFIG.copy() | ||
config["ssl_cipher_list"] = cipher_list | ||
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" | ||
) as mock_client: | ||
mock_client.return_value.search.return_value = ( | ||
"OK", | ||
[b""], | ||
) | ||
result2 = await hass.config_entries.flow.async_configure( | ||
result["flow_id"], config | ||
) | ||
await hass.async_block_till_done() | ||
|
||
assert result2["type"] == FlowResultType.CREATE_ENTRY | ||
assert result2["title"] == "[email protected]" | ||
assert result2["data"] == config | ||
assert len(mock_setup_entry.mock_calls) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters