Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion invenio_saml/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def default_account_info(attributes, remote_app):

name = attributes[mappings["name"]][0]
surname = attributes[mappings["surname"]][0]
email = attributes[mappings["email"]][0]
email = attributes[mappings["email"]][0].lower()
external_id = attributes[mappings["external_id"]][0]
username = (
remote_app + "-" + external_id.split("@")[0]
Expand Down
32 changes: 32 additions & 0 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,35 @@ def test_custom_user_lookup(appctx, users):
assert mock_user_lookup.call_count == 1
assert current_user.is_authenticated
assert current_user.confirmed_at is None


def test_acs_handler_email_lowercase(appctx, db):
"""Test ACS handler factory regarding email lowercase conversion."""
appctx.config["SSO_SAML_IDPS"] = {
"test": {
"mappings": {
"email": "email",
"name": "name",
"surname": "surname",
"external_id": "external_id",
},
}
}
attrs = dict(
email=["federico@Example.Com"],
name=["federico"],
surname=["Fernandez"],
external_id=["12345679abcdf"],
)

acs_handler = acs_handler_factory("test")

with appctx.test_request_context(), patch(
"invenio_saml.utils.SAMLAuth"
) as mock_saml_auth:
mock_saml_auth.get_attributes.return_value = attrs
next_url = acs_handler(mock_saml_auth, "/foo")

assert next_url == "/foo"
assert current_user.is_authenticated
assert current_user.email == "federico@example.com"
Loading