From e9c12766344d4f991dd4c37c6905e92cc33694c8 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 16 Aug 2022 14:20:45 +0200 Subject: [PATCH] blueprints: use relative path in @apply_blueprint Signed-off-by: Jens Langhammer --- Dockerfile | 4 ++-- authentik/blueprints/tests/__init__.py | 6 +++++- authentik/blueprints/tests/test_bundled.py | 2 +- authentik/providers/oauth2/tests/test_token_cc.py | 2 +- .../providers/oauth2/tests/test_token_cc_jwt_source.py | 2 +- authentik/providers/oauth2/tests/test_userinfo.py | 2 +- authentik/providers/saml/tests/test_auth_n_request.py | 2 +- authentik/providers/saml/tests/test_schema.py | 2 +- authentik/sources/ldap/tests/test_auth.py | 2 +- authentik/sources/ldap/tests/test_sync.py | 2 +- tests/e2e/test_flows_authenticators.py | 4 ++-- tests/e2e/test_flows_stage_setup.py | 2 +- tests/e2e/test_provider_oauth2_oidc.py | 4 ++-- tests/e2e/test_provider_oauth2_oidc_implicit.py | 4 ++-- 14 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index ac0af7d9f..4553627c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ RUN pip install --no-cache-dir poetry && \ poetry export -f requirements.txt --dev --output requirements-dev.txt # Stage 4: Build go proxy -FROM docker.io/golang:1.19.0-bullseye AS builder +FROM docker.io/golang:1.19.0-bullseye AS go-builder WORKDIR /work @@ -46,7 +46,7 @@ COPY ./go.sum /work/go.sum RUN go build -o /work/authentik ./cmd/server/main.go # Stage 5: Run -FROM docker.io/python:3.10.6-slim-bullseye +FROM docker.io/python:3.10.6-slim-bullseye AS final-image LABEL org.opencontainers.image.url https://goauthentik.io LABEL org.opencontainers.image.description goauthentik.io Main server image, see https://goauthentik.io for more info. diff --git a/authentik/blueprints/tests/__init__.py b/authentik/blueprints/tests/__init__.py index 29bd87294..9d83d7703 100644 --- a/authentik/blueprints/tests/__init__.py +++ b/authentik/blueprints/tests/__init__.py @@ -1,10 +1,12 @@ """Blueprint helpers""" from functools import wraps +from pathlib import Path from typing import Callable from django.apps import apps from authentik.blueprints.manager import ManagedAppConfig +from authentik.lib.config import CONFIG def apply_blueprint(*files: str): @@ -17,8 +19,10 @@ def apply_blueprint(*files: str): @wraps(func) def wrapper(*args, **kwargs): + base_path = Path(CONFIG.y("blueprints_dir")) for file in files: - with open(file, "r+", encoding="utf-8") as _file: + full_path = Path(base_path, file) + with full_path.open("r", encoding="utf-8") as _file: Importer(_file.read()).apply() return func(*args, **kwargs) diff --git a/authentik/blueprints/tests/test_bundled.py b/authentik/blueprints/tests/test_bundled.py index 21e7e9eaa..64c0f346e 100644 --- a/authentik/blueprints/tests/test_bundled.py +++ b/authentik/blueprints/tests/test_bundled.py @@ -14,7 +14,7 @@ from authentik.tenants.models import Tenant class TestBundled(TransactionTestCase): """Empty class, test methods are added dynamically""" - @apply_blueprint("blueprints/default/90-default-tenant.yaml") + @apply_blueprint("default/90-default-tenant.yaml") def test_decorator_static(self): """Test @apply_blueprint decorator""" self.assertTrue(Tenant.objects.filter(domain="authentik-default").exists()) diff --git a/authentik/providers/oauth2/tests/test_token_cc.py b/authentik/providers/oauth2/tests/test_token_cc.py index 97b191cfd..fc7f00d04 100644 --- a/authentik/providers/oauth2/tests/test_token_cc.py +++ b/authentik/providers/oauth2/tests/test_token_cc.py @@ -24,7 +24,7 @@ from authentik.providers.oauth2.tests.utils import OAuthTestCase class TestTokenClientCredentials(OAuthTestCase): """Test token (client_credentials) view""" - @apply_blueprint("blueprints/system/providers-oauth2.yaml") + @apply_blueprint("system/providers-oauth2.yaml") def setUp(self) -> None: super().setUp() self.factory = RequestFactory() diff --git a/authentik/providers/oauth2/tests/test_token_cc_jwt_source.py b/authentik/providers/oauth2/tests/test_token_cc_jwt_source.py index 77e511a9f..7890bcfdb 100644 --- a/authentik/providers/oauth2/tests/test_token_cc_jwt_source.py +++ b/authentik/providers/oauth2/tests/test_token_cc_jwt_source.py @@ -26,7 +26,7 @@ from authentik.sources.oauth.models import OAuthSource class TestTokenClientCredentialsJWTSource(OAuthTestCase): """Test token (client_credentials, with JWT) view""" - @apply_blueprint("blueprints/system/providers-oauth2.yaml") + @apply_blueprint("system/providers-oauth2.yaml") def setUp(self) -> None: super().setUp() self.factory = RequestFactory() diff --git a/authentik/providers/oauth2/tests/test_userinfo.py b/authentik/providers/oauth2/tests/test_userinfo.py index c0342a4d7..007db5c40 100644 --- a/authentik/providers/oauth2/tests/test_userinfo.py +++ b/authentik/providers/oauth2/tests/test_userinfo.py @@ -16,7 +16,7 @@ from authentik.providers.oauth2.tests.utils import OAuthTestCase class TestUserinfo(OAuthTestCase): """Test token view""" - @apply_blueprint("blueprints/system/providers-oauth2.yaml") + @apply_blueprint("system/providers-oauth2.yaml") def setUp(self) -> None: super().setUp() self.app = Application.objects.create(name=generate_id(), slug=generate_id()) diff --git a/authentik/providers/saml/tests/test_auth_n_request.py b/authentik/providers/saml/tests/test_auth_n_request.py index 5e682994e..6fb58169a 100644 --- a/authentik/providers/saml/tests/test_auth_n_request.py +++ b/authentik/providers/saml/tests/test_auth_n_request.py @@ -74,7 +74,7 @@ qNAZMq1DqpibfCBg class TestAuthNRequest(TestCase): """Test AuthN Request generator and parser""" - @apply_blueprint("blueprints/system/providers-saml.yaml") + @apply_blueprint("system/providers-saml.yaml") def setUp(self): cert = create_test_cert() self.provider: SAMLProvider = SAMLProvider.objects.create( diff --git a/authentik/providers/saml/tests/test_schema.py b/authentik/providers/saml/tests/test_schema.py index 49463588f..4b7110be7 100644 --- a/authentik/providers/saml/tests/test_schema.py +++ b/authentik/providers/saml/tests/test_schema.py @@ -18,7 +18,7 @@ from authentik.sources.saml.processors.request import RequestProcessor class TestSchema(TestCase): """Test Requests and Responses against schema""" - @apply_blueprint("blueprints/system/providers-saml.yaml") + @apply_blueprint("system/providers-saml.yaml") def setUp(self): cert = create_test_cert() self.provider: SAMLProvider = SAMLProvider.objects.create( diff --git a/authentik/sources/ldap/tests/test_auth.py b/authentik/sources/ldap/tests/test_auth.py index 51ab96cd6..396c78468 100644 --- a/authentik/sources/ldap/tests/test_auth.py +++ b/authentik/sources/ldap/tests/test_auth.py @@ -19,7 +19,7 @@ LDAP_PASSWORD = generate_key() class LDAPSyncTests(TestCase): """LDAP Sync tests""" - @apply_blueprint("blueprints/system/sources-ldap.yaml") + @apply_blueprint("system/sources-ldap.yaml") def setUp(self): self.source = LDAPSource.objects.create( name="ldap", diff --git a/authentik/sources/ldap/tests/test_sync.py b/authentik/sources/ldap/tests/test_sync.py index f44e776a4..f190a4437 100644 --- a/authentik/sources/ldap/tests/test_sync.py +++ b/authentik/sources/ldap/tests/test_sync.py @@ -23,7 +23,7 @@ LDAP_PASSWORD = generate_key() class LDAPSyncTests(TestCase): """LDAP Sync tests""" - @apply_blueprint("blueprints/system/sources-ldap.yaml") + @apply_blueprint("system/sources-ldap.yaml") def setUp(self): self.source: LDAPSource = LDAPSource.objects.create( name="ldap", diff --git a/tests/e2e/test_flows_authenticators.py b/tests/e2e/test_flows_authenticators.py index 4ef14a3a1..2da6d5e2f 100644 --- a/tests/e2e/test_flows_authenticators.py +++ b/tests/e2e/test_flows_authenticators.py @@ -55,7 +55,7 @@ class TestFlowsAuthenticator(SeleniumTestCase): "blueprints/default/10-flow-default-authentication-flow.yaml", "blueprints/default/10-flow-default-invalidation-flow.yaml", ) - @apply_blueprint("blueprints/default/20-flow-default-authenticator-totp-setup.yaml") + @apply_blueprint("default/20-flow-default-authenticator-totp-setup.yaml") def test_totp_setup(self): """test TOTP Setup stage""" flow: Flow = Flow.objects.get(slug="default-authentication-flow") @@ -101,7 +101,7 @@ class TestFlowsAuthenticator(SeleniumTestCase): "blueprints/default/10-flow-default-authentication-flow.yaml", "blueprints/default/10-flow-default-invalidation-flow.yaml", ) - @apply_blueprint("blueprints/default/20-flow-default-authenticator-static-setup.yaml") + @apply_blueprint("default/20-flow-default-authenticator-static-setup.yaml") def test_static_setup(self): """test Static OTP Setup stage""" flow: Flow = Flow.objects.get(slug="default-authentication-flow") diff --git a/tests/e2e/test_flows_stage_setup.py b/tests/e2e/test_flows_stage_setup.py index 8672b837d..e2ffb8164 100644 --- a/tests/e2e/test_flows_stage_setup.py +++ b/tests/e2e/test_flows_stage_setup.py @@ -18,7 +18,7 @@ class TestFlowsStageSetup(SeleniumTestCase): """test stage setup flows""" @retry() - @apply_blueprint("blueprints/default/0-flow-password-change.yaml") + @apply_blueprint("default/0-flow-password-change.yaml") @apply_blueprint( "blueprints/default/10-flow-default-authentication-flow.yaml", "blueprints/default/10-flow-default-invalidation-flow.yaml", diff --git a/tests/e2e/test_provider_oauth2_oidc.py b/tests/e2e/test_provider_oauth2_oidc.py index f54f4e74f..e7f0785c7 100644 --- a/tests/e2e/test_provider_oauth2_oidc.py +++ b/tests/e2e/test_provider_oauth2_oidc.py @@ -120,7 +120,7 @@ class TestProviderOAuth2OIDC(SeleniumTestCase): "blueprints/default/20-flow-default-provider-authorization-implicit-consent.yaml", ) @reconcile_app("authentik_crypto") - @apply_blueprint("blueprints/system/providers-oauth2.yaml") + @apply_blueprint("system/providers-oauth2.yaml") def test_authorization_consent_implied(self): """test OpenID Provider flow (default authorization flow with implied consent)""" sleep(1) @@ -175,7 +175,7 @@ class TestProviderOAuth2OIDC(SeleniumTestCase): "blueprints/default/20-flow-default-provider-authorization-implicit-consent.yaml", ) @reconcile_app("authentik_crypto") - @apply_blueprint("blueprints/system/providers-oauth2.yaml") + @apply_blueprint("system/providers-oauth2.yaml") def test_authorization_consent_explicit(self): """test OpenID Provider flow (default authorization flow with explicit consent)""" sleep(1) diff --git a/tests/e2e/test_provider_oauth2_oidc_implicit.py b/tests/e2e/test_provider_oauth2_oidc_implicit.py index 8aa0252bf..123f4047e 100644 --- a/tests/e2e/test_provider_oauth2_oidc_implicit.py +++ b/tests/e2e/test_provider_oauth2_oidc_implicit.py @@ -120,7 +120,7 @@ class TestProviderOAuth2OIDCImplicit(SeleniumTestCase): "blueprints/default/20-flow-default-provider-authorization-implicit-consent.yaml", ) @reconcile_app("authentik_crypto") - @apply_blueprint("blueprints/system/providers-oauth2.yaml") + @apply_blueprint("system/providers-oauth2.yaml") def test_authorization_consent_implied(self): """test OpenID Provider flow (default authorization flow with implied consent)""" sleep(1) @@ -170,7 +170,7 @@ class TestProviderOAuth2OIDCImplicit(SeleniumTestCase): "blueprints/default/20-flow-default-provider-authorization-implicit-consent.yaml", ) @reconcile_app("authentik_crypto") - @apply_blueprint("blueprints/system/providers-oauth2.yaml") + @apply_blueprint("system/providers-oauth2.yaml") def test_authorization_consent_explicit(self): """test OpenID Provider flow (default authorization flow with explicit consent)""" sleep(1)