@@ -123,6 +123,21 @@ def get_user_identity() -> Mapping[str, List[str]]:
123
123
}
124
124
125
125
126
+ def get_user_identify_with_slashed_keys () -> Mapping [str , List [str ]]:
127
+ """Fixture for returning user identity produced by pysaml2 with slashed, claim-like keys.
128
+
129
+ Returns:
130
+ dict: keys are SAML attributes and values are lists of attribute values
131
+ """
132
+ return {
133
+ "http://schemas.org/user/username" : [
"[email protected] " ],
134
+ "http://schemas.org/user/claim2.0/email" : [
"[email protected] " ],
135
+ "http://schemas.org/user/claim2.0/first_name" : ["John" ],
136
+ "http://schemas.org/user/claim2.0/last_name" : ["Doe" ],
137
+ "http://schemas.org/auth/server/token" : ["TOKEN" ],
138
+ }
139
+
140
+
126
141
def mock_parse_authn_request_response (
127
142
self : Saml2Client , response : AuthnResponse , binding : str
128
143
) -> "MockAuthnResponse" : # type: ignore # noqa: F821
@@ -447,6 +462,29 @@ def test_extract_user_identity_success():
447
462
assert result ["user_identity" ] == get_user_identity ()
448
463
449
464
465
+ def test_extract_user_identity_with_slashed_attribute_keys_success (settings : SettingsWrapper ):
466
+ """Test extract_user_identity function to verify if it correctly extracts user identity
467
+ information from a (pysaml2) parsed SAML response with slashed attribute keys."""
468
+ settings .SAML2_AUTH = {
469
+ "ATTRIBUTES_MAP" : {
470
+ "email" : "http://schemas.org/user/claim2.0/email" ,
471
+ "username" : "http://schemas.org/user/username" ,
472
+ "first_name" : "http://schemas.org/user/claim2.0/first_name" ,
473
+ "last_name" : "http://schemas.org/user/claim2.0/last_name" ,
474
+ "token" : "http://schemas.org/auth/server/token" ,
475
+ }
476
+ }
477
+
478
+ result = extract_user_identity (get_user_identify_with_slashed_keys ()) # type: ignore
479
+
480
+ assert len (result ) == 6
481
+ assert result [
"username" ]
== result [
"email" ]
== "[email protected] "
482
+ assert result ["first_name" ] == "John"
483
+ assert result ["last_name" ] == "Doe"
484
+ assert result ["token" ] == "TOKEN"
485
+ assert result ["user_identity" ] == get_user_identify_with_slashed_keys ()
486
+
487
+
450
488
def test_extract_user_identity_token_not_required (settings : SettingsWrapper ):
451
489
"""Test extract_user_identity function to verify if it correctly extracts user identity
452
490
information from a (pysaml2) parsed SAML response when token is not required."""
0 commit comments