From dc012232ad98759c0a97393d129f24ef074eb510 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 20 Nov 2023 15:35:50 +0100 Subject: [PATCH] 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