From c47ba3ebb260ecbdde5b35fd730e55fe1feaf399 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 29 Mar 2022 16:18:09 +0200 Subject: [PATCH 1/6] fix email sending issue --- .../web/server/src/simcore_service_webserver/login/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/server/src/simcore_service_webserver/login/plugin.py b/services/web/server/src/simcore_service_webserver/login/plugin.py index 179b148e8a4..388bf59ac17 100644 --- a/services/web/server/src/simcore_service_webserver/login/plugin.py +++ b/services/web/server/src/simcore_service_webserver/login/plugin.py @@ -54,7 +54,7 @@ def setup_login_storage(app: web.Application): def _setup_login_options(app: web.Application): settings: SMTPSettings = get_email_plugin_settings(app) - cfg = settings.dict(exclude_unset=True) + cfg = settings.dict(exclude_none=True) if INDEX_RESOURCE_NAME in app.router: cfg["LOGIN_REDIRECT"] = f"{app.router[INDEX_RESOURCE_NAME].url_for()}" From 1b7dbc8a2eb0b487402744fd6120a174658b46f1 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 29 Mar 2022 17:04:35 +0200 Subject: [PATCH 2/6] better choice --- .../web/server/src/simcore_service_webserver/login/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/server/src/simcore_service_webserver/login/plugin.py b/services/web/server/src/simcore_service_webserver/login/plugin.py index 388bf59ac17..4f57d559b17 100644 --- a/services/web/server/src/simcore_service_webserver/login/plugin.py +++ b/services/web/server/src/simcore_service_webserver/login/plugin.py @@ -54,7 +54,7 @@ def setup_login_storage(app: web.Application): def _setup_login_options(app: web.Application): settings: SMTPSettings = get_email_plugin_settings(app) - cfg = settings.dict(exclude_none=True) + cfg = settings.dict() if INDEX_RESOURCE_NAME in app.router: cfg["LOGIN_REDIRECT"] = f"{app.router[INDEX_RESOURCE_NAME].url_for()}" From 71fa9054a5c8f8eede24be6459cdc33ed67b61bb Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 29 Mar 2022 17:06:13 +0200 Subject: [PATCH 3/6] addiung debug --- services/web/server/src/simcore_service_webserver/login/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/services/web/server/src/simcore_service_webserver/login/utils.py b/services/web/server/src/simcore_service_webserver/login/utils.py index b295a1102cd..1572d59a92d 100644 --- a/services/web/server/src/simcore_service_webserver/login/utils.py +++ b/services/web/server/src/simcore_service_webserver/login/utils.py @@ -118,6 +118,7 @@ def flash_response(msg: str, level: str = "INFO") -> web.Response: async def send_mail(app: web.Application, msg: MIMEText): cfg: LoginOptions = get_plugin_options(app) + log.debug("Email configuration %s", cfg) msg["From"] = cfg.SMTP_SENDER smtp_args = dict( From f2653d3a4e497628650dd4b541d28fd40e9918fc Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 29 Mar 2022 18:05:51 +0200 Subject: [PATCH 4/6] renaming class and fixing warning --- .../unit/test_modules_project_networks.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/services/director-v2/tests/unit/test_modules_project_networks.py b/services/director-v2/tests/unit/test_modules_project_networks.py index 28cccb70637..f67f30e9388 100644 --- a/services/director-v2/tests/unit/test_modules_project_networks.py +++ b/services/director-v2/tests/unit/test_modules_project_networks.py @@ -26,7 +26,7 @@ class MockedCalls(BaseModel): attach: List[Any] -class TestCase(BaseModel): +class Example(BaseModel): existing_networks_with_aliases: NetworksWithAliases new_networks_with_aliases: NetworksWithAliases expected_calls: MockedCalls @@ -38,7 +38,7 @@ def using( new: Dict[str, Any], detach: List[Any], attach: List[Any], - ) -> "TestCase": + ) -> "Example": return cls( existing_networks_with_aliases=NetworksWithAliases.parse_obj(existing), new_networks_with_aliases=NetworksWithAliases.parse_obj(new), @@ -62,12 +62,12 @@ def _network_name(number: int) -> str: @pytest.fixture -def test_case_factory( +def examples_factory( mock_scheduler: AsyncMock, project_id: ProjectID -) -> List[TestCase]: +) -> List[Example]: return [ # nothing exists - TestCase.using( + Example.using( existing={}, new={ _network_name(1): { @@ -90,7 +90,7 @@ def test_case_factory( ], ), # with existing network, remove node 2 - TestCase.using( + Example.using( existing={ _network_name(1): { _node_id(1): _node_alias(1), @@ -111,7 +111,7 @@ def test_case_factory( attach=[], ), # remove node 2 and add node 2 with different alias - TestCase.using( + Example.using( existing={ _network_name(1): { _node_id(1): _node_alias(1), @@ -139,7 +139,7 @@ def test_case_factory( ], ), # nothing happens when updates with the same content - TestCase.using( + Example.using( existing={ _network_name(1): { _node_id(1): _node_alias(1), @@ -227,20 +227,20 @@ def mock_docker_calls(mocker: MockerFixture) -> Iterable[Dict[str, AsyncMock]]: async def test_send_network_configuration_to_dynamic_sidecar( mock_scheduler: AsyncMock, project_id: ProjectID, - test_case_factory: List[TestCase], + examples_factory: List[Example], mock_docker_calls: Dict[str, AsyncMock], ) -> None: - for test_case in test_case_factory: + for example in examples_factory: await _send_network_configuration_to_dynamic_sidecar( scheduler=mock_scheduler, project_id=project_id, - new_networks_with_aliases=test_case.new_networks_with_aliases, - existing_networks_with_aliases=test_case.existing_networks_with_aliases, + new_networks_with_aliases=example.new_networks_with_aliases, + existing_networks_with_aliases=example.existing_networks_with_aliases, ) - mock_scheduler.assert_has_calls(test_case.expected_calls.attach, any_order=True) - mock_scheduler.assert_has_calls(test_case.expected_calls.detach, any_order=True) + mock_scheduler.assert_has_calls(example.expected_calls.attach, any_order=True) + mock_scheduler.assert_has_calls(example.expected_calls.detach, any_order=True) async def test_get_networks_with_aliases_for_default_network_is_json_serializable( From 1cd1296cf513c703694926f9617354918ed37c1b Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 29 Mar 2022 18:09:29 +0200 Subject: [PATCH 5/6] fixed issues --- .../unit/test_modules_project_networks.py | 4 +--- .../login/settings.py | 8 +++---- .../tests/unit/isolated/test_login_plugin.py | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 services/web/server/tests/unit/isolated/test_login_plugin.py diff --git a/services/director-v2/tests/unit/test_modules_project_networks.py b/services/director-v2/tests/unit/test_modules_project_networks.py index f67f30e9388..0df7a98f7fb 100644 --- a/services/director-v2/tests/unit/test_modules_project_networks.py +++ b/services/director-v2/tests/unit/test_modules_project_networks.py @@ -62,9 +62,7 @@ def _network_name(number: int) -> str: @pytest.fixture -def examples_factory( - mock_scheduler: AsyncMock, project_id: ProjectID -) -> List[Example]: +def examples_factory(mock_scheduler: AsyncMock, project_id: ProjectID) -> List[Example]: return [ # nothing exists Example.using( diff --git a/services/web/server/src/simcore_service_webserver/login/settings.py b/services/web/server/src/simcore_service_webserver/login/settings.py index 23dae2af76e..82643595b83 100644 --- a/services/web/server/src/simcore_service_webserver/login/settings.py +++ b/services/web/server/src/simcore_service_webserver/login/settings.py @@ -42,12 +42,12 @@ class LoginOptions(BaseModel): LOGIN_REDIRECT: str = "/" LOGOUT_REDIRECT: str = "/" - SMTP_SENDER: Optional[str] = None + SMTP_SENDER: str SMTP_HOST: str SMTP_PORT: int - SMTP_TLS_ENABLED: bool = False - SMTP_USERNAME: Optional[str] = None - SMTP_PASSWORD: Optional[SecretStr] = None + SMTP_TLS_ENABLED: bool + SMTP_USERNAME: Optional[str] + SMTP_PASSWORD: Optional[SecretStr] # lifetime limits are in days REGISTRATION_CONFIRMATION_LIFETIME: PositiveFloat = 5 * _DAYS diff --git a/services/web/server/tests/unit/isolated/test_login_plugin.py b/services/web/server/tests/unit/isolated/test_login_plugin.py new file mode 100644 index 00000000000..ac696e7546a --- /dev/null +++ b/services/web/server/tests/unit/isolated/test_login_plugin.py @@ -0,0 +1,23 @@ +# pylint: disable=unused-argument +import os +from typing import Any, Dict + +from settings_library.email import SMTPSettings +from simcore_service_webserver.login.plugin import LoginOptions + + +def test_smtp_settings(mock_env_devel_environment: Dict[str, Any]): + + settings = SMTPSettings() + + cfg = settings.dict(exclude_unset=True) + + for env_name in cfg: + assert env_name in os.environ + + cfg = settings.dict() + + config = LoginOptions(**cfg) + print(config.json(indent=1)) + + assert config.SMTP_SENDER is not None From 41e04672582ecc76f9140de5a602b4ed24b561de Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Tue, 29 Mar 2022 18:24:25 +0200 Subject: [PATCH 6/6] fields must now be provided --- .../server/src/simcore_service_webserver/login/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/login/settings.py b/services/web/server/src/simcore_service_webserver/login/settings.py index 82643595b83..eeeeccede1b 100644 --- a/services/web/server/src/simcore_service_webserver/login/settings.py +++ b/services/web/server/src/simcore_service_webserver/login/settings.py @@ -46,8 +46,8 @@ class LoginOptions(BaseModel): SMTP_HOST: str SMTP_PORT: int SMTP_TLS_ENABLED: bool - SMTP_USERNAME: Optional[str] - SMTP_PASSWORD: Optional[SecretStr] + SMTP_USERNAME: Optional[str] = Field(...) + SMTP_PASSWORD: Optional[SecretStr] = Field(...) # lifetime limits are in days REGISTRATION_CONFIRMATION_LIFETIME: PositiveFloat = 5 * _DAYS