more fixes

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-02-24 14:27:11 +01:00
parent 3ec477d58d
commit 905ae00e02
No known key found for this signature in database
6 changed files with 11 additions and 3 deletions

View File

@ -297,6 +297,7 @@ class FlowViewSet(UsedByMixin, ModelViewSet):
{ {
"link": request._request.build_absolute_uri( "link": request._request.build_absolute_uri(
reverse_interface( reverse_interface(
request,
InterfaceType.FLOW, InterfaceType.FLOW,
flow_slug=flow.slug, flow_slug=flow.slug,
), ),

View File

@ -7,12 +7,12 @@ from django.http import Http404, HttpRequest, HttpResponse, QueryDict
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.template import Template, TemplateSyntaxError, engines from django.template import Template, TemplateSyntaxError, engines
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View from django.views import View
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.csrf import ensure_csrf_cookie
from rest_framework.request import Request from rest_framework.request import Request
from structlog.stdlib import get_logger
from authentik import get_build_hash from authentik import get_build_hash
from authentik.admin.tasks import LOCAL_VERSION from authentik.admin.tasks import LOCAL_VERSION
@ -23,6 +23,8 @@ from authentik.lib.utils.urls import reverse_with_qs
from authentik.tenants.api import CurrentTenantSerializer from authentik.tenants.api import CurrentTenantSerializer
from authentik.tenants.models import Tenant from authentik.tenants.models import Tenant
LOGGER = get_logger()
def template_from_string(template_string: str) -> Template: def template_from_string(template_string: str) -> Template:
"""Render template from string""" """Render template from string"""
@ -57,6 +59,7 @@ def reverse_interface(
interface = tenant.interface_flow interface = tenant.interface_flow
if not interface: if not interface:
LOGGER.warning("No interface found", type=interface_type, tenant=tenant)
raise Http404() raise Http404()
kwargs["if_name"] = interface.url_name kwargs["if_name"] = interface.url_name
return reverse_with_qs( return reverse_with_qs(

View File

@ -3,7 +3,6 @@ from datetime import timedelta
from django.contrib import messages from django.contrib import messages
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.urls import reverse
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.timezone import now from django.utils.timezone import now

View File

@ -7,6 +7,7 @@ from django.core.mail.backends.locmem import EmailBackend
from django.urls import reverse from django.urls import reverse
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from authentik.blueprints.tests import apply_blueprint
from authentik.core.tests.utils import create_test_admin_user, create_test_flow from authentik.core.tests.utils import create_test_admin_user, create_test_flow
from authentik.events.models import Event, EventAction from authentik.events.models import Event, EventAction
from authentik.flows.markers import StageMarker from authentik.flows.markers import StageMarker
@ -29,6 +30,7 @@ class TestEmailStageSending(APITestCase):
) )
self.binding = FlowStageBinding.objects.create(target=self.flow, stage=self.stage, order=2) self.binding = FlowStageBinding.objects.create(target=self.flow, stage=self.stage, order=2)
@apply_blueprint("system/interfaces.yaml")
def test_pending_user(self): def test_pending_user(self):
"""Test with pending user""" """Test with pending user"""
plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()]) plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()])
@ -54,6 +56,7 @@ class TestEmailStageSending(APITestCase):
self.assertEqual(event.context["to_email"], [self.user.email]) self.assertEqual(event.context["to_email"], [self.user.email])
self.assertEqual(event.context["from_email"], "system@authentik.local") self.assertEqual(event.context["from_email"], "system@authentik.local")
@apply_blueprint("system/interfaces.yaml")
def test_send_error(self): def test_send_error(self):
"""Test error during sending (sending will be retried)""" """Test error during sending (sending will be retried)"""
plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()]) plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()])

View File

@ -7,6 +7,7 @@ from django.core.mail.backends.smtp import EmailBackend as SMTPEmailBackend
from django.urls import reverse from django.urls import reverse
from django.utils.http import urlencode from django.utils.http import urlencode
from authentik.blueprints.tests import apply_blueprint
from authentik.core.tests.utils import create_test_admin_user, create_test_flow from authentik.core.tests.utils import create_test_admin_user, create_test_flow
from authentik.flows.markers import StageMarker from authentik.flows.markers import StageMarker
from authentik.flows.models import FlowDesignation, FlowStageBinding, FlowToken from authentik.flows.models import FlowDesignation, FlowStageBinding, FlowToken
@ -74,6 +75,7 @@ class TestEmailStage(FlowTestCase):
response = self.client.get(url) response = self.client.get(url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@apply_blueprint("system/interfaces.yaml")
@patch( @patch(
"authentik.stages.email.models.EmailStage.backend_class", "authentik.stages.email.models.EmailStage.backend_class",
PropertyMock(return_value=EmailBackend), PropertyMock(return_value=EmailBackend),
@ -123,6 +125,7 @@ class TestEmailStage(FlowTestCase):
with self.settings(EMAIL_HOST=host): with self.settings(EMAIL_HOST=host):
self.assertEqual(EmailStage(use_global_settings=True).backend.host, host) self.assertEqual(EmailStage(use_global_settings=True).backend.host, host)
@apply_blueprint("system/interfaces.yaml")
def test_token(self): def test_token(self):
"""Test with token""" """Test with token"""
# Make sure token exists # Make sure token exists

View File

@ -29,7 +29,6 @@ from authentik.flows.views.executor import SESSION_KEY_APPLICATION_PRE, SESSION_
from authentik.interfaces.models import InterfaceType from authentik.interfaces.models import InterfaceType
from authentik.interfaces.views import reverse_interface from authentik.interfaces.views import reverse_interface
from authentik.lib.utils.http import get_client_ip from authentik.lib.utils.http import get_client_ip
from authentik.lib.utils.urls import reverse_with_qs
from authentik.sources.oauth.types.apple import AppleLoginChallenge from authentik.sources.oauth.types.apple import AppleLoginChallenge
from authentik.sources.plex.models import PlexAuthenticationChallenge from authentik.sources.plex.models import PlexAuthenticationChallenge
from authentik.stages.identification.models import IdentificationStage from authentik.stages.identification.models import IdentificationStage