-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ set -x | |
|
||
black "${files[@]}" | ||
ruff --fix "${files[@]}" | ||
mypy synapse-sso-connect | ||
mypy synapse-sso-proconnect |
File renamed without changes.
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 |
---|---|---|
|
@@ -78,7 +78,7 @@ async def map_user_attributes( | |
) | ||
|
||
# Return a dict with specific email replacements mappings. | ||
async def getReplaceMapping(): | ||
async def getReplaceMapping(self): | ||
return { | ||
# Specific email replacement | ||
"[email protected]" : "[email protected]", | ||
|
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Any, Dict, Optional | ||
from unittest.mock import AsyncMock, Mock | ||
|
||
import attr | ||
from synapse.module_api import ModuleApi, UserID | ||
|
||
from synapse_sso_proconnect.proconnect_mapping import ProConnectMappingProvider | ||
|
||
class MockHomeserver: | ||
def get_datastores(self): | ||
return Mock(spec=["main"]) | ||
|
||
def get_task_scheduler(self): | ||
return Mock(spec=["register_action"]) | ||
|
||
def create_module( | ||
config_override: Optional[Dict[str, Any]] = None, server_name: str = "example.com" | ||
) -> ProConnectMappingProvider: | ||
# Create a mock based on the ModuleApi spec, but override some mocked functions | ||
# because some capabilities are needed for running the tests. | ||
module_api = Mock(spec=ModuleApi) | ||
|
||
if config_override is None: | ||
config_override = {} | ||
config_override["id_server"] = "example.com" | ||
|
||
config = ProConnectMappingProvider.parse_config(config_override) | ||
|
||
return ProConnectMappingProvider(config, module_api) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from unittest.mock import AsyncMock | ||
import aiounittest | ||
from tests import create_module | ||
from synapse_sso_proconnect.proconnect_mapping import ProConnectMappingProvider | ||
|
||
|
||
def create_module( | ||
) -> ProConnectMappingProvider: | ||
module_api = AsyncMock() | ||
# Adding _store to the module_api object | ||
module_api._store = AsyncMock() | ||
module_api.getReplaceMapping = AsyncMock( | ||
return_value={"numerique.gouv.fr": "beta.gouv.fr"} | ||
) | ||
module_api._store.get_user_id_by_threepid.side_effect = lambda typ, email: ( | ||
"test-beta" if email == "[email protected]" | ||
else "test-exemple" if email == "[email protected]" | ||
else None | ||
) | ||
config= {} | ||
return ProConnectMappingProvider(config, module_api) | ||
|
||
|
||
class ProConnectMappingTest(aiounittest.AsyncTestCase): | ||
def setUp(self) -> None: | ||
self.module = create_module() | ||
|
||
|
||
async def test_with_email_replacement(self): | ||
|
||
# Call the tested function with an email that requires replacement | ||
user_id = await self.module.search_user_id_by_threepid("[email protected]") | ||
|
||
# Assertions | ||
self.assertEqual(user_id, "test-beta") # Should match the replaced email | ||
self.module.module_api._store.get_user_id_by_threepid.assert_any_call("email", "[email protected]") | ||
self.module.module_api._store.get_user_id_by_threepid.assert_any_call("email", "[email protected]") |
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