-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maint: Add protections in line with base
- Loading branch information
1 parent
a7b2556
commit c0bf01d
Showing
8 changed files
with
155 additions
and
52 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
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,8 +1,14 @@ | ||
# pylint: disable=line-too-long, unused-argument | ||
"""Test the config flow.""" | ||
|
||
from copy import deepcopy | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
from homeassistant import config_entries | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.data_entry_flow import FlowResultType | ||
from requests_mock import Mocker | ||
|
||
from custom_components.ms365_mail.integration.const_integration import ( | ||
CONF_HAS_ATTACHMENT, | ||
|
@@ -14,7 +20,14 @@ | |
) | ||
|
||
from ..helpers.mock_config_entry import MS365MockConfigEntry | ||
from ..helpers.utils import get_schema_default | ||
from ..helpers.utils import build_token_url, get_schema_default, mock_token | ||
from .const_integration import ( | ||
AUTH_CALLBACK_PATH_DEFAULT, | ||
BASE_CONFIG_ENTRY, | ||
DOMAIN, | ||
SHARED_TOKEN_PERMS, | ||
) | ||
from .helpers_integration.mocks import MS365MOCKS | ||
|
||
|
||
async def test_options_flow( | ||
|
@@ -76,3 +89,48 @@ async def test_options_flow_empty( | |
assert CONF_IMPORTANCE not in result["data"] | ||
assert CONF_HAS_ATTACHMENT not in result["data"] | ||
assert CONF_IS_UNREAD not in result["data"] | ||
|
||
|
||
async def test_shared_email_invalid( | ||
hass: HomeAssistant, | ||
requests_mock: Mocker, | ||
caplog: pytest.LogCaptureFixture, | ||
) -> None: | ||
"""Test for invalid shared mailbox.""" | ||
mock_token(requests_mock, SHARED_TOKEN_PERMS) | ||
MS365MOCKS.standard_mocks(requests_mock) | ||
|
||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, context={"source": config_entries.SOURCE_USER} | ||
) | ||
|
||
user_input = deepcopy(BASE_CONFIG_ENTRY) | ||
email = "[email protected]" | ||
user_input["shared_mailbox"] = email | ||
result = await hass.config_entries.flow.async_configure( | ||
result["flow_id"], | ||
user_input=user_input, | ||
) | ||
|
||
with patch( | ||
f"custom_components.{DOMAIN}.classes.permissions.Account", | ||
return_value=mock_account(email), | ||
): | ||
result = await hass.config_entries.flow.async_configure( | ||
result["flow_id"], | ||
user_input={ | ||
"url": build_token_url(result, AUTH_CALLBACK_PATH_DEFAULT), | ||
}, | ||
) | ||
|
||
assert result["type"] is FlowResultType.CREATE_ENTRY | ||
|
||
assert ( | ||
f"Login email address '{email}' should not be entered as shared email address, config attribute removed" | ||
in caplog.text | ||
) | ||
|
||
|
||
def mock_account(email): | ||
"""Mock the account.""" | ||
return MagicMock(is_authenticated=True, current_username=email, main_resource=email) |
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