diff --git a/multiauthenticator/multiauthenticator.py b/multiauthenticator/multiauthenticator.py index 61b881e..dfe7040 100644 --- a/multiauthenticator/multiauthenticator.py +++ b/multiauthenticator/multiauthenticator.py @@ -123,7 +123,11 @@ def check_blocked_users(self, username, authentication=None): self._authenticators.append(authenticator) def get_custom_html(self, base_url): - """Re-implementation generating one login button per configured authenticator""" + """Re-implementation generating one login button per configured authenticator + + Note: the html generated in this method will be passed through Jinja's template + rendering, see the login implementation in JupyterHub's sources. + """ html = [] for authenticator in self._authenticators: @@ -137,7 +141,7 @@ def get_custom_html(self, base_url): html.append( f"""
diff --git a/multiauthenticator/tests/test_multiauthenticator.py b/multiauthenticator/tests/test_multiauthenticator.py index 4b55155..b288707 100644 --- a/multiauthenticator/tests/test_multiauthenticator.py +++ b/multiauthenticator/tests/test_multiauthenticator.py @@ -4,6 +4,7 @@ """Test module for the MultiAuthenticator class""" import pytest +from jinja2 import Template from jupyterhub.auth import DummyAuthenticator from jupyterhub.auth import PAMAuthenticator from oauthenticator import OAuthenticator @@ -297,3 +298,27 @@ class MyAuthenticator(OAuthenticator): MultiAuthenticator() assert f"Login service cannot contain {PREFIX_SEPARATOR}" in str(excinfo.value) + + +def test_next_handling(): + MultiAuthenticator.authenticators = [ + ( + PAMAuthenticator, + "/pam", + {"service_name": "test-service", "allowed_users": {"test"}}, + ), + ] + + multi_authenticator = MultiAuthenticator() + html = multi_authenticator.get_custom_html("") + + template = Template(html) + + with_next = template.render({"next": "/next-destination"}) + assert "href='pam/login?next=/next-destination'" in with_next + + without_next = template.render() + assert "href='pam/login'" in without_next + + with_empty_next = template.render({"next": ""}) + assert "href='pam/login'" in with_empty_next