From 9d5784efb9d97b2d4e9011f08ccd3289c85a786d Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Thu, 24 Oct 2019 09:01:23 -0700 Subject: [PATCH] Pass in base_url rather than app object - Limits what we consider public API - Still allows for redirects outside JupyterHub --- jupyterhub/app.py | 3 ++- jupyterhub/handlers/base.py | 2 +- jupyterhub/tests/test_pages.py | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/jupyterhub/app.py b/jupyterhub/app.py index 66e1b623..17deac41 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -1269,7 +1269,8 @@ class JupyterHub(Application): 2. request - A Tornado HTTPServerRequest object representing the current request. 3. user - The currently authenticated user. - 4. app - The JupyterHub object + 4. base_url - The base_url of the current hub, to allow for relative + redirects It should return the new URL to redirect to, or None to preserve current behavior. diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index 7c51c360..aa7eb281 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -1490,7 +1490,7 @@ class UserRedirectHandler(BaseHandler): if self.app.user_redirect_hook: url = await maybe_future( self.app.user_redirect_hook( - path, self.request, self.current_user, self.app + path, self.request, self.current_user, self.base_url ) ) if url is None: diff --git a/jupyterhub/tests/test_pages.py b/jupyterhub/tests/test_pages.py index 14ebd901..dc40b0bc 100644 --- a/jupyterhub/tests/test_pages.py +++ b/jupyterhub/tests/test_pages.py @@ -406,11 +406,11 @@ async def test_user_redirect_hook(app, username): name = username cookies = await app.login_user(name) - async def dummy_redirect(path, request, user, passed_app): - assert passed_app == app + async def dummy_redirect(path, request, user, base_url): + assert base_url == app.base_url assert path == 'redirect-to-terminal' assert request.uri == ujoin( - app.hub.base_url, 'user-redirect', 'redirect-to-terminal' + base_url, 'hub', 'user-redirect', 'redirect-to-terminal' ) url = ujoin(user.url, '/terminals/1') return url