-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow custom assertion URIs (#348)
* feat: Allow custom assertion URIs * Update README * Remove CUSTOM_ASSERTION_URI * Lambda to func * URI to URL
- Loading branch information
Showing
3 changed files
with
37 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
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 |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
from django.http import HttpRequest | ||
from django.test.client import RequestFactory | ||
from django.urls import NoReverseMatch | ||
from saml2 import BINDING_HTTP_POST | ||
|
||
from django_saml2_auth.exceptions import SAMLAuthError | ||
from django_saml2_auth.saml import ( | ||
decode_saml_response, | ||
|
@@ -113,6 +115,13 @@ def get_metadata_auto_conf_urls( | |
return [{"url": METADATA_URL1}, {"url": METADATA_URL2}] | ||
|
||
|
||
def get_custom_assertion_url(): | ||
return "https://example.com/custom-tenant/acs" | ||
|
||
|
||
GET_CUSTOM_ASSERTION_URL = "django_saml2_auth.tests.test_saml.get_custom_assertion_url" | ||
|
||
|
||
def mock_extract_user_identity( | ||
user: Dict[str, Optional[Any]], authn_response: AuthnResponse | ||
) -> Dict[str, Optional[Any]]: | ||
|
@@ -457,6 +466,19 @@ def test_get_saml_client_success_with_key_and_cert_files( | |
del settings.SAML2_AUTH[key] | ||
|
||
|
||
def test_get_saml_client_success_with_custom_assertion_url_hook(settings: SettingsWrapper): | ||
settings.SAML2_AUTH["METADATA_LOCAL_FILE_PATH"] = "django_saml2_auth/tests/metadata.xml" | ||
|
||
settings.SAML2_AUTH["TRIGGER"]["GET_CUSTOM_ASSERTION_URL"] = GET_CUSTOM_ASSERTION_URL | ||
|
||
result = get_saml_client("example.com", acs, "[email protected]") | ||
assert result is not None | ||
assert "https://example.com/custom-tenant/acs" in result.config.endpoint( | ||
"assertion_consumer_service", | ||
BINDING_HTTP_POST, | ||
"sp", | ||
) | ||
|
||
@responses.activate | ||
def test_decode_saml_response_success( | ||
settings: SettingsWrapper, | ||
|