-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow claims-like attribute keys (#253)
* added feature and tests * added author * cleanup * cleanup and add .idea (intellij) to .gitignore * remove nested .idea/ * cleanup debugging * Remove unused file * Reformat with ruff
- Loading branch information
Showing
4 changed files
with
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,4 @@ target/ | |
|
||
# IDEs | ||
.vscode/ | ||
.idea/ |
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
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 |
---|---|---|
|
@@ -123,6 +123,21 @@ def get_user_identity() -> Mapping[str, List[str]]: | |
} | ||
|
||
|
||
def get_user_identify_with_slashed_keys() -> Mapping[str, List[str]]: | ||
"""Fixture for returning user identity produced by pysaml2 with slashed, claim-like keys. | ||
Returns: | ||
dict: keys are SAML attributes and values are lists of attribute values | ||
""" | ||
return { | ||
"http://schemas.org/user/username": ["[email protected]"], | ||
"http://schemas.org/user/claim2.0/email": ["[email protected]"], | ||
"http://schemas.org/user/claim2.0/first_name": ["John"], | ||
"http://schemas.org/user/claim2.0/last_name": ["Doe"], | ||
"http://schemas.org/auth/server/token": ["TOKEN"], | ||
} | ||
|
||
|
||
def mock_parse_authn_request_response( | ||
self: Saml2Client, response: AuthnResponse, binding: str | ||
) -> "MockAuthnResponse": # type: ignore # noqa: F821 | ||
|
@@ -447,6 +462,29 @@ def test_extract_user_identity_success(): | |
assert result["user_identity"] == get_user_identity() | ||
|
||
|
||
def test_extract_user_identity_with_slashed_attribute_keys_success(settings: SettingsWrapper): | ||
"""Test extract_user_identity function to verify if it correctly extracts user identity | ||
information from a (pysaml2) parsed SAML response with slashed attribute keys.""" | ||
settings.SAML2_AUTH = { | ||
"ATTRIBUTES_MAP": { | ||
"email": "http://schemas.org/user/claim2.0/email", | ||
"username": "http://schemas.org/user/username", | ||
"first_name": "http://schemas.org/user/claim2.0/first_name", | ||
"last_name": "http://schemas.org/user/claim2.0/last_name", | ||
"token": "http://schemas.org/auth/server/token", | ||
} | ||
} | ||
|
||
result = extract_user_identity(get_user_identify_with_slashed_keys()) # type: ignore | ||
|
||
assert len(result) == 6 | ||
assert result["username"] == result["email"] == "[email protected]" | ||
assert result["first_name"] == "John" | ||
assert result["last_name"] == "Doe" | ||
assert result["token"] == "TOKEN" | ||
assert result["user_identity"] == get_user_identify_with_slashed_keys() | ||
|
||
|
||
def test_extract_user_identity_token_not_required(settings: SettingsWrapper): | ||
"""Test extract_user_identity function to verify if it correctly extracts user identity | ||
information from a (pysaml2) parsed SAML response when token is not required.""" | ||
|