-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Spawner options to enable admins to spawn user sessions (#598)
* FEAT: add Spawner options for to Admin logins * TST: update selenium tests with admin login and logout routines * TST: fix to AdminDriverTest logout * TST: include tests for Spawner Options form * FIX: explictly include default methods on BaseSpawner * FIX: typos in HTML string for options form * FIX: further typos in HTML string for options form * TST: fix CSS selector reference in options form test * DOC: update user documentation on admin UI * CLN: simplify BaseSpawner options_from_form and cmd logic * FIX: typo, BaseSpawner.cmd property should be a list * CLN: small clean up and flake8 fix * TST: fixes to BaseSpawner.cmd unit tests * DOC: add documentation for manually shutting down sessions when admin to re-create the options form * DEV: override LogoutHandler to close admin session when user logs out, rather than manually navigating to JupyterHub home page * DEV: expose SimphonyRemoteAuthMixin in remoteappmanager.jupyterhub.auth module * DOC: update documentation on admin auto-sign outs * ENH: robustify custom logout handler by explictly waiting for stop_single_user call to complete
- Loading branch information
Showing
12 changed files
with
173 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .world_authenticator import WorldAuthenticator # noqa | ||
from .basic_authenticator import BasicAuthenticator # noqa | ||
from .github_whitelist_authenticator import GitHubWhitelistAuthenticator # noqa | ||
from .simphony_remote_auth_mixin import SimphonyRemoteAuthMixin # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
remoteappmanager/jupyterhub/auth/simphony_remote_auth_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from tornado import gen | ||
|
||
from jupyterhub.handlers import LogoutHandler as _LogoutHandler | ||
from jupyterhub.handlers import LoginHandler | ||
|
||
|
||
class LogoutHandler(_LogoutHandler): | ||
""" Custom logout handler that also closes servers of admin | ||
users, so that spawner options form will be shown during every login | ||
""" | ||
@gen.coroutine | ||
def get(self): | ||
user = self.get_current_user() | ||
if user: | ||
# Ensures admin sessions are shut down when user | ||
# logs out so that the spawner options form is | ||
# shown upon subsequent logins | ||
# TODO: replace for configuring shutdown_on_logout option | ||
# once running on jupyterhub>=1.0.0 | ||
if user.admin and user.spawner is not None: | ||
self.log.info(f"Shutting down {user.name}'s server") | ||
yield gen.maybe_future(self.stop_single_user(user)) | ||
self.log.info("User logged out: %s", user.name) | ||
self.clear_login_cookie() | ||
for name in user.other_user_cookies: | ||
self.clear_login_cookie(name) | ||
user.other_user_cookies = set([]) | ||
self.statsd.incr('logout') | ||
self.redirect(self.settings['login_url'], permanent=False) | ||
|
||
|
||
class SimphonyRemoteAuthMixin: | ||
|
||
def get_handlers(self, app): | ||
"""Includes standard LoginHandler and modified LogoutHandler that | ||
closes admin sessions upon signing out | ||
""" | ||
return [ | ||
('/login', LoginHandler), | ||
('/logout', LogoutHandler) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
from selenium_tests.RemoteAppDriverTest import RemoteAppDriverTest | ||
from selenium.webdriver.common.by import By | ||
|
||
|
||
class TestSpawnerOptionsForm(RemoteAppDriverTest): | ||
|
||
def test_admin_login_default_session(self): | ||
self.login("admin") | ||
|
||
self.click_first_element_located(By.ID, "start") | ||
self.click_first_element_located(By.CSS_SELECTOR, "input.btn") | ||
self.click_first_element_located(By.ID, "start") | ||
|
||
self.wait_until_text_inside_element_located( | ||
By.CSS_SELECTOR, ".header", "ADMIN") | ||
|
||
def test_admin_login_user_session(self): | ||
self.login("admin") | ||
|
||
self.click_first_element_located(By.ID, "start") | ||
self.click_first_element_located( | ||
By.CSS_SELECTOR, "#session_form > option:nth-child(2)") | ||
self.click_first_element_located(By.CSS_SELECTOR, "input.btn") | ||
self.click_first_element_located(By.ID, "start") | ||
|
||
self.wait_until_text_inside_element_located( | ||
By.CSS_SELECTOR, ".header", "APPLICATIONS") | ||
|
||
def tearDown(self): | ||
self.logout() | ||
RemoteAppDriverTest.tearDown(self) |