2023-06-09 02:55:06 +02:00
|
|
|
import asyncio
|
2019-07-16 20:18:45 +03:00
|
|
|
from functools import partial
|
|
|
|
|
|
2023-05-15 08:51:35 +00:00
|
|
|
import pytest
|
|
|
|
|
from hubtraf.auth.dummy import login_dummy
|
|
|
|
|
from hubtraf.user import User
|
|
|
|
|
|
2023-06-09 02:55:06 +02:00
|
|
|
# Use sudo to invoke it, since this is how users invoke it.
|
|
|
|
|
# This catches issues with PATH
|
|
|
|
|
TLJH_CONFIG_PATH = ["sudo", "tljh-config"]
|
|
|
|
|
|
|
|
|
|
# This *must* be localhost, not an IP
|
|
|
|
|
# aiohttp throws away cookies if we are connecting to an IP!
|
2023-06-09 02:00:30 +02:00
|
|
|
HUB_URL = "http://localhost"
|
2023-06-06 16:53:16 +02:00
|
|
|
|
2019-07-16 20:18:45 +03:00
|
|
|
|
2023-06-09 02:55:06 +02:00
|
|
|
# FIXME: Other tests may have set the auth.type to dummy, so we reset it here to
|
|
|
|
|
# get the default of firstuseauthenticator. Tests should cleanup after
|
|
|
|
|
# themselves to a better degree, but its a bit trouble to reload the
|
|
|
|
|
# jupyterhub between each test as well if thats needed...
|
|
|
|
|
async def test_restore_relevant_tljh_state():
|
|
|
|
|
assert (
|
|
|
|
|
0
|
|
|
|
|
== await (
|
|
|
|
|
await asyncio.create_subprocess_exec(
|
|
|
|
|
*TLJH_CONFIG_PATH,
|
|
|
|
|
"set",
|
|
|
|
|
"auth.type",
|
|
|
|
|
"firstuseauthenticator.FirstUseAuthenticator",
|
|
|
|
|
)
|
|
|
|
|
).wait()
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
0
|
|
|
|
|
== await (
|
|
|
|
|
await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, "reload")
|
|
|
|
|
).wait()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2019-07-16 20:18:45 +03:00
|
|
|
@pytest.mark.parametrize(
|
2023-06-09 00:33:41 +02:00
|
|
|
"username, password, expect_successful_login",
|
2019-07-16 20:18:45 +03:00
|
|
|
[
|
2023-06-09 00:33:41 +02:00
|
|
|
("test-admin-username", "test-admin-password", True),
|
|
|
|
|
("user", "", False),
|
2019-07-16 20:18:45 +03:00
|
|
|
],
|
|
|
|
|
)
|
2023-06-09 00:33:41 +02:00
|
|
|
async def test_pre_configured_admin_login(username, password, expect_successful_login):
|
2019-07-16 20:18:45 +03:00
|
|
|
"""
|
2023-06-09 00:33:41 +02:00
|
|
|
Verify that the "--admin <username>:<password>" flag allows that user/pass
|
|
|
|
|
combination and no other user can login.
|
2019-07-16 20:18:45 +03:00
|
|
|
"""
|
2023-06-09 02:00:30 +02:00
|
|
|
async with User(username, HUB_URL, partial(login_dummy, password=password)) as u:
|
2020-07-21 16:58:54 +03:00
|
|
|
user_logged_in = await u.login()
|
|
|
|
|
|
2023-06-09 00:33:41 +02:00
|
|
|
assert user_logged_in == expect_successful_login
|