From e75d24aca2ec99b74630b024c6ba94fcae17f106 Mon Sep 17 00:00:00 2001 From: Hirschfeld Date: Mon, 17 Jul 2017 11:38:04 +1000 Subject: [PATCH] Create `getgrnam` wrapper function to allow mocking in tests --- jupyterhub/auth.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jupyterhub/auth.py b/jupyterhub/auth.py index 68f20b0a..95eb1018 100644 --- a/jupyterhub/auth.py +++ b/jupyterhub/auth.py @@ -24,6 +24,15 @@ from .utils import url_path_join from .traitlets import Command + +def getgrnam(name): + """Wrapper function to protect against `grp` not being available + on Windows + """ + import grp + return grp.getgrnam(name) + + class Authenticator(LoggingConfigurable): """Base class for implementing an authentication provider for JupyterHub""" @@ -429,7 +438,6 @@ class LocalAuthenticator(Authenticator): """ If group_whitelist is configured, check if authenticating user is part of group. """ - from grp import getgrnam if not self.group_whitelist: return False for grnam in self.group_whitelist: