From bdb86d7119d950bbd055fe9bcb082ade2cb674da Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 20 Feb 2021 18:58:50 +0100 Subject: [PATCH] *: replace shortcuts.reverse with urls.reverse --- authentik/admin/tests/test_api.py | 2 +- authentik/admin/tests/test_generated.py | 2 +- authentik/admin/views/certificate_key_pair.py | 9 +++++---- authentik/admin/views/flows.py | 9 +++++---- authentik/admin/views/groups.py | 7 ++++--- .../admin/views/outposts_service_connections.py | 7 ++++--- authentik/admin/views/policies.py | 7 ++++--- authentik/admin/views/policies_bindings.py | 7 ++++--- authentik/admin/views/stages.py | 7 ++++--- authentik/admin/views/stages_bindings.py | 7 ++++--- authentik/admin/views/stages_invitations.py | 5 +++-- authentik/admin/views/stages_prompts.py | 7 ++++--- authentik/admin/views/tokens.py | 3 ++- authentik/admin/views/users.py | 15 ++++++++------- authentik/admin/views/utils.py | 3 ++- authentik/core/api/propertymappings.py | 2 +- authentik/core/api/providers.py | 2 +- authentik/core/api/sources.py | 2 +- authentik/core/tests/test_impersonation.py | 2 +- authentik/core/tests/test_views_overview.py | 2 +- authentik/core/tests/test_views_user.py | 2 +- authentik/events/tests/test_api.py | 2 +- authentik/events/tests/test_middleware.py | 2 +- authentik/flows/api/stages.py | 2 +- authentik/flows/challenge.py | 17 +++++++++++------ authentik/flows/tests/test_api.py | 2 +- authentik/flows/tests/test_planner.py | 2 +- authentik/flows/tests/test_views.py | 4 ++-- authentik/flows/tests/test_views_helper.py | 2 +- .../outposts/api/outpost_service_connections.py | 2 +- authentik/policies/api.py | 2 +- authentik/providers/oauth2/api.py | 2 +- authentik/providers/saml/processors/metadata.py | 2 +- authentik/recovery/tests.py | 2 +- authentik/root/tests.py | 2 +- authentik/sources/oauth/models.py | 2 +- authentik/sources/oauth/tests/test_views.py | 2 +- authentik/sources/saml/models.py | 3 +-- authentik/stages/authenticator_static/models.py | 2 +- authentik/stages/authenticator_totp/models.py | 2 +- .../stages/authenticator_webauthn/models.py | 2 +- authentik/stages/captcha/tests.py | 2 +- authentik/stages/consent/tests.py | 2 +- authentik/stages/dummy/tests.py | 2 +- authentik/stages/email/tests/test_sending.py | 2 +- authentik/stages/email/tests/test_stage.py | 2 +- authentik/stages/identification/stage.py | 11 ++++++----- authentik/stages/identification/tests.py | 2 +- authentik/stages/invitation/tests.py | 2 +- authentik/stages/password/models.py | 2 +- authentik/stages/password/tests.py | 2 +- authentik/stages/password/views.py | 2 +- authentik/stages/prompt/tests.py | 2 +- authentik/stages/user_delete/tests.py | 2 +- authentik/stages/user_login/tests.py | 2 +- authentik/stages/user_logout/tests.py | 2 +- authentik/stages/user_write/tests.py | 2 +- tests/e2e/utils.py | 2 +- 58 files changed, 114 insertions(+), 96 deletions(-) diff --git a/authentik/admin/tests/test_api.py b/authentik/admin/tests/test_api.py index 5b4d66933..870c45c11 100644 --- a/authentik/admin/tests/test_api.py +++ b/authentik/admin/tests/test_api.py @@ -1,8 +1,8 @@ """test admin api""" from json import loads -from django.shortcuts import reverse from django.test import TestCase +from django.urls import reverse from authentik import __version__ from authentik.core.models import Group, User diff --git a/authentik/admin/tests/test_generated.py b/authentik/admin/tests/test_generated.py index 5f9399a07..af63fe1ed 100644 --- a/authentik/admin/tests/test_generated.py +++ b/authentik/admin/tests/test_generated.py @@ -3,8 +3,8 @@ from importlib import import_module from typing import Callable from django.forms import ModelForm -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.urls.exceptions import NoReverseMatch from authentik.admin.urls import urlpatterns diff --git a/authentik/admin/views/certificate_key_pair.py b/authentik/admin/views/certificate_key_pair.py index 1e2ea400a..046abd802 100644 --- a/authentik/admin/views/certificate_key_pair.py +++ b/authentik/admin/views/certificate_key_pair.py @@ -5,6 +5,7 @@ from django.contrib.auth.mixins import ( ) from django.contrib.messages.views import SuccessMessageMixin from django.http.response import HttpResponse +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import UpdateView from django.views.generic.edit import FormView @@ -33,7 +34,7 @@ class CertificateKeyPairCreateView( permission_required = "authentik_crypto.add_certificatekeypair" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Certificate-Key Pair") @@ -50,7 +51,7 @@ class CertificateKeyPairGenerateView( permission_required = "authentik_crypto.add_certificatekeypair" template_name = "administration/certificatekeypair/generate.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully generated Certificate-Key Pair") def form_valid(self, form: CertificateKeyPairGenerateForm) -> HttpResponse: @@ -77,7 +78,7 @@ class CertificateKeyPairUpdateView( permission_required = "authentik_crypto.change_certificatekeypair" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated Certificate-Key Pair") @@ -90,5 +91,5 @@ class CertificateKeyPairDeleteView( permission_required = "authentik_crypto.delete_certificatekeypair" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Certificate-Key Pair") diff --git a/authentik/admin/views/flows.py b/authentik/admin/views/flows.py index 9cfa6ffd2..25855db33 100644 --- a/authentik/admin/views/flows.py +++ b/authentik/admin/views/flows.py @@ -6,6 +6,7 @@ from django.contrib.auth.mixins import ( ) from django.contrib.messages.views import SuccessMessageMixin from django.http import HttpRequest, HttpResponse, JsonResponse +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import DetailView, FormView, UpdateView from guardian.mixins import PermissionRequiredMixin @@ -36,7 +37,7 @@ class FlowCreateView( permission_required = "authentik_flows.add_flow" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Flow") @@ -53,7 +54,7 @@ class FlowUpdateView( permission_required = "authentik_flows.change_flow" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated Flow") @@ -64,7 +65,7 @@ class FlowDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageV permission_required = "authentik_flows.delete_flow" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Flow") @@ -104,7 +105,7 @@ class FlowImportView(LoginRequiredMixin, FormView): form_class = FlowImportForm template_name = "administration/flow/import.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") def dispatch(self, request, *args, **kwargs): if not request.user.is_superuser: diff --git a/authentik/admin/views/groups.py b/authentik/admin/views/groups.py index 74a77b5f1..d50bc708f 100644 --- a/authentik/admin/views/groups.py +++ b/authentik/admin/views/groups.py @@ -4,6 +4,7 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import UpdateView from guardian.mixins import PermissionRequiredMixin @@ -27,7 +28,7 @@ class GroupCreateView( permission_required = "authentik_core.add_group" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Group") @@ -44,7 +45,7 @@ class GroupUpdateView( permission_required = "authentik_core.change_group" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated Group") @@ -55,5 +56,5 @@ class GroupDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessage permission_required = "authentik_flows.delete_group" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Group") diff --git a/authentik/admin/views/outposts_service_connections.py b/authentik/admin/views/outposts_service_connections.py index 442690bed..e82ffabbd 100644 --- a/authentik/admin/views/outposts_service_connections.py +++ b/authentik/admin/views/outposts_service_connections.py @@ -4,6 +4,7 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin @@ -27,7 +28,7 @@ class OutpostServiceConnectionCreateView( permission_required = "authentik_outposts.add_outpostserviceconnection" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Outpost Service Connection") @@ -43,7 +44,7 @@ class OutpostServiceConnectionUpdateView( permission_required = "authentik_outposts.change_outpostserviceconnection" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated Outpost Service Connection") @@ -56,5 +57,5 @@ class OutpostServiceConnectionDeleteView( permission_required = "authentik_outposts.delete_outpostserviceconnection" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Outpost Service Connection") diff --git a/authentik/admin/views/policies.py b/authentik/admin/views/policies.py index bb18a3502..85a246b0e 100644 --- a/authentik/admin/views/policies.py +++ b/authentik/admin/views/policies.py @@ -7,6 +7,7 @@ from django.contrib.auth.mixins import ( ) from django.contrib.messages.views import SuccessMessageMixin from django.http import HttpResponse +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import FormView from django.views.generic.detail import DetailView @@ -34,7 +35,7 @@ class PolicyCreateView( permission_required = "authentik_policies.add_policy" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Policy") @@ -50,7 +51,7 @@ class PolicyUpdateView( permission_required = "authentik_policies.change_policy" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated Policy") @@ -61,7 +62,7 @@ class PolicyDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessag permission_required = "authentik_policies.delete_policy" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Policy") diff --git a/authentik/admin/views/policies_bindings.py b/authentik/admin/views/policies_bindings.py index 336f0dd64..2626a0f99 100644 --- a/authentik/admin/views/policies_bindings.py +++ b/authentik/admin/views/policies_bindings.py @@ -7,6 +7,7 @@ from django.contrib.auth.mixins import ( ) from django.contrib.messages.views import SuccessMessageMixin from django.db.models import Max +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import UpdateView from guardian.mixins import PermissionRequiredMixin @@ -30,7 +31,7 @@ class PolicyBindingCreateView( form_class = PolicyBindingForm template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created PolicyBinding") def get_initial(self) -> dict[str, Any]: @@ -63,7 +64,7 @@ class PolicyBindingUpdateView( form_class = PolicyBindingForm template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated PolicyBinding") @@ -76,5 +77,5 @@ class PolicyBindingDeleteView( permission_required = "authentik_policies.delete_policybinding" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted PolicyBinding") diff --git a/authentik/admin/views/stages.py b/authentik/admin/views/stages.py index 049b591e4..b63b2fcef 100644 --- a/authentik/admin/views/stages.py +++ b/authentik/admin/views/stages.py @@ -4,6 +4,7 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin @@ -27,7 +28,7 @@ class StageCreateView( template_name = "generic/create.html" permission_required = "authentik_flows.add_stage" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Stage") @@ -42,7 +43,7 @@ class StageUpdateView( model = Stage permission_required = "authentik_flows.update_application" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated Stage") @@ -52,5 +53,5 @@ class StageDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessage model = Stage template_name = "generic/delete.html" permission_required = "authentik_flows.delete_stage" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Stage") diff --git a/authentik/admin/views/stages_bindings.py b/authentik/admin/views/stages_bindings.py index e8376e6b3..b1038eb1f 100644 --- a/authentik/admin/views/stages_bindings.py +++ b/authentik/admin/views/stages_bindings.py @@ -7,6 +7,7 @@ from django.contrib.auth.mixins import ( ) from django.contrib.messages.views import SuccessMessageMixin from django.db.models import Max +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import UpdateView from guardian.mixins import PermissionRequiredMixin @@ -30,7 +31,7 @@ class StageBindingCreateView( form_class = FlowStageBindingForm template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created StageBinding") def get_initial(self) -> dict[str, Any]: @@ -61,7 +62,7 @@ class StageBindingUpdateView( form_class = FlowStageBindingForm template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated StageBinding") @@ -74,5 +75,5 @@ class StageBindingDeleteView( permission_required = "authentik_flows.delete_flowstagebinding" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted FlowStageBinding") diff --git a/authentik/admin/views/stages_invitations.py b/authentik/admin/views/stages_invitations.py index 3e87247cc..f792c875d 100644 --- a/authentik/admin/views/stages_invitations.py +++ b/authentik/admin/views/stages_invitations.py @@ -5,6 +5,7 @@ from django.contrib.auth.mixins import ( ) from django.contrib.messages.views import SuccessMessageMixin from django.http import HttpResponseRedirect +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin @@ -27,7 +28,7 @@ class InvitationCreateView( permission_required = "authentik_stages_invitation.add_invitation" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Invitation") def form_valid(self, form): @@ -46,5 +47,5 @@ class InvitationDeleteView( permission_required = "authentik_stages_invitation.delete_invitation" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Invitation") diff --git a/authentik/admin/views/stages_prompts.py b/authentik/admin/views/stages_prompts.py index d61b04850..a9ab27668 100644 --- a/authentik/admin/views/stages_prompts.py +++ b/authentik/admin/views/stages_prompts.py @@ -4,6 +4,7 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import UpdateView from guardian.mixins import PermissionRequiredMixin @@ -27,7 +28,7 @@ class PromptCreateView( permission_required = "authentik_stages_prompt.add_prompt" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created Prompt") @@ -44,7 +45,7 @@ class PromptUpdateView( permission_required = "authentik_stages_prompt.change_prompt" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated Prompt") @@ -55,5 +56,5 @@ class PromptDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessag permission_required = "authentik_stages_prompt.delete_prompt" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Prompt") diff --git a/authentik/admin/views/tokens.py b/authentik/admin/views/tokens.py index 0dc6ce311..966189227 100644 --- a/authentik/admin/views/tokens.py +++ b/authentik/admin/views/tokens.py @@ -1,5 +1,6 @@ """authentik Token administration""" from django.contrib.auth.mixins import LoginRequiredMixin +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin @@ -14,5 +15,5 @@ class TokenDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessage permission_required = "authentik_core.delete_token" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted Token") diff --git a/authentik/admin/views/users.py b/authentik/admin/views/users.py index 379a8c641..cd521cd03 100644 --- a/authentik/admin/views/users.py +++ b/authentik/admin/views/users.py @@ -7,7 +7,8 @@ from django.contrib.auth.mixins import ( from django.contrib.messages.views import SuccessMessageMixin from django.http import HttpRequest, HttpResponse from django.http.response import HttpResponseRedirect -from django.shortcuts import redirect, reverse +from django.shortcuts import redirect +from django.urls import reverse_lazy from django.utils.http import urlencode from django.utils.translation import gettext as _ from django.views.generic import DetailView, UpdateView @@ -32,7 +33,7 @@ class UserCreateView( permission_required = "authentik_core.add_user" template_name = "generic/create.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully created User") @@ -51,7 +52,7 @@ class UserUpdateView( # By default the object's name is user which is used by other checks context_object_name = "object" template_name = "generic/update.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully updated User") @@ -64,7 +65,7 @@ class UserDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageV # By default the object's name is user which is used by other checks context_object_name = "object" template_name = "generic/delete.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully deleted User") @@ -79,7 +80,7 @@ class UserDisableView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessage # By default the object's name is user which is used by other checks context_object_name = "object" template_name = "administration/user/disable.html" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully disabled User") def delete(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: @@ -100,7 +101,7 @@ class UserEnableView(LoginRequiredMixin, PermissionRequiredMixin, DetailView): # By default the object's name is user which is used by other checks context_object_name = "object" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") success_message = _("Successfully enabled User") def get(self, request: HttpRequest, *args, **kwargs): @@ -124,7 +125,7 @@ class UserPasswordResetView(LoginRequiredMixin, PermissionRequiredMixin, DetailV ) querystring = urlencode({"token": token.key}) link = request.build_absolute_uri( - reverse("authentik_flows:default-recovery") + f"?{querystring}" + reverse_lazy("authentik_flows:default-recovery") + f"?{querystring}" ) messages.success( request, _("Password reset link:
%(link)s
" % {"link": link}) diff --git a/authentik/admin/views/utils.py b/authentik/admin/views/utils.py index f17b1b354..28fa1a08c 100644 --- a/authentik/admin/views/utils.py +++ b/authentik/admin/views/utils.py @@ -4,6 +4,7 @@ from typing import Any from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.http import Http404 +from django.urls import reverse_lazy from django.views.generic import DeleteView, UpdateView from authentik.lib.utils.reflection import all_subclasses @@ -13,7 +14,7 @@ from authentik.lib.views import CreateAssignPermView class DeleteMessageView(SuccessMessageMixin, DeleteView): """DeleteView which shows `self.success_message` on successful deletion""" - success_url = "/" + success_url = reverse_lazy("authentik_core:shell") def delete(self, request, *args, **kwargs): messages.success(self.request, self.success_message) diff --git a/authentik/core/api/propertymappings.py b/authentik/core/api/propertymappings.py index 147ba44fe..2a58331c0 100644 --- a/authentik/core/api/propertymappings.py +++ b/authentik/core/api/propertymappings.py @@ -1,5 +1,5 @@ """PropertyMapping API Views""" -from django.shortcuts import reverse +from django.urls import reverse from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.request import Request diff --git a/authentik/core/api/providers.py b/authentik/core/api/providers.py index ff58a206f..bbee513f9 100644 --- a/authentik/core/api/providers.py +++ b/authentik/core/api/providers.py @@ -1,5 +1,5 @@ """Provider API Views""" -from django.shortcuts import reverse +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action diff --git a/authentik/core/api/sources.py b/authentik/core/api/sources.py index 0e0c6bf9d..66cf1f087 100644 --- a/authentik/core/api/sources.py +++ b/authentik/core/api/sources.py @@ -1,5 +1,5 @@ """Source API Views""" -from django.shortcuts import reverse +from django.urls import reverse from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.request import Request diff --git a/authentik/core/tests/test_impersonation.py b/authentik/core/tests/test_impersonation.py index 4c18483b3..cce520c17 100644 --- a/authentik/core/tests/test_impersonation.py +++ b/authentik/core/tests/test_impersonation.py @@ -1,6 +1,6 @@ """impersonation tests""" -from django.shortcuts import reverse from django.test.testcases import TestCase +from django.urls import reverse from authentik.core.models import User diff --git a/authentik/core/tests/test_views_overview.py b/authentik/core/tests/test_views_overview.py index cd2a1c1a0..84e214d51 100644 --- a/authentik/core/tests/test_views_overview.py +++ b/authentik/core/tests/test_views_overview.py @@ -2,8 +2,8 @@ import string from random import SystemRandom -from django.shortcuts import reverse from django.test import TestCase +from django.urls import reverse from authentik.core.models import User diff --git a/authentik/core/tests/test_views_user.py b/authentik/core/tests/test_views_user.py index d55edd38c..63a8cef94 100644 --- a/authentik/core/tests/test_views_user.py +++ b/authentik/core/tests/test_views_user.py @@ -2,8 +2,8 @@ import string from random import SystemRandom -from django.shortcuts import reverse from django.test import TestCase +from django.urls import reverse from authentik.core.models import User diff --git a/authentik/events/tests/test_api.py b/authentik/events/tests/test_api.py index f13d86116..7a2812e02 100644 --- a/authentik/events/tests/test_api.py +++ b/authentik/events/tests/test_api.py @@ -1,6 +1,6 @@ """Event API tests""" -from django.shortcuts import reverse +from django.urls import reverse from rest_framework.test import APITestCase from authentik.core.models import User diff --git a/authentik/events/tests/test_middleware.py b/authentik/events/tests/test_middleware.py index f30c93e51..ed91193cf 100644 --- a/authentik/events/tests/test_middleware.py +++ b/authentik/events/tests/test_middleware.py @@ -1,6 +1,6 @@ """Event Middleware tests""" -from django.shortcuts import reverse +from django.urls import reverse from rest_framework.test import APITestCase from authentik.core.models import Application, User diff --git a/authentik/flows/api/stages.py b/authentik/flows/api/stages.py index 661a6e537..2ea926899 100644 --- a/authentik/flows/api/stages.py +++ b/authentik/flows/api/stages.py @@ -1,5 +1,5 @@ """Flow Stage API Views""" -from django.shortcuts import reverse +from django.urls import reverse from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.request import Request diff --git a/authentik/flows/challenge.py b/authentik/flows/challenge.py index 1c64f4a29..830cf4806 100644 --- a/authentik/flows/challenge.py +++ b/authentik/flows/challenge.py @@ -1,14 +1,15 @@ -from authentik.flows.transfer.common import DataclassEncoder -from dataclasses import asdict, is_dataclass +"""Challenge helpers""" from enum import Enum -from json.encoder import JSONEncoder from django.http import JsonResponse -from rest_framework.fields import ChoiceField, DictField, JSONField +from rest_framework.fields import ChoiceField, JSONField from rest_framework.serializers import CharField, Serializer +from authentik.flows.transfer.common import DataclassEncoder + class ChallengeTypes(Enum): + """Currently defined challenge types""" native = "native" shell = "shell" @@ -16,6 +17,8 @@ class ChallengeTypes(Enum): class Challenge(Serializer): + """Challenge that gets sent to the client based on which stage + is currently active""" type = ChoiceField(choices=list(ChallengeTypes)) component = CharField(required=False) @@ -23,10 +26,12 @@ class Challenge(Serializer): class ChallengeResponse(Serializer): - - pass + """Base class for all challenge responses""" class HttpChallengeResponse(JsonResponse): + """Subclass of JsonResponse that uses the `DataclassEncoder`""" + def __init__(self, challenge: Challenge, **kwargs) -> None: + # pyright: reportGeneralTypeIssues=false super().__init__(challenge.data, encoder=DataclassEncoder, **kwargs) diff --git a/authentik/flows/tests/test_api.py b/authentik/flows/tests/test_api.py index f242b95e8..e211b7118 100644 --- a/authentik/flows/tests/test_api.py +++ b/authentik/flows/tests/test_api.py @@ -1,5 +1,5 @@ """API flow tests""" -from django.shortcuts import reverse +from django.urls import reverse from rest_framework.test import APITestCase from authentik.core.models import User diff --git a/authentik/flows/tests/test_planner.py b/authentik/flows/tests/test_planner.py index 5206ddc5d..9eb60a112 100644 --- a/authentik/flows/tests/test_planner.py +++ b/authentik/flows/tests/test_planner.py @@ -4,8 +4,8 @@ from unittest.mock import MagicMock, Mock, PropertyMock, patch from django.contrib.sessions.middleware import SessionMiddleware from django.core.cache import cache from django.http import HttpRequest -from django.shortcuts import reverse from django.test import RequestFactory, TestCase +from django.urls import reverse from guardian.shortcuts import get_anonymous_user from authentik.core.models import User diff --git a/authentik/flows/tests/test_views.py b/authentik/flows/tests/test_views.py index 9e9433fe6..badeab777 100644 --- a/authentik/flows/tests/test_views.py +++ b/authentik/flows/tests/test_views.py @@ -2,9 +2,9 @@ from unittest.mock import MagicMock, PropertyMock, patch from django.http import HttpRequest, HttpResponse -from django.shortcuts import reverse from django.test import TestCase from django.test.client import RequestFactory +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User @@ -359,7 +359,7 @@ class TestFlowExecutor(TestCase): self.assertEqual(response.status_code, 200) self.assertJSONEqual( force_str(response.content), - {"type": "redirect", "to": reverse("authentik_core:shell")}, + {"args": {"to": reverse("authentik_core:shell")}, "type": "redirect"}, ) def test_reevaluate_remove_consecutive(self): diff --git a/authentik/flows/tests/test_views_helper.py b/authentik/flows/tests/test_views_helper.py index 3a5af523f..c42fcdc66 100644 --- a/authentik/flows/tests/test_views_helper.py +++ b/authentik/flows/tests/test_views_helper.py @@ -1,6 +1,6 @@ """flow views tests""" -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from authentik.flows.models import Flow, FlowDesignation from authentik.flows.planner import FlowPlan diff --git a/authentik/outposts/api/outpost_service_connections.py b/authentik/outposts/api/outpost_service_connections.py index 1a5c7d947..d8ed4bd7d 100644 --- a/authentik/outposts/api/outpost_service_connections.py +++ b/authentik/outposts/api/outpost_service_connections.py @@ -2,7 +2,7 @@ from dataclasses import asdict from django.db.models.base import Model -from django.shortcuts import reverse +from django.urls import reverse from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.fields import BooleanField, CharField, SerializerMethodField diff --git a/authentik/policies/api.py b/authentik/policies/api.py index 9b480d6b6..75a8fa6ab 100644 --- a/authentik/policies/api.py +++ b/authentik/policies/api.py @@ -1,7 +1,7 @@ """policy API Views""" from django.core.cache import cache from django.core.exceptions import ObjectDoesNotExist -from django.shortcuts import reverse +from django.urls import reverse from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.request import Request diff --git a/authentik/providers/oauth2/api.py b/authentik/providers/oauth2/api.py index 13edd2c66..7e6ef24ee 100644 --- a/authentik/providers/oauth2/api.py +++ b/authentik/providers/oauth2/api.py @@ -1,5 +1,5 @@ """OAuth2Provider API Views""" -from django.shortcuts import reverse +from django.urls import reverse from drf_yasg2.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.fields import ReadOnlyField diff --git a/authentik/providers/saml/processors/metadata.py b/authentik/providers/saml/processors/metadata.py index 218dad17e..32edb7d15 100644 --- a/authentik/providers/saml/processors/metadata.py +++ b/authentik/providers/saml/processors/metadata.py @@ -3,7 +3,7 @@ from typing import Iterator, Optional import xmlsec # nosec from django.http import HttpRequest -from django.shortcuts import reverse +from django.urls import reverse from lxml.etree import Element, SubElement, tostring # nosec from authentik.providers.saml.models import SAMLProvider diff --git a/authentik/recovery/tests.py b/authentik/recovery/tests.py index 39406d49d..4357a7c80 100644 --- a/authentik/recovery/tests.py +++ b/authentik/recovery/tests.py @@ -2,8 +2,8 @@ from io import StringIO from django.core.management import call_command -from django.shortcuts import reverse from django.test import TestCase +from django.urls import reverse from authentik.core.models import Token, TokenIntents, User diff --git a/authentik/root/tests.py b/authentik/root/tests.py index e8021c617..94ae0a5cf 100644 --- a/authentik/root/tests.py +++ b/authentik/root/tests.py @@ -2,8 +2,8 @@ from base64 import b64encode from django.conf import settings -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse class TestRoot(TestCase): diff --git a/authentik/sources/oauth/models.py b/authentik/sources/oauth/models.py index 23d99643f..f64148bbe 100644 --- a/authentik/sources/oauth/models.py +++ b/authentik/sources/oauth/models.py @@ -3,10 +3,10 @@ from typing import Optional, Type from django.db import models from django.forms import ModelForm +from django.templatetags.static import static from django.urls import reverse, reverse_lazy from django.utils.translation import gettext_lazy as _ from rest_framework.serializers import Serializer -from django.templatetags.static import static from authentik.core.models import Source, UserSourceConnection from authentik.core.types import UILoginButton diff --git a/authentik/sources/oauth/tests/test_views.py b/authentik/sources/oauth/tests/test_views.py index ec4f44eec..9478902ab 100644 --- a/authentik/sources/oauth/tests/test_views.py +++ b/authentik/sources/oauth/tests/test_views.py @@ -1,6 +1,6 @@ """OAuth Source tests""" -from django.shortcuts import reverse from django.test import TestCase +from django.urls import reverse from authentik.sources.oauth.models import OAuthSource diff --git a/authentik/sources/saml/models.py b/authentik/sources/saml/models.py index fb55a72e0..8889a4afa 100644 --- a/authentik/sources/saml/models.py +++ b/authentik/sources/saml/models.py @@ -4,8 +4,7 @@ from typing import Type from django.db import models from django.forms import ModelForm from django.http import HttpRequest -from django.shortcuts import reverse -from django.urls import reverse_lazy +from django.urls import reverse, reverse_lazy from django.utils.translation import gettext_lazy as _ from rest_framework.serializers import Serializer diff --git a/authentik/stages/authenticator_static/models.py b/authentik/stages/authenticator_static/models.py index aa76a955b..8184f3c27 100644 --- a/authentik/stages/authenticator_static/models.py +++ b/authentik/stages/authenticator_static/models.py @@ -3,7 +3,7 @@ from typing import Optional, Type from django.db import models from django.forms import ModelForm -from django.shortcuts import reverse +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.serializers import BaseSerializer diff --git a/authentik/stages/authenticator_totp/models.py b/authentik/stages/authenticator_totp/models.py index 010a1fd97..4f19d47a7 100644 --- a/authentik/stages/authenticator_totp/models.py +++ b/authentik/stages/authenticator_totp/models.py @@ -3,7 +3,7 @@ from typing import Optional, Type from django.db import models from django.forms import ModelForm -from django.shortcuts import reverse +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.serializers import BaseSerializer diff --git a/authentik/stages/authenticator_webauthn/models.py b/authentik/stages/authenticator_webauthn/models.py index a3f5c409c..30eb1b7e3 100644 --- a/authentik/stages/authenticator_webauthn/models.py +++ b/authentik/stages/authenticator_webauthn/models.py @@ -4,7 +4,7 @@ from typing import Optional, Type from django.contrib.auth import get_user_model from django.db import models from django.forms import ModelForm -from django.shortcuts import reverse +from django.urls import reverse from django.utils.timezone import now from django.utils.translation import gettext_lazy as _ from django.views import View diff --git a/authentik/stages/captcha/tests.py b/authentik/stages/captcha/tests.py index dcebb1d4e..278d9bd2b 100644 --- a/authentik/stages/captcha/tests.py +++ b/authentik/stages/captcha/tests.py @@ -1,7 +1,7 @@ """captcha tests""" from django.conf import settings -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/consent/tests.py b/authentik/stages/consent/tests.py index 7a17b42c4..572edcca0 100644 --- a/authentik/stages/consent/tests.py +++ b/authentik/stages/consent/tests.py @@ -1,8 +1,8 @@ """consent tests""" from time import sleep -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import Application, User diff --git a/authentik/stages/dummy/tests.py b/authentik/stages/dummy/tests.py index 97e5a796b..56570192a 100644 --- a/authentik/stages/dummy/tests.py +++ b/authentik/stages/dummy/tests.py @@ -1,6 +1,6 @@ """dummy tests""" -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/email/tests/test_sending.py b/authentik/stages/email/tests/test_sending.py index fcf4f3f9e..62be151db 100644 --- a/authentik/stages/email/tests/test_sending.py +++ b/authentik/stages/email/tests/test_sending.py @@ -4,8 +4,8 @@ from unittest.mock import MagicMock, patch from django.core import mail from django.core.mail.backends.locmem import EmailBackend -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from authentik.core.models import User from authentik.flows.markers import StageMarker diff --git a/authentik/stages/email/tests/test_stage.py b/authentik/stages/email/tests/test_stage.py index bc00dc24b..a852653e5 100644 --- a/authentik/stages/email/tests/test_stage.py +++ b/authentik/stages/email/tests/test_stage.py @@ -2,8 +2,8 @@ from unittest.mock import MagicMock, patch from django.core import mail -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import Token, User diff --git a/authentik/stages/identification/stage.py b/authentik/stages/identification/stage.py index 59569ef93..2c329e06a 100644 --- a/authentik/stages/identification/stage.py +++ b/authentik/stages/identification/stage.py @@ -1,10 +1,10 @@ """Identification stage logic""" -from typing import Optional +from typing import Optional, Union from django.contrib import messages from django.db.models import Q from django.http import HttpResponse -from django.shortcuts import reverse +from django.urls import reverse from django.utils.translation import gettext as _ from django.views.generic import FormView from rest_framework.fields import CharField @@ -55,7 +55,7 @@ class IdentificationStageView(ChallengeStageView): def get_challenge(self) -> Challenge: current_stage: IdentificationStage = self.executor.current_stage - args = {"input_type": "text"} + args: dict[str, Union[str, list[UILoginButton]]] = {"input_type": "text"} if current_stage.user_fields == [UserFields.E_MAIL]: args["input_type"] = "email" # If the user has been redirected to us whilst trying to access an @@ -76,14 +76,15 @@ class IdentificationStageView(ChallengeStageView): args["primary_action"] = _("Log in") # Check all enabled source, add them if they have a UI Login button. - args["sources"] = [] + ui_sources = [] sources: list[Source] = ( Source.objects.filter(enabled=True).order_by("name").select_subclasses() ) for source in sources: ui_login_button = source.ui_login_button if ui_login_button: - args["sources"].append(ui_login_button) + ui_sources.append(ui_login_button) + args["sources"] = ui_sources return Challenge( data={ "type": ChallengeTypes.native, diff --git a/authentik/stages/identification/tests.py b/authentik/stages/identification/tests.py index d3b451715..1c29b4792 100644 --- a/authentik/stages/identification/tests.py +++ b/authentik/stages/identification/tests.py @@ -1,6 +1,6 @@ """identification tests""" -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/invitation/tests.py b/authentik/stages/invitation/tests.py index 072ecd49e..19412dd0e 100644 --- a/authentik/stages/invitation/tests.py +++ b/authentik/stages/invitation/tests.py @@ -1,8 +1,8 @@ """invitation tests""" from unittest.mock import MagicMock, patch -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from guardian.shortcuts import get_anonymous_user diff --git a/authentik/stages/password/models.py b/authentik/stages/password/models.py index 43e4a6277..e599d49cd 100644 --- a/authentik/stages/password/models.py +++ b/authentik/stages/password/models.py @@ -4,7 +4,7 @@ from typing import Optional, Type from django.contrib.postgres.fields import ArrayField from django.db import models from django.forms import ModelForm -from django.shortcuts import reverse +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.serializers import BaseSerializer diff --git a/authentik/stages/password/tests.py b/authentik/stages/password/tests.py index 0d7c35a5c..2a5e87af5 100644 --- a/authentik/stages/password/tests.py +++ b/authentik/stages/password/tests.py @@ -4,8 +4,8 @@ from random import SystemRandom from unittest.mock import MagicMock, patch from django.core.exceptions import PermissionDenied -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/password/views.py b/authentik/stages/password/views.py index 1808781a7..1a4624719 100644 --- a/authentik/stages/password/views.py +++ b/authentik/stages/password/views.py @@ -2,7 +2,7 @@ from typing import Any from django.contrib.auth.mixins import LoginRequiredMixin -from django.shortcuts import reverse +from django.urls import reverse from django.utils.http import urlencode from django.views.generic import TemplateView diff --git a/authentik/stages/prompt/tests.py b/authentik/stages/prompt/tests.py index b2cbb95c3..d209849c8 100644 --- a/authentik/stages/prompt/tests.py +++ b/authentik/stages/prompt/tests.py @@ -1,8 +1,8 @@ """Prompt tests""" from unittest.mock import MagicMock, patch -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/user_delete/tests.py b/authentik/stages/user_delete/tests.py index 85c6a7c09..1c691101d 100644 --- a/authentik/stages/user_delete/tests.py +++ b/authentik/stages/user_delete/tests.py @@ -1,8 +1,8 @@ """delete tests""" from unittest.mock import patch -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/user_login/tests.py b/authentik/stages/user_login/tests.py index 7a5a29679..219009169 100644 --- a/authentik/stages/user_login/tests.py +++ b/authentik/stages/user_login/tests.py @@ -1,8 +1,8 @@ """login tests""" from unittest.mock import patch -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/user_logout/tests.py b/authentik/stages/user_logout/tests.py index f50cf95f1..9dba5a0d4 100644 --- a/authentik/stages/user_logout/tests.py +++ b/authentik/stages/user_logout/tests.py @@ -1,6 +1,6 @@ """logout tests""" -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/authentik/stages/user_write/tests.py b/authentik/stages/user_write/tests.py index 52f9f8f13..4f5b213ce 100644 --- a/authentik/stages/user_write/tests.py +++ b/authentik/stages/user_write/tests.py @@ -3,8 +3,8 @@ import string from random import SystemRandom from unittest.mock import patch -from django.shortcuts import reverse from django.test import Client, TestCase +from django.urls import reverse from django.utils.encoding import force_str from authentik.core.models import User diff --git a/tests/e2e/utils.py b/tests/e2e/utils.py index e63ff2a9d..e42fde3bd 100644 --- a/tests/e2e/utils.py +++ b/tests/e2e/utils.py @@ -12,8 +12,8 @@ from django.apps import apps from django.contrib.staticfiles.testing import StaticLiveServerTestCase from django.db import connection, transaction from django.db.utils import IntegrityError -from django.shortcuts import reverse from django.test.testcases import TransactionTestCase +from django.urls import reverse from docker import DockerClient, from_env from docker.models.containers import Container from selenium import webdriver