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-06 16:53:16 +02:00
|
|
|
hub_url = "http://localhost"
|
|
|
|
|
|
2019-07-16 20:18:45 +03:00
|
|
|
|
|
|
|
|
async def test_admin_login():
|
|
|
|
|
"""
|
|
|
|
|
Test if the admin that was added during install can login with
|
|
|
|
|
the password provided.
|
|
|
|
|
"""
|
|
|
|
|
username = "admin"
|
|
|
|
|
password = "admin"
|
|
|
|
|
|
|
|
|
|
async with User(username, hub_url, partial(login_dummy, password=password)) as u:
|
2020-07-21 16:58:54 +03:00
|
|
|
await u.login()
|
|
|
|
|
# If user is not logged in, this will raise an exception
|
2023-06-07 01:35:34 +02:00
|
|
|
await u.ensure_server_simulate(timeout=60, spawn_refresh_time=5)
|
2019-07-16 20:18:45 +03:00
|
|
|
|
2021-11-01 09:42:45 +01:00
|
|
|
|
2019-07-16 20:18:45 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"username, password",
|
|
|
|
|
[
|
|
|
|
|
("admin", ""),
|
|
|
|
|
("admin", "wrong_passw"),
|
|
|
|
|
("user", "password"),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
async def test_unsuccessful_login(username, password):
|
|
|
|
|
"""
|
|
|
|
|
Ensure nobody but the admin that was added during install can login
|
|
|
|
|
"""
|
2020-07-21 16:58:54 +03:00
|
|
|
async with User(username, hub_url, partial(login_dummy, password="")) as u:
|
|
|
|
|
user_logged_in = await u.login()
|
|
|
|
|
|
|
|
|
|
assert user_logged_in == False
|