Pass in base_url rather than app object

- Limits what we consider public API
- Still allows for redirects outside JupyterHub
This commit is contained in:
YuviPanda
2019-10-24 09:01:23 -07:00
parent d66f0635a3
commit 9d5784efb9
3 changed files with 6 additions and 5 deletions

View File

@@ -1269,7 +1269,8 @@ class JupyterHub(Application):
2. request - A Tornado HTTPServerRequest object representing the 2. request - A Tornado HTTPServerRequest object representing the
current request. current request.
3. user - The currently authenticated user. 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 It should return the new URL to redirect to, or None to preserve
current behavior. current behavior.

View File

@@ -1490,7 +1490,7 @@ class UserRedirectHandler(BaseHandler):
if self.app.user_redirect_hook: if self.app.user_redirect_hook:
url = await maybe_future( url = await maybe_future(
self.app.user_redirect_hook( 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: if url is None:

View File

@@ -406,11 +406,11 @@ async def test_user_redirect_hook(app, username):
name = username name = username
cookies = await app.login_user(name) cookies = await app.login_user(name)
async def dummy_redirect(path, request, user, passed_app): async def dummy_redirect(path, request, user, base_url):
assert passed_app == app assert base_url == app.base_url
assert path == 'redirect-to-terminal' assert path == 'redirect-to-terminal'
assert request.uri == ujoin( 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') url = ujoin(user.url, '/terminals/1')
return url return url