blueprints: use relative path in @apply_blueprint

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-08-16 14:20:45 +02:00
parent 71d6304407
commit e9c1276634
14 changed files with 22 additions and 18 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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())

View File

@ -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()

View File

@ -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()

View File

@ -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())

View File

@ -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(

View File

@ -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(

View File

@ -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",

View File

@ -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",

View File

@ -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")

View File

@ -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",

View File

@ -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)

View File

@ -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)