From 2ec979d490b044285989d569cf387f3ec989d741 Mon Sep 17 00:00:00 2001 From: Jens L Date: Mon, 18 Dec 2023 23:00:24 +0100 Subject: [PATCH] root: make test database name configurable (#7591) * test Signed-off-by: Jens Langhammer * idk attempt to fix flaky test Signed-off-by: Jens Langhammer * oops Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- .github/workflows/ci-main.yml | 6 ++++++ authentik/api/tests/test_auth.py | 8 +++++++- authentik/lib/default.yml | 2 ++ authentik/root/settings.py | 3 +++ go.mod | 2 -- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-main.yml b/.github/workflows/ci-main.yml index 8d0e8bc79..282543d96 100644 --- a/.github/workflows/ci-main.yml +++ b/.github/workflows/ci-main.yml @@ -94,6 +94,12 @@ jobs: - name: migrate to latest run: | poetry run python -m lifecycle.migrate + - name: run tests + env: + # Test in the main database that we just migrated from the previous stable version + AUTHENTIK_POSTGRESQL__TEST__NAME: authentik + run: | + poetry run make test test-unittest: name: test-unittest - PostgreSQL ${{ matrix.psql }} runs-on: ubuntu-latest diff --git a/authentik/api/tests/test_auth.py b/authentik/api/tests/test_auth.py index cd23a1835..c09bca5a3 100644 --- a/authentik/api/tests/test_auth.py +++ b/authentik/api/tests/test_auth.py @@ -12,6 +12,8 @@ from authentik.blueprints.tests import reconcile_app from authentik.core.models import Token, TokenIntents, User, UserTypes from authentik.core.tests.utils import create_test_admin_user, create_test_flow from authentik.lib.generators import generate_id +from authentik.outposts.apps import MANAGED_OUTPOST +from authentik.outposts.models import Outpost from authentik.providers.oauth2.constants import SCOPE_AUTHENTIK_API from authentik.providers.oauth2.models import AccessToken, OAuth2Provider @@ -49,8 +51,12 @@ class TestAPIAuth(TestCase): with self.assertRaises(AuthenticationFailed): bearer_auth(f"Bearer {token.key}".encode()) - def test_managed_outpost(self): + @reconcile_app("authentik_outposts") + def test_managed_outpost_fail(self): """Test managed outpost""" + outpost = Outpost.objects.filter(managed=MANAGED_OUTPOST).first() + outpost.user.delete() + outpost.delete() with self.assertRaises(AuthenticationFailed): bearer_auth(f"Bearer {settings.SECRET_KEY}".encode()) diff --git a/authentik/lib/default.yml b/authentik/lib/default.yml index 83bd3c7c9..7573888ae 100644 --- a/authentik/lib/default.yml +++ b/authentik/lib/default.yml @@ -8,6 +8,8 @@ postgresql: password: "env://POSTGRES_PASSWORD" use_pgbouncer: false use_pgpool: false + test: + name: test_authentik listen: listen_http: 0.0.0.0:9000 diff --git a/authentik/root/settings.py b/authentik/root/settings.py index df144431f..08959c127 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -278,6 +278,9 @@ DATABASES = { "SSLROOTCERT": CONFIG.get("postgresql.sslrootcert"), "SSLCERT": CONFIG.get("postgresql.sslcert"), "SSLKEY": CONFIG.get("postgresql.sslkey"), + "TEST": { + "NAME": CONFIG.get("postgresql.test.name"), + }, } } diff --git a/go.mod b/go.mod index d36876837..c295495c8 100644 --- a/go.mod +++ b/go.mod @@ -82,5 +82,3 @@ require ( gopkg.in/square/go-jose.v2 v2.5.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace goauthentik.io/api/v3 => ./gen-go-api