def test_validate_names(io_loop): a = auth.PAMAuthenticator() assert a.validate_username('willow') assert a.validate_username('giles') a = auth.PAMAuthenticator(username_pattern='w.*') assert not a.validate_username('xander') assert a.validate_username('willow')
def test_validate_names(): a = auth.PAMAuthenticator() assert a.validate_username('willow') assert a.validate_username('giles') assert a.validate_username('Test') assert a.validate_username('hExi') assert a.validate_username('Glenn#Smith!') a = auth.PAMAuthenticator(username_pattern='w.*') assert not a.validate_username('xander') assert a.validate_username('willow')
async def test_cant_add_system_user(): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.add_user_cmd = ['jupyterhub-fake-command'] authenticator.create_system_users = True class DummyFile: def read(self): return b'dummy error' class DummyPopen: def __init__(self, *args, **kwargs): self.args = args self.kwargs = kwargs self.returncode = 1 self.stdout = DummyFile() def wait(self): return with mock.patch.object(auth, 'Popen', DummyPopen): with pytest.raises(RuntimeError) as exc: await authenticator.add_user(user) assert str(exc.value ) == 'Failed to create system user lioness4321: dummy error'
def test_cant_add_system_user(io_loop): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.create_system_users = True def check_output(cmd, *a, **kw): raise CalledProcessError(1, cmd) with mock.patch.object(auth, 'check_output', check_output): with pytest.raises(RuntimeError): io_loop.run_sync(lambda : authenticator.add_user(user))
def test_cant_add_system_user(io_loop): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.add_user_cmd = ['jupyterhub-fake-command'] authenticator.create_system_users = True def check_call(cmd, *a, **kw): raise CalledProcessError(1, cmd) with mock.patch.object(auth, 'check_call', check_call): with pytest.raises(CalledProcessError): io_loop.run_sync(lambda : authenticator.add_user(user))
def test_add_system_user(io_loop): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.create_system_users = True authenticator.add_user_cmd = ['echo', '/home/USERNAME'] record = {} def check_call(cmd, *a, **kw): record['cmd'] = cmd with mock.patch.object(auth, 'check_call', check_call): io_loop.run_sync(lambda : authenticator.add_user(user)) assert record['cmd'] == ['echo', '/home/lioness4321', 'lioness4321']
def test_add_system_user(io_loop): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.create_system_users = True def check_output(*a, **kw): return record = {} def check_call(cmd, *a, **kw): record['cmd'] = cmd with mock.patch.object(auth, 'check_output', check_output), \ mock.patch.object(auth, 'check_call', check_call): io_loop.run_sync(lambda : authenticator.add_user(user)) assert user.name in record['cmd']
def test_add_system_user(io_loop): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.create_system_users = True authenticator.add_user_cmd = ['echo', '/home/USERNAME'] record = {} class DummyPopen: def __init__(self, cmd, *args, **kwargs): record['cmd'] = cmd self.returncode = 0 def wait(self): return with mock.patch.object(auth, 'Popen', DummyPopen): io_loop.run_sync(lambda : authenticator.add_user(user)) assert record['cmd'] == ['echo', '/home/lioness4321', 'lioness4321']
def test_handlers(app): a = auth.PAMAuthenticator() handlers = a.get_handlers(app) assert handlers[0][0] == '/login'
def test_urls(): a = auth.PAMAuthenticator() logout = a.logout_url('/base/url/') login = a.login_url('/base/url') assert logout == '/base/url/logout' assert login == '/base/url/login'
async def test_wont_add_system_user(): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.create_system_users = False with pytest.raises(KeyError): await authenticator.add_user(user)
def test_wont_add_system_user(io_loop): user = orm.User(name='lioness4321') authenticator = auth.PAMAuthenticator(whitelist={'mal'}) authenticator.create_system_users = False with pytest.raises(KeyError): io_loop.run_sync(lambda : authenticator.add_user(user))