From 29da0229749976c4e251fe964babd685a9cc35b3 Mon Sep 17 00:00:00 2001 From: Bastien Date: Mon, 20 Nov 2023 14:47:51 +0100 Subject: [PATCH 1/4] fix: allow redirection after login --- multiauthenticator/multiauthenticator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiauthenticator/multiauthenticator.py b/multiauthenticator/multiauthenticator.py index 61b881e..88d7de9 100644 --- a/multiauthenticator/multiauthenticator.py +++ b/multiauthenticator/multiauthenticator.py @@ -137,7 +137,7 @@ def get_custom_html(self, base_url): html.append( f"""
- + Sign in with {login_service}
From 375e8904577a581377edb01a992531d7c3c1875f Mon Sep 17 00:00:00 2001 From: Bastien Date: Mon, 20 Nov 2023 15:10:13 +0100 Subject: [PATCH 2/4] fix: allow redirection after login --- multiauthenticator/multiauthenticator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiauthenticator/multiauthenticator.py b/multiauthenticator/multiauthenticator.py index 88d7de9..48b488b 100644 --- a/multiauthenticator/multiauthenticator.py +++ b/multiauthenticator/multiauthenticator.py @@ -137,7 +137,7 @@ def get_custom_html(self, base_url): html.append( f""" From 0132e54429fa45ba4048b0b489ed6c8385d1fdc1 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 20 Nov 2023 15:35:08 +0100 Subject: [PATCH 3/4] doc: annotate get_custom_html docstring to keep in mind that Jinja is involved --- multiauthenticator/multiauthenticator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/multiauthenticator/multiauthenticator.py b/multiauthenticator/multiauthenticator.py index 48b488b..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: From dc012232ad98759c0a97393d129f24ef074eb510 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 20 Nov 2023 15:35:50 +0100 Subject: [PATCH 4/4] test: ensure next handling is working as expected --- .../tests/test_multiauthenticator.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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