Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
[BAU] convert emails to lower case when reading from a mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrusdobbs committed Dec 4, 2023
1 parent 95a43d7 commit fd8a20e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/main/authorisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, auth_class: type[AuthBase], mapping: dict[str, tuple[tuple[st
"""
self._auth_class = auth_class
# for each item in the dictionary, encapsulate the auth details values in an instance of the auth_class
self._mapping = {email: auth_class(*auth_details) for email, auth_details in mapping.items()}
self._mapping = {email.lower(): auth_class(*auth_details) for email, auth_details in mapping.items()}

def get_auth(self, email: str) -> AuthBase | None:
"""Get the authorisation information associated with the given email address.
Expand Down
14 changes: 14 additions & 0 deletions tests/test_authorisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def mock_mapping():
mapping = {
"wizard1@hogwarts.magic.uk": (("Hogwarts",), ("Professor Albus Dumbledore",)),
"hogwarts.magic.uk": (("Hogwarts",), ("Harry Potter", "Ron Weasley")),
"wizardWITHCAPSINMAPPING@charingcross.magic.uk": (("Diagon Alley",), ("Snape",)),
}
return mapping

Expand Down Expand Up @@ -66,6 +67,19 @@ def test_auth_mapping_email_match_case_insensitive(mock_auth_mapping, mock_auth_
assert auth.get_auth_dict() == {"Wizards": ("Professor Albus Dumbledore",)}


def test_auth_mapping_email_match_case_insensitive_from_mapping(mock_auth_mapping, mock_auth_class):
"""
GIVEN a valid AuthMapping object
WHEN an email address is passed to it that contained caps in the original mapping
THEN it should return the mapping for that email regardless of case
"""
auth = mock_auth_mapping.get_auth("wizardwithcapsinmapping@charingcross.magic.uk")

assert isinstance(auth, mock_auth_class)
assert auth.get_organisations() == ("Diagon Alley",)
assert auth.get_auth_dict() == {"Wizards": ("Snape",)}


def test_auth_mapping_domain_match(mock_auth_mapping, mock_auth_class):
"""
GIVEN a valid AuthMapping object
Expand Down

0 comments on commit fd8a20e

Please sign in to comment.