* remove tenants * remove unused ignore * add missing migration * merge migrations * remove probably-unneeded redirect * fix docs link * fix e2e tests * fixup! fix e2e tests * change `base_url` to `TextField` * abstract `schema_name` * keep database fields required for rolling upgrade These should be deleted in a subsequent cleanup patch. * introduce system settings cache This is a bit more complicated than other middleware context var caches, because invalidation is sometimes needed. * cleanup * fixup! change `base_url` to `TextField` * fix tests Whoops
57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
"""authentik e2e testing utilities"""
|
|
|
|
from datetime import timedelta
|
|
from time import mktime
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from daphne.testing import DaphneProcess
|
|
from django import setup as django_setup
|
|
from django.conf import settings
|
|
from django.core.signals import request_started
|
|
from django.utils.timezone import now
|
|
|
|
from authentik.lib.config import CONFIG
|
|
from authentik.lib.generators import generate_id
|
|
|
|
|
|
class TestDatabaseProcess(DaphneProcess):
|
|
"""Channels does not correctly switch to the test database by default.
|
|
https://github.com/django/channels/issues/2048"""
|
|
|
|
def _clear_ct_cache(self, **_):
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
ContentType.objects.clear_cache()
|
|
|
|
def run(self):
|
|
if not settings.configured: # Fix For raise AppRegistryNotReady("Apps aren't loaded yet.")
|
|
django_setup() # Ensure Django is fully set up before using settings
|
|
if not settings.DATABASES[list(settings.DATABASES.keys())[0]]["NAME"].startswith("test_"):
|
|
for _, db_settings in settings.DATABASES.items():
|
|
db_settings["NAME"] = f"test_{db_settings['NAME']}"
|
|
settings.TEST = True
|
|
|
|
# In e2e tests, make sure subprocesses can't have stale caches
|
|
request_started.connect(self._clear_ct_cache, weak=False)
|
|
|
|
from authentik.enterprise.license import LicenseKey
|
|
from authentik.root.test_runner import patched__get_ct_cached
|
|
|
|
with (
|
|
patch(
|
|
"authentik.enterprise.license.LicenseKey.validate",
|
|
MagicMock(
|
|
return_value=LicenseKey(
|
|
aud="",
|
|
exp=int(mktime((now() + timedelta(days=3000)).timetuple())),
|
|
name=generate_id(),
|
|
internal_users=100,
|
|
external_users=100,
|
|
)
|
|
),
|
|
),
|
|
CONFIG.patch("email.port", 1025),
|
|
patch("guardian.shortcuts._get_ct_cached", patched__get_ct_cached),
|
|
):
|
|
return super().run()
|