diff --git a/integration-tests/test_hub.py b/integration-tests/test_hub.py index 9d63380..a4e8704 100644 --- a/integration-tests/test_hub.py +++ b/integration-tests/test_hub.py @@ -8,6 +8,7 @@ import asyncio import pwd import grp import sys +from tljh.normalize import generate_system_username # Use sudo to invoke it, since this is how users invoke it. @@ -112,4 +113,31 @@ async def test_user_admin_remove(): await u.ensure_server() # Assert that the user does *not* have admin rights - assert f'jupyter-{username}' in grp.getgrnam('jupyterhub-admins').gr_mem \ No newline at end of file + assert f'jupyter-{username}' in grp.getgrnam('jupyterhub-admins').gr_mem + + +@pytest.mark.asyncio +async def test_long_username(): + """ + User with a long name logs in, and we check if their name is properly truncated. + """ + # This *must* be localhost, not an IP + # aiohttp throws away cookies if we are connecting to an IP! + hub_url = 'http://localhost' + username = secrets.token_hex(32) + + assert 0 == await (await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, 'set', 'auth.type', 'dummyauthenticator.DummyAuthenticator')).wait() + assert 0 == await (await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, 'reload')).wait() + + # FIXME: wait for reload to finish & hub to come up + # Should be part of tljh-config reload + await asyncio.sleep(1) + async with User(username, hub_url, partial(login_dummy, password='')) as u: + await u.login() + await u.ensure_server() + + # Assert that the user exists + system_username = generate_system_username(f'jupyter-{username}') + assert pwd.getpwnam(system_username) is not None + + await u.stop_server() \ No newline at end of file