2023-05-13 22:58:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from tentacles.store import Store
|
|
|
|
|
|
|
|
|
2023-06-03 19:20:05 +00:00
|
|
|
def test_mkuser(store: Store, username_testy, password_testy):
|
|
|
|
res = store.try_create_user(
|
|
|
|
username=username_testy, email=username_testy, password=password_testy
|
|
|
|
)
|
|
|
|
assert res
|
|
|
|
assert store.list_users() == [(res.id, username_testy)]
|
2023-05-13 22:58:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_mksession(store: Store, uid_testy, username_testy, password_testy, login_ttl):
|
2023-06-03 19:20:05 +00:00
|
|
|
res = store.try_login(
|
|
|
|
username=username_testy, password=password_testy, ttl=login_ttl
|
|
|
|
)
|
|
|
|
assert res is not None
|
|
|
|
assert [it.id for it in store.list_keys(uid=uid_testy)] == [res.id]
|
|
|
|
assert store.try_key(kid=res.id).user_id == uid_testy
|
2023-05-13 22:58:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_refresh_key(store: Store, sid_testy, login_ttl):
|
2023-06-03 19:20:05 +00:00
|
|
|
before = store.fetch_key(kid=sid_testy)
|
|
|
|
store.refresh_key(kid=sid_testy, ttl=login_ttl * 2)
|
|
|
|
after = store.fetch_key(kid=sid_testy)
|
2023-05-13 22:58:17 +00:00
|
|
|
assert before != after
|
|
|
|
|
|
|
|
|
|
|
|
def tets_mkkey(store: Store, sid_testy, uid_testy):
|
2023-06-03 19:20:05 +00:00
|
|
|
assert store.try_key(kid=sid_testy) == uid_testy
|
|
|
|
new_key = store.create_key(kid=sid_testy, ttl=None)
|
2023-05-13 22:58:17 +00:00
|
|
|
assert new_key is not None
|
2023-06-03 19:20:05 +00:00
|
|
|
assert store.try_key(kid=new_key) == uid_testy
|
2023-05-13 22:58:17 +00:00
|
|
|
|
|
|
|
|
2023-06-03 19:20:05 +00:00
|
|
|
def test_logout(store: Store, uid_testy, sid_testy):
|
|
|
|
assert store.try_key(kid=sid_testy)
|
|
|
|
store.delete_key(uid=uid_testy, kid=sid_testy)
|
|
|
|
assert not store.try_key(kid=sid_testy)
|