From 73f1211286668c13350fbbb51e2c88a986ddd3d0 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Tue, 23 Jun 2020 20:11:49 +1200 Subject: [PATCH] Update append_query_parameters to have exclude=["none"] by default, and avoid using dicts with url_concat, to have consistent tests as otherwise in Python 3.5 the generated URL's could have parameters in random order. --- jupyterhub/handlers/base.py | 10 ++++++++-- jupyterhub/tests/test_pages.py | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index f2d21e89..b08a6ac7 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -668,12 +668,18 @@ class BaseHandler(RequestHandler): This is important to avoid infinite loops with the next parameter being added over and over, for instance. + The default value for ``exclude`` is an array with "next". This is useful + as most use cases in JupyterHub (all?) won't want to include the next + parameter twice (the next parameter is added elsewhere to the query + parameters). + :param str url: a URL - :param list exclude: optional list of parameters to be ignored + :param list exclude: optional list of parameters to be ignored, defaults to + a list with "next" (to avoid redirect-loops) :rtype (str) """ if not exclude: - exclude = [] + exclude = ['next'] if self.request.query: query_string = [ param diff --git a/jupyterhub/tests/test_pages.py b/jupyterhub/tests/test_pages.py index 544b54c9..3dc478ef 100644 --- a/jupyterhub/tests/test_pages.py +++ b/jupyterhub/tests/test_pages.py @@ -517,7 +517,7 @@ async def test_user_redirect_deprecated(app, username): async def test_login_page(app): - url = url_concat('login', dict(next='foo', param1='test')) + url = url_concat('login', [('next', 'foo'), ('param1', 'test')]) r = await get_page(url, app) assert r.url.endswith('/hub/login?next=foo¶m1=test') # now the login.html rendered template must include the given parameters in the form @@ -577,8 +577,8 @@ async def test_login_strip(app): (False, '///other.domain/triple', '', None), (False, '\\\\other.domain/backslashes', '', None), # params are handled correctly - (True, '/hub/admin', 'hub/admin?left=1&right=2', dict(left=1, right=2)), - (False, '/hub/admin', 'hub/admin?left=1&right=2', dict(left=1, right=2)), + (True, '/hub/admin', 'hub/admin?left=1&right=2', [('left', 1), ('right', 2)]), + (False, '/hub/admin', 'hub/admin?left=1&right=2', [('left', 1), ('right', 2)]), ], ) async def test_login_redirect(app, running, next_url, location, params):