Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make token generator class configurable (#17701)
Marcin Wcisłof74a5394c7f1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 494b55ae3e..bce2991335 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -124,3 +124,4 @@ All notable, unreleased changes to this project will be documented in this file.- The prices for draft orders created in `OrderBulkCreate` now are properly calculated - #17583 by @IKarbowiak- Fixes incorrect stock deallocation when multiple order lines share the same ProductVariant - #17657 by @korycins- Decrease allocations for lines with inventory tracking disabled, if allocations exist - #17657 by @korycins+- Make token generator class configurable - #17701 by @wcislo-saleordiff --git a/saleor/account/notifications.py b/saleor/account/notifications.pyindex 1b3e2bfb20..f920428b7a 100644--- a/saleor/account/notifications.py+++ b/saleor/account/notifications.py@@ -1,10 +1,8 @@from urllib.parse import urlencode-from django.contrib.auth.tokens import default_token_generator-from ..core.notification.utils import get_site_contextfrom ..core.notify import NotifyEventType, NotifyHandler-from ..core.tokens import account_delete_token_generator+from ..core.tokens import account_delete_token_generator, token_generatorfrom ..core.utils.url import prepare_urlfrom ..graphql.core.utils import to_global_id_or_nonefrom .models import User@@ -43,7 +41,7 @@ def send_password_reset_notification("""Trigger sending a password reset notification for the given customer/staff."""def _generate_payload():- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)params = urlencode({"email": user.email, "token": token})reset_url = prepare_url(params, redirect_url)@@ -71,7 +69,7 @@ def send_account_confirmation(user, redirect_url, manager, channel_slug, token=Ndef _generate_payload():if not token:- user_token = default_token_generator.make_token(user)+ user_token = token_generator.make_token(user)else:user_token = token@@ -181,12 +179,12 @@ def send_set_password_notification("""Trigger sending a set password notification for the given customer/staff."""def _generate_payload():- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)params = urlencode({"email": user.email, "token": token})password_set_url = prepare_url(params, redirect_url)payload = {"user": get_default_user_payload(user),- "token": default_token_generator.make_token(user),+ "token": token_generator.make_token(user),"recipient_email": user.email,"password_set_url": password_set_url,"channel_slug": channel_slug,diff --git a/saleor/account/tasks.py b/saleor/account/tasks.pyindex 46f84c68f1..20c0ec2433 100644--- a/saleor/account/tasks.py+++ b/saleor/account/tasks.py@@ -2,11 +2,11 @@ import loggingfrom typing import castfrom urllib.parse import urlencode-from django.contrib.auth.tokens import default_token_generatorfrom django.utils import timezonefrom ..celeryconf import appfrom ..core.db.connection import allow_writer+from ..core.tokens import token_generatorfrom ..core.utils.events import call_eventfrom ..core.utils.url import prepare_urlfrom ..graphql.plugins.dataloaders import get_plugin_manager_promise@@ -54,7 +54,7 @@ def trigger_send_password_reset_notification(staff=user.is_staff,)- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)redirect_params = _prepare_redirect_url(user, redirect_url, token)if user.is_staff:@@ -98,7 +98,7 @@ def finish_creating_user(user_pk, redirect_url, channel_slug, context_data):if site.settings.enable_account_confirmation_by_email:# Notifications will be deprecated in the future- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)notifications.send_account_confirmation(user=user,redirect_url=redirect_url,diff --git a/saleor/account/tests/test_notifications.py b/saleor/account/tests/test_notifications.pyindex f891d348a4..c1052439e5 100644--- a/saleor/account/tests/test_notifications.py+++ b/saleor/account/tests/test_notifications.py@@ -104,7 +104,7 @@ def test_send_email_changed_notification(@pytest.mark.parametrize("is_staff", [True, False])[email protected]("saleor.account.notifications.default_token_generator.make_token")[email protected]("saleor.account.notifications.token_generator.make_token")@mock.patch("saleor.plugins.manager.PluginsManager.notify")def test_send_password_reset_notification(mocked_notify, mocked_generator, is_staff, site_settings, customer_user, channel_PLNdiff --git a/saleor/core/tokens.py b/saleor/core/tokens.pyindex a0033ebd51..e68c724290 100644--- a/saleor/core/tokens.py+++ b/saleor/core/tokens.py@@ -1,7 +1,10 @@-from django.contrib.auth.tokens import PasswordResetTokenGenerator+from django.conf import settings+from django.utils.module_loading import import_string+token_generator_cls = import_string(settings.TOKEN_GENERATOR_CLASS)-class AccountDeleteTokenGenerator(PasswordResetTokenGenerator):++class AccountDeleteTokenGenerator(token_generator_cls): # type: ignore[valid-type,misc]def _make_hash_value(self, user, timestamp):# Override this method to remove the user `last_login` value from the hash.# As this token is used for deleting the user, so there is no worry@@ -12,3 +15,4 @@ class AccountDeleteTokenGenerator(PasswordResetTokenGenerator):account_delete_token_generator = AccountDeleteTokenGenerator()+token_generator = token_generator_cls()diff --git a/saleor/graphql/account/mutations/account/confirm_account.py b/saleor/graphql/account/mutations/account/confirm_account.pyindex 37c88487ad..95cb19c22d 100644--- a/saleor/graphql/account/mutations/account/confirm_account.py+++ b/saleor/graphql/account/mutations/account/confirm_account.py@@ -1,9 +1,9 @@import graphene-from django.contrib.auth.tokens import default_token_generatorfrom django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom .....account import modelsfrom .....account.error_codes import AccountErrorCode+from .....core.tokens import token_generatorfrom .....giftcard.utils import assign_user_gift_cardsfrom .....order.utils import match_orders_with_new_userfrom .....webhook.event_types import WebhookEventAsyncType@@ -56,7 +56,7 @@ class ConfirmAccount(BaseMutation):error = Trueuser = models.User()- valid_token = default_token_generator.check_token(user, data["token"])+ valid_token = token_generator.check_token(user, data["token"])if not valid_token or error:raise ValidationError({diff --git a/saleor/graphql/account/mutations/account/send_confirmation_email.py b/saleor/graphql/account/mutations/account/send_confirmation_email.pyindex 40c3d94e05..0e1fb0b53c 100644--- a/saleor/graphql/account/mutations/account/send_confirmation_email.py+++ b/saleor/graphql/account/mutations/account/send_confirmation_email.py@@ -3,13 +3,13 @@ from urllib.parse import urlencodeimport graphenefrom django.conf import settings-from django.contrib.auth.tokens import default_token_generatorfrom django.core.exceptions import ValidationErrorfrom django.utils import timezonefrom .....account import modelsfrom .....account.error_codes import SendConfirmationEmailErrorCodefrom .....account.notifications import send_account_confirmation+from .....core.tokens import token_generatorfrom .....core.utils.url import prepare_url, validate_storefront_urlfrom .....permission.auth_filters import AuthorizationFiltersfrom .....webhook.event_types import WebhookEventAsyncType@@ -100,7 +100,7 @@ class SendConfirmationEmail(BaseMutation):allow_replica=False,).slugmanager = get_plugin_manager_promise(info.context).get()- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)send_account_confirmation(user,diff --git a/saleor/graphql/account/mutations/authentication/set_password.py b/saleor/graphql/account/mutations/authentication/set_password.pyindex 99f3894946..53c3326937 100644--- a/saleor/graphql/account/mutations/authentication/set_password.py+++ b/saleor/graphql/account/mutations/authentication/set_password.py@@ -1,12 +1,12 @@import graphenefrom django.contrib.auth import password_validation-from django.contrib.auth.tokens import default_token_generatorfrom django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom .....account import events as account_eventsfrom .....account import modelsfrom .....account.error_codes import AccountErrorCodefrom .....core.db.connection import allow_writer+from .....core.tokens import token_generatorfrom .....order.utils import match_orders_with_new_userfrom ....core import ResolveInfofrom ....core.context import disallow_replica_in_context@@ -59,7 +59,7 @@ class SetPassword(CreateToken):error = Trueuser = models.User()- valid_token = default_token_generator.check_token(user, token)+ valid_token = token_generator.check_token(user, token)if not valid_token or error:raise ValidationError({diff --git a/saleor/graphql/account/mutations/staff/customer_create.py b/saleor/graphql/account/mutations/staff/customer_create.pyindex 0ffb020939..ef72324390 100644--- a/saleor/graphql/account/mutations/staff/customer_create.py+++ b/saleor/graphql/account/mutations/staff/customer_create.py@@ -1,6 +1,5 @@from urllib.parse import urlencode-from django.contrib.auth.tokens import default_token_generatorfrom django.core.exceptions import ValidationErrorfrom django.db import IntegrityError, transaction@@ -8,6 +7,7 @@ from .....account import events as account_eventsfrom .....account import modelsfrom .....account.notifications import send_set_password_notificationfrom .....account.search import prepare_user_search_document_value+from .....core.tokens import token_generatorfrom .....core.tracing import traced_atomic_transactionfrom .....core.utils.url import prepare_urlfrom .....permission.enums import AccountPermissions@@ -155,7 +155,7 @@ class CustomerCreate(BaseCustomerCreate):plugins_manager,channel_slug,)- token = default_token_generator.make_token(instance)+ token = token_generator.make_token(instance)params = urlencode({"email": instance.email, "token": token})cls.call_event(diff --git a/saleor/graphql/account/mutations/staff/staff_create.py b/saleor/graphql/account/mutations/staff/staff_create.pyindex 7e984b4b1c..090839e52a 100644--- a/saleor/graphql/account/mutations/staff/staff_create.py+++ b/saleor/graphql/account/mutations/staff/staff_create.py@@ -3,7 +3,6 @@ from typing import castfrom urllib.parse import urlencodeimport graphene-from django.contrib.auth.tokens import default_token_generatorfrom django.core.exceptions import ValidationErrorfrom .....account import models@@ -11,6 +10,7 @@ from .....account.error_codes import AccountErrorCodefrom .....account.notifications import send_set_password_notificationfrom .....account.search import USER_SEARCH_FIELDS, prepare_user_search_document_valuefrom .....core.exceptions import PermissionDenied+from .....core.tokens import token_generatorfrom .....core.tracing import traced_atomic_transactionfrom .....core.utils.url import prepare_url, validate_storefront_urlfrom .....permission.enums import AccountPermissions@@ -182,7 +182,7 @@ class StaffCreate(DeprecatedModelMutation):channel_slug=None,staff=True,)- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)params = urlencode({"email": user.email, "token": token})cls.call_event(manager.staff_set_password_requested,diff --git a/saleor/graphql/account/tests/mutations/account/test_account_register.py b/saleor/graphql/account/tests/mutations/account/test_account_register.pyindex fa628fa32b..0aa3aabc12 100644--- a/saleor/graphql/account/tests/mutations/account/test_account_register.py+++ b/saleor/graphql/account/tests/mutations/account/test_account_register.py@@ -1,7 +1,6 @@from unittest.mock import ANY, patchfrom urllib.parse import urlencode-from django.contrib.auth.tokens import default_token_generatorfrom django.test import override_settingsfrom ......account import events as account_events@@ -11,6 +10,7 @@ from ......account.search import generate_user_fields_search_document_valuefrom ......account.tasks import finish_creating_userfrom ......core.notify import NotifyEventTypefrom ......core.tests.utils import get_site_context_payload+from ......core.tokens import token_generatorfrom ......core.utils.url import prepare_urlfrom ......tests import race_conditionfrom .....tests.utils import get_graphql_content@@ -41,7 +41,7 @@ ACCOUNT_REGISTER_MUTATION = """@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True, ALLOWED_CLIENT_HOSTS=["localhost"])-@patch("saleor.account.notifications.default_token_generator.make_token")+@patch("saleor.account.notifications.token_generator.make_token")@patch("saleor.plugins.manager.PluginsManager.notify")@patch("saleor.graphql.account.mutations.account.account_register.finish_creating_user",@@ -121,7 +121,7 @@ def test_customer_register(@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True, ALLOWED_CLIENT_HOSTS=["localhost"])-@patch("saleor.account.notifications.default_token_generator.make_token")+@patch("saleor.account.notifications.token_generator.make_token")@patch("saleor.plugins.manager.PluginsManager.notify")@patch("saleor.graphql.account.mutations.account.account_register.finish_creating_user",@@ -260,7 +260,7 @@ def test_customer_register_generates_valid_token(assert called_kwargs["channel_slug"] == channel_PLN.slugassert not data["errors"]- assert default_token_generator.check_token(new_user, token)+ assert token_generator.check_token(new_user, token)@patch("saleor.plugins.manager.PluginsManager.notify")@@ -413,7 +413,7 @@ def test_account_register_returns_empty_id(@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True, ALLOWED_CLIENT_HOSTS=["localhost"])-@patch("saleor.account.notifications.default_token_generator.make_token")+@patch("saleor.account.notifications.token_generator.make_token")@patch("saleor.plugins.manager.PluginsManager.notify")@patch("saleor.graphql.account.mutations.account.account_register.finish_creating_user",diff --git a/saleor/graphql/account/tests/mutations/account/test_confirm_account.py b/saleor/graphql/account/tests/mutations/account/test_confirm_account.pyindex 84a957d941..f7d312fae5 100644--- a/saleor/graphql/account/tests/mutations/account/test_confirm_account.py+++ b/saleor/graphql/account/tests/mutations/account/test_confirm_account.py@@ -1,9 +1,9 @@from unittest.mock import patch-from django.contrib.auth.tokens import default_token_generatorfrom freezegun import freeze_timefrom ......account.error_codes import AccountErrorCode+from ......core.tokens import token_generatorfrom .....tests.utils import get_graphql_contentCONFIRM_ACCOUNT_MUTATION = """@@ -43,7 +43,7 @@ def test_account_confirmation(variables = {"email": customer_user.email,- "token": default_token_generator.make_token(customer_user),+ "token": token_generator.make_token(customer_user),"channel": channel_USD.slug,}response = api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)@@ -73,7 +73,7 @@ def test_account_confirmation_invalid_user():variables = {"email": "[email protected]",- "token": default_token_generator.make_token(customer_user),+ "token": token_generator.make_token(customer_user),"channel": channel_USD.slug,}response = user_api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)diff --git a/saleor/graphql/account/tests/mutations/account/test_send_confirmation_email.py b/saleor/graphql/account/tests/mutations/account/test_send_confirmation_email.pyindex cd062350dc..626e07f30b 100644--- a/saleor/graphql/account/tests/mutations/account/test_send_confirmation_email.py+++ b/saleor/graphql/account/tests/mutations/account/test_send_confirmation_email.py@@ -2,7 +2,6 @@ import datetimefrom unittest.mock import patchfrom urllib.parse import urlencode-from django.contrib.auth.tokens import default_token_generatorfrom django.test import override_settingsfrom django.utils import timezonefrom freezegun import freeze_time@@ -11,6 +10,7 @@ from ......account.error_codes import SendConfirmationEmailErrorCodefrom ......account.notifications import get_default_user_payloadfrom ......core.notify import NotifyEventTypefrom ......core.tests.utils import get_site_context_payload+from ......core.tokens import token_generatorfrom ......core.utils.url import prepare_urlfrom .....tests.utils import get_graphql_content@@ -55,7 +55,7 @@ def test_send_confirmation_email(data = content["data"]["sendConfirmationEmail"]assert not data["errors"]- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)params = urlencode({"email": user.email, "token": token})confirm_url = prepare_url(params, redirect_url)expected_payload = {@@ -226,4 +226,4 @@ def test_send_confirmation_email_generates_valid_token(token = called_kwargs["payload_func"]()["token"]user.refresh_from_db()- assert default_token_generator.check_token(user, token)+ assert token_generator.check_token(user, token)diff --git a/saleor/graphql/account/tests/mutations/authentication/test_request_password_reset.py b/saleor/graphql/account/tests/mutations/authentication/test_request_password_reset.pyindex 16e0212e8b..56d2a648a7 100644--- a/saleor/graphql/account/tests/mutations/authentication/test_request_password_reset.py+++ b/saleor/graphql/account/tests/mutations/authentication/test_request_password_reset.py@@ -2,13 +2,13 @@ import datetimefrom unittest.mock import patchfrom urllib.parse import urlencode-from django.contrib.auth.tokens import default_token_generatorfrom django.utils import timezonefrom freezegun import freeze_timefrom ......account.notifications import get_default_user_payloadfrom ......core.notify import NotifyEventTypefrom ......core.tests.utils import get_site_context_payload+from ......core.tokens import token_generatorfrom ......core.utils.url import prepare_urlfrom .....tests.utils import get_graphql_content@@ -54,7 +54,7 @@ def test_account_reset_password(# thendata = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {@@ -159,7 +159,7 @@ def test_account_reset_password_with_upper_case_email(# thendata = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {@@ -206,7 +206,7 @@ def test_request_password_reset_email_for_staff(# thendata = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(user)+ token = token_generator.make_token(user)params = urlencode({"email": user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {@@ -322,7 +322,7 @@ def test_account_reset_password_all_storefront_hosts_allowed(data = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {@@ -365,7 +365,7 @@ def test_account_reset_password_subdomain(data = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {@@ -443,7 +443,7 @@ def test_account_reset_password_for_not_confirmed_user(content = get_graphql_content(response)data = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {@@ -501,7 +501,7 @@ def test_account_reset_password_no_channel_provided_multiple_channels(# thendata = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {@@ -562,7 +562,7 @@ def test_account_reset_password_no_channel_provided_one_channel(# thendata = content["data"]["requestPasswordReset"]assert not data["errors"]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})reset_url = prepare_url(params, redirect_url)expected_payload = {diff --git a/saleor/graphql/account/tests/mutations/authentication/test_set_password.py b/saleor/graphql/account/tests/mutations/authentication/test_set_password.pyindex ba4a9d5fb8..a0662d5f0c 100644--- a/saleor/graphql/account/tests/mutations/authentication/test_set_password.py+++ b/saleor/graphql/account/tests/mutations/authentication/test_set_password.py@@ -1,10 +1,10 @@from unittest.mock import patch-from django.contrib.auth.tokens import default_token_generatorfrom freezegun import freeze_timefrom ......account import events as account_eventsfrom ......account.error_codes import AccountErrorCode+from ......core.tokens import token_generatorfrom .....core.utils import str_to_enumfrom .....tests.utils import get_graphql_contentfrom ....mutations.base import INVALID_TOKEN@@ -33,7 +33,7 @@ SET_PASSWORD_MUTATION = """@freeze_time("2018-05-31 12:00:01")def test_set_password(user_api_client, customer_user):- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)password = "spanish-inquisition"variables = {"email": customer_user.email, "password": password, "token": token}@@ -62,7 +62,7 @@ def test_set_password_confirm_user_and_match_orders(customer_user.is_confirmed = Falsecustomer_user.save(update_fields=["is_confirmed"])- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)password = "spanish-inquisition"variables = {"email": customer_user.email, "password": password, "token": token}@@ -122,7 +122,7 @@ def test_set_password_invalid_password(user_api_client, customer_user, settings){"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},]- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)variables = {"email": customer_user.email, "password": "1234", "token": token}response = user_api_client.post_graphql(SET_PASSWORD_MUTATION, variables)content = get_graphql_content(response)diff --git a/saleor/graphql/account/tests/mutations/staff/test_customer_create.py b/saleor/graphql/account/tests/mutations/staff/test_customer_create.pyindex c3ab6d6d40..777b795c40 100644--- a/saleor/graphql/account/tests/mutations/staff/test_customer_create.py+++ b/saleor/graphql/account/tests/mutations/staff/test_customer_create.py@@ -85,7 +85,7 @@ CUSTOMER_CREATE_MUTATION = """@patch("saleor.plugins.manager.PluginsManager.customer_metadata_updated")-@patch("saleor.account.notifications.default_token_generator.make_token")+@patch("saleor.account.notifications.token_generator.make_token")@patch("saleor.plugins.manager.PluginsManager.notify")@patch("saleor.plugins.manager.PluginsManager.account_set_password_requested")def test_customer_create(@@ -203,7 +203,7 @@ def test_customer_create(@patch("saleor.plugins.manager.PluginsManager.customer_metadata_updated")-@patch("saleor.account.notifications.default_token_generator.make_token")+@patch("saleor.account.notifications.token_generator.make_token")@patch("saleor.plugins.manager.PluginsManager.notify")@patch("saleor.plugins.manager.PluginsManager.account_set_password_requested")def test_customer_create_as_app(@@ -325,7 +325,7 @@ def test_customer_create_as_app()-@patch("saleor.account.notifications.default_token_generator.make_token")+@patch("saleor.account.notifications.token_generator.make_token")@patch("saleor.plugins.manager.PluginsManager.notify")def test_customer_create_send_password_with_url(mocked_notify,@@ -513,7 +513,7 @@ def test_customer_create_with_non_unique_external_reference(assert error["message"] == "User with this External reference already exists."-@patch("saleor.account.notifications.default_token_generator.make_token")+@patch("saleor.account.notifications.token_generator.make_token")@patch("saleor.plugins.webhook.plugin.trigger_webhooks_async")def test_customer_create_webhook_event_triggered(mocked_trigger_webhooks_async,diff --git a/saleor/graphql/account/tests/mutations/staff/test_staff_create.py b/saleor/graphql/account/tests/mutations/staff/test_staff_create.pyindex 5165df2f01..ff19b518ea 100644--- a/saleor/graphql/account/tests/mutations/staff/test_staff_create.py+++ b/saleor/graphql/account/tests/mutations/staff/test_staff_create.py@@ -3,7 +3,6 @@ from unittest.mock import call, patchfrom urllib.parse import urlencodeimport graphene-from django.contrib.auth.tokens import default_token_generatorfrom django.utils.functional import SimpleLazyObjectfrom freezegun import freeze_time@@ -12,6 +11,7 @@ from ......account.models import Group, Userfrom ......account.notifications import get_default_user_payloadfrom ......core.notify import NotifyEventTypefrom ......core.tests.utils import get_site_context_payload+from ......core.tokens import token_generatorfrom ......core.utils.json_serializer import CustomJsonEncoderfrom ......core.utils.url import prepare_urlfrom ......webhook.event_types import WebhookEventAsyncType@@ -121,7 +121,7 @@ def test_staff_create(assert len(groups) == 1assert {perm["code"].lower() for perm in groups[0]["permissions"]} == expected_perms- token = default_token_generator.make_token(staff_user)+ token = token_generator.make_token(staff_user)params = urlencode({"email": email, "token": token})password_set_url = prepare_url(params, redirect_url)expected_payload = {@@ -375,7 +375,7 @@ def test_staff_create_out_of_scope_group(assert len(groups) == 2for group in expected_groups:assert group in groups- token = default_token_generator.make_token(staff_user)+ token = token_generator.make_token(staff_user)params = urlencode({"email": email, "token": token})password_set_url = prepare_url(params, redirect_url)expected_payload = {@@ -416,7 +416,7 @@ def test_staff_create_send_password_with_url(staff_user = User.objects.get(email=email)assert staff_user.is_staff- token = default_token_generator.make_token(staff_user)+ token = token_generator.make_token(staff_user)params = urlencode({"email": email, "token": token})password_set_url = prepare_url(params, redirect_url)expected_payload = {diff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.pyindex 5d3a96e78c..6de82aa123 100644--- a/saleor/plugins/webhook/tests/test_webhook.py+++ b/saleor/plugins/webhook/tests/test_webhook.py@@ -11,7 +11,6 @@ import grapheneimport pytestfrom celery.exceptions import MaxRetriesExceededErrorfrom celery.exceptions import Retry as CeleryTaskRetryError-from django.contrib.auth.tokens import default_token_generatorfrom django.contrib.sites.models import Sitefrom django.core.serializers import serializefrom freezegun import freeze_time@@ -30,6 +29,7 @@ from ....core import EventDeliveryStatusfrom ....core.models import EventDelivery, EventDeliveryAttempt, EventPayloadfrom ....core.notification.utils import get_site_contextfrom ....core.notify import NotifyEventType+from ....core.tokens import token_generatorfrom ....core.utils.url import prepare_urlfrom ....discount import DiscountType, DiscountValueType, RewardType, RewardValueTypefrom ....discount.interface import VariantPromotionRuleInfo@@ -1685,7 +1685,7 @@ def test_notify_user(redirect_url = "http://redirect.com/"send_account_confirmation(customer_user, redirect_url, manager, channel_USD.slug)- token = default_token_generator.make_token(customer_user)+ token = token_generator.make_token(customer_user)params = urlencode({"email": customer_user.email, "token": token})confirm_url = prepare_url(params, redirect_url)diff --git a/saleor/settings.py b/saleor/settings.pyindex 7fea43e892..511b058633 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -1017,6 +1017,8 @@ ENABLE_LIMITING_WEBHOOKS_FOR_IDENTICAL_PAYLOADS = get_bool_from_env(TRANSACTION_ITEMS_LIMIT = 100+TOKEN_GENERATOR_CLASS = "django.contrib.auth.tokens.PasswordResetTokenGenerator"+# Disable Django warnings regarding too long cache keys being incompatible with# memcached to avoid leaking key values.warnings.filterwarnings("ignore", category=CacheKeyWarning)