2022-03-04 18:51:33 +01:00
|
|
|
import email
|
2022-03-06 15:29:00 +01:00
|
|
|
import logging
|
2022-04-29 14:56:51 +02:00
|
|
|
|
|
|
|
from app.authentik.settings import AuthentikSettings
|
2022-03-06 15:29:00 +01:00
|
|
|
from .api import Authentik
|
2022-03-06 12:31:12 +01:00
|
|
|
from .models import User
|
|
|
|
import pytest
|
2022-03-04 18:51:33 +01:00
|
|
|
|
2022-04-29 14:56:51 +02:00
|
|
|
@pytest.fixture()
|
|
|
|
def settings() -> AuthentikSettings:
|
|
|
|
return AuthentikSettings(
|
|
|
|
baseurl="http://localhost:9000/", token="foobar123",)
|
2022-03-04 18:51:33 +01:00
|
|
|
|
2022-03-06 12:31:12 +01:00
|
|
|
@pytest.fixture
|
2022-04-29 14:56:51 +02:00
|
|
|
def api(settings: AuthentikSettings) -> Authentik:
|
|
|
|
return Authentik(settings)
|
2022-03-06 12:31:12 +01:00
|
|
|
|
2022-04-29 14:13:54 +02:00
|
|
|
|
|
|
|
def test_create_event_transport_already_exists(api: Authentik):
|
|
|
|
exception = None
|
|
|
|
try:
|
|
|
|
api.create_event_transport("/","asd")
|
|
|
|
except Exception as e:
|
|
|
|
exception = e
|
|
|
|
assert not exception == None # TODO create exception types
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_event_rule_already_exists(api: Authentik):
|
|
|
|
exception = None
|
|
|
|
try:
|
|
|
|
api.create_event_rule({"pk" : "asd"},"webhook")
|
|
|
|
except Exception as e:
|
|
|
|
exception = e
|
|
|
|
assert not exception == None # TODO create exception types
|
|
|
|
|
2022-03-06 12:31:12 +01:00
|
|
|
def test_get_user_by_username(api: Authentik):
|
|
|
|
u = User(username="akadmin",
|
|
|
|
name="",
|
|
|
|
groups=[],
|
|
|
|
email="",
|
|
|
|
is_active=True,
|
|
|
|
attributes={}
|
|
|
|
)
|
2022-04-23 18:49:28 +02:00
|
|
|
u = api.get_user(u)
|
2022-03-06 12:31:12 +01:00
|
|
|
assert not u == None
|
|
|
|
assert u.username == "akadmin"
|
2022-03-04 18:51:33 +01:00
|
|
|
|
2022-03-06 12:31:12 +01:00
|
|
|
|
|
|
|
def test_create_user(api: Authentik):
|
2022-03-04 18:51:33 +01:00
|
|
|
u = User(username="banane",
|
|
|
|
name="banane",
|
|
|
|
groups=[],
|
|
|
|
email="foo@example.org",
|
|
|
|
is_active=True,
|
|
|
|
attributes={}
|
2022-03-06 12:31:12 +01:00
|
|
|
)
|
|
|
|
if(api.get_user(u)):
|
|
|
|
api.delete_user(api.get_user(u))
|
|
|
|
|
|
|
|
assert api.get_user(u) == None
|
|
|
|
|
|
|
|
c = api.create_user(u)
|
2022-03-04 18:51:33 +01:00
|
|
|
assert u.username == c.username
|
|
|
|
assert not c.pk == None
|
2022-04-29 14:13:54 +02:00
|
|
|
|
|
|
|
assert api.delete_user(c) == True
|