Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
fix: move all risky usages of set_password() (#18890)
Mikail372d083b8132
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8ae82bef06..92d40fe31c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -41,6 +41,7 @@ Validation is now performed on the frontend (Dashboard). This change increases v- Add optional usage telemetry. - #18789 by @wcislo-saleor- The app can now be installed without providing a `tokenTargetUrl` in the manifest file.- Removed the setting `JWT_EXPIRE` which allowed to configure Saleor to ignore the JWT token expiration. - #18856 by @NyanKiyoshi+- Removed support for custom `User` DB models in `./manage.py createsuperuser` command. - #18890 by @NyanKiyoshi#### Search improvementsdiff --git a/saleor/account/management/commands/createsuperuser.py b/saleor/account/management/commands/createsuperuser.pyindex 9531fc4c97..b7dbba41d3 100644--- a/saleor/account/management/commands/createsuperuser.py+++ b/saleor/account/management/commands/createsuperuser.py@@ -8,13 +8,15 @@ import getpassimport osimport sys-from django.contrib.auth import get_user_modelfrom django.contrib.auth.password_validation import validate_passwordfrom django.core import exceptionsfrom django.core.management.base import BaseCommand, CommandErrorfrom django.db import DEFAULT_DB_ALIASfrom django.utils.text import capfirst+from ...models import User+from ...tests.fixtures.user import dangerously_get_or_create_superuser+class NotRunningInTTYException(Exception):pass@@ -30,14 +32,11 @@ class Command(BaseCommand):def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)- self.UserModel = get_user_model()- self.username_field = self.UserModel._meta.get_field(- self.UserModel.USERNAME_FIELD- )+ self.username_field = User._meta.get_field(User.USERNAME_FIELD)def add_arguments(self, parser):parser.add_argument(- f"--{self.UserModel.USERNAME_FIELD}",+ f"--{User.USERNAME_FIELD}",help="Specifies the login for the superuser.",)parser.add_argument(@@ -47,7 +46,7 @@ class Command(BaseCommand):dest="interactive",help=("Tells Django to NOT prompt the user for input of any kind. "- f"You must use --{self.UserModel.USERNAME_FIELD} with --noinput, along "+ f"You must use --{User.USERNAME_FIELD} with --noinput, along ""with an option for any other required field. Superusers created with ""--noinput will not be able to log in until they're given a valid ""password."@@ -58,8 +57,8 @@ class Command(BaseCommand):default=DEFAULT_DB_ALIAS,help='Specifies the database to use. Default is "default".',)- for field_name in self.UserModel.REQUIRED_FIELDS:- field = self.UserModel._meta.get_field(field_name)+ for field_name in User.REQUIRED_FIELDS:+ field = User._meta.get_field(field_name)if field.many_to_many:if (field.remote_field.through@@ -88,12 +87,12 @@ class Command(BaseCommand):return super().execute(*args, **options)def handle(self, *args, **options):- username = options[self.UserModel.USERNAME_FIELD]+ username = options[User.USERNAME_FIELD]database = options["database"]user_data = {}verbose_field_name = self.username_field.verbose_nametry:- self.UserModel._meta.get_field(PASSWORD_FIELD)+ User._meta.get_field(PASSWORD_FIELD)except exceptions.FieldDoesNotExist:passelse:@@ -134,15 +133,15 @@ class Command(BaseCommand):self.stderr.write(error_msg)username = Nonecontinue- user_data[self.UserModel.USERNAME_FIELD] = username- fake_user_data[self.UserModel.USERNAME_FIELD] = (+ user_data[User.USERNAME_FIELD] = username+ fake_user_data[User.USERNAME_FIELD] = (self.username_field.remote_field.model(username)if self.username_field.remote_fieldelse username)# Prompt for required fields.- for field_name in self.UserModel.REQUIRED_FIELDS:- field = self.UserModel._meta.get_field(field_name)+ for field_name in User.REQUIRED_FIELDS:+ field = User._meta.get_field(field_name)user_data[field_name] = options[field_name]while user_data[field_name] is None:message = self._get_input_message(field)@@ -178,7 +177,7 @@ class Command(BaseCommand):# Don't validate blank passwords.continuetry:- validate_password(password2, self.UserModel(**fake_user_data))+ validate_password(password2, User(**fake_user_data))except exceptions.ValidationError as err:self.stderr.write("\n".join(err.messages))response = input(@@ -199,11 +198,11 @@ class Command(BaseCommand):# options.if username is None:username = os.environ.get(- "DJANGO_SUPERUSER_" + self.UserModel.USERNAME_FIELD.upper()+ "DJANGO_SUPERUSER_" + User.USERNAME_FIELD.upper())if username is None:raise CommandError(- f"You must use --{self.UserModel.USERNAME_FIELD} with --noinput."+ f"You must use --{User.USERNAME_FIELD} with --noinput.")error_msg = self._validate_username(username, verbose_field_name, database@@ -211,22 +210,25 @@ class Command(BaseCommand):if error_msg:raise CommandError(error_msg)- user_data[self.UserModel.USERNAME_FIELD] = username- for field_name in self.UserModel.REQUIRED_FIELDS:+ user_data[User.USERNAME_FIELD] = username+ for field_name in User.REQUIRED_FIELDS:env_var = "DJANGO_SUPERUSER_" + field_name.upper()value = options[field_name] or os.environ.get(env_var)if not value:raise CommandError(f"You must use --{field_name} with --noinput.")- field = self.UserModel._meta.get_field(field_name)+ field = User._meta.get_field(field_name)user_data[field_name] = field.clean(value, None)- self.UserModel._default_manager.db_manager(database).create_superuser(- **user_data- )- if options["verbosity"] >= 1:+ _superuser, created = dangerously_get_or_create_superuser(**user_data)+ if created:self.stdout.write("Superuser created successfully.")+ else:+ self.stderr.write(+ "The operation was aborted: user already exists in database."+ )+ sys.exit(1)except KeyboardInterrupt:self.stderr.write("\nOperation cancelled.")sys.exit(1)@@ -269,10 +271,8 @@ class Command(BaseCommand):"""Validate username. If invalid, return a string error message."""if self.username_field.unique:try:- self.UserModel._default_manager.db_manager(database).get_by_natural_key(- username- )- except self.UserModel.DoesNotExist:+ User._default_manager.db_manager(database).get_by_natural_key(username)+ except User.DoesNotExist:passelse:return f"Error: That {verbose_field_name} is already taken."diff --git a/saleor/account/models.py b/saleor/account/models.pyindex 9eb10b9324..4aa440ac83 100644--- a/saleor/account/models.py+++ b/saleor/account/models.py@@ -125,32 +125,6 @@ class Address(ModelWithMetadata):class UserManager(BaseUserManager["User"]):- def create_user(- self, email, password=None, is_staff=False, is_active=True, **extra_fields- ):- """Create a user instance with the given email and password."""- email = UserManager.normalize_email(email)- # Google OAuth2 backend send unnecessary username field- extra_fields.pop("username", None)-- user = self.model(- email=email, is_active=is_active, is_staff=is_staff, **extra_fields- )- if password:- user.set_password(password)- user.save()- return user-- def create_superuser(self, email, password=None, **extra_fields):- user = self.create_user(- email, password, is_staff=True, is_superuser=True, **extra_fields- )- group, created = Group.objects.get_or_create(name="Full Access")- if created:- group.permissions.add(*get_permissions())- group.user_set.add(user)- return user-def customers(self):orders = Order.objects.values("user_id")return self.get_queryset().filter(diff --git a/saleor/account/tests/fixtures/user.py b/saleor/account/tests/fixtures/user.pyindex d7f67f2b71..9ccf7bba69 100644--- a/saleor/account/tests/fixtures/user.py+++ b/saleor/account/tests/fixtures/user.py@@ -1,12 +1,65 @@+from typing import Any+import pytest-from ....account.models import User+from ....account.models import Group, User, UserManager+from ....permission.enums import get_permissions+++def dangerously_get_or_create_superuser(+ email: str, password: str | None = None, **extra_fields: Any+) -> tuple[User, bool]:+ """Create a superuser for unittests with the given email and password.++ This should never be called for production use (due to lack of+ validation).+ """+ if user := User.objects.filter(email=email).first():+ return user, False+ user = dangerously_create_test_user(+ email=email, password=password, is_staff=True, is_superuser=True, **extra_fields+ )+ group, group_created = Group.objects.get_or_create(name="Full Access")+ if group_created:+ group.permissions.add(*get_permissions())+ group.user_set.add(user)+ return user, True+++def dangerously_create_test_user(+ email, password=None, is_staff=False, is_active=True, **extra_fields+):+ """Create a user for unittests with the given email and password.++ This should never be called for production use (due to lack of+ validation).+ """+ email = UserManager.normalize_email(email)+ # Google OAuth2 backend send unnecessary username field+ extra_fields.pop("username", None)++ user = User(email=email, is_active=is_active, is_staff=is_staff, **extra_fields)+ if password:+ # Semgrep rule that verifies whether the user's password is validated before+ # calling `user.set_password()` is being silenced due to this function being+ # voluntarily insecure and being dedicated for unit-testing only.+ # We might change that in the future by requiring tests to always provide+ # a strong password.+ # For now, it's wrapped around a function name "dangerously_[...]" and being+ # put inside a 'tests' namespace (saleor.account.tests.fixtures.user)+ # in order to minimize as much as possible the risk of someone using that+ # insecure function.+ user.set_password( # nosemgrep: python.django.security.audit.unvalidated-password.unvalidated-password+ password+ )+ user.save()+ return user@pytest.fixturedef customer_user(address): # pylint: disable=W0613default_address = address.get_copy()- user = User.objects.create_user(+ user = dangerously_create_test_user("password",default_billing_address=default_address,@@ -25,7 +78,7 @@ def customer_user(address): # pylint: disable=W0613@pytest.fixturedef customer_user2(address):default_address = address.get_copy()- user = User.objects.create_user(+ user = dangerously_create_test_user("password",default_billing_address=default_address,@@ -42,7 +95,7 @@ def customer_user2(address):@pytest.fixturedef customer_users(address, customer_user, customer_user2):default_address = address.get_copy()- customer_user3 = User.objects.create_user(+ customer_user3 = dangerously_create_test_user("password",default_billing_address=default_address,@@ -59,7 +112,7 @@ def customer_users(address, customer_user, customer_user2):@pytest.fixturedef admin_user(db):"""Return a Django admin user."""- return User.objects.create_user(+ return dangerously_create_test_user("password",is_staff=True,@@ -71,7 +124,7 @@ def admin_user(db):@pytest.fixturedef staff_user(db):"""Return a staff member."""- return User.objects.create_user(+ return dangerously_create_test_user(email="[email protected]",password="password",is_staff=True,diff --git a/saleor/account/tests/test_utils.py b/saleor/account/tests/test_utils.pyindex 0d358d2d63..e1fe5dd84e 100644--- a/saleor/account/tests/test_utils.py+++ b/saleor/account/tests/test_utils.py@@ -16,6 +16,7 @@ from ..utils import (send_user_event,store_user_address,)+from .fixtures.user import dangerously_create_test_userdef test_remove_staff_member_with_orders(staff_user, permission_manage_products, order):@@ -68,7 +69,7 @@ def test_is_user_address_limit_reached_false(customer_user, address):def test_store_user_address_uses_existing_one(address):- user = User.objects.create_user("[email protected]", "password")+ user = dangerously_create_test_user("[email protected]", "password")user.addresses.add(address)expected_user_addresses_count = 1@@ -82,7 +83,7 @@ def test_store_user_address_uses_existing_one(address):def test_store_user_address_uses_existing_one_despite_duplicated(address):same_address = Address.objects.create(**address.as_data())- user = User.objects.create_user("[email protected]", "password")+ user = dangerously_create_test_user("[email protected]", "password")user.addresses.set([address, same_address])expected_user_addresses_count = 2@@ -95,7 +96,7 @@ def test_store_user_address_uses_existing_one_despite_duplicated(address):def test_store_user_address_create_new_address_if_not_associated(address):- user = User.objects.create_user("[email protected]", "password")+ user = dangerously_create_test_user("[email protected]", "password")expected_user_addresses_count = 1manager = get_plugins_manager(allow_replica=False)@@ -109,7 +110,7 @@ def test_store_user_address_create_new_address_if_not_associated(address):def test_store_user_address_address_not_saved(address):"""Test that the address count does never exceeds the limit."""same_address = Address.objects.create(**address.as_data())- user = User.objects.create_user("[email protected]", "password")+ user = dangerously_create_test_user("[email protected]", "password")user.addresses.set([address, same_address])address_count = user.addresses.count()diff --git a/saleor/account/utils.py b/saleor/account/utils.pyindex 34c16d1b42..1e332231cb 100644--- a/saleor/account/utils.py+++ b/saleor/account/utils.py@@ -129,20 +129,6 @@ def change_user_default_address(set_user_default_shipping_address(user, address)-def create_superuser(credentials):- user, created = User.objects.get_or_create(- email=credentials["email"],- defaults={"is_active": True, "is_staff": True, "is_superuser": True},- )- if created:- user.set_password(credentials["password"])- user.save()- msg = f"Superuser - {credentials['email']}/{credentials['password']}"- else:- msg = f"Superuser already exists - {credentials['email']}"- return msg--def remove_staff_member(staff):"""Remove staff member account only if it has no orders placed.diff --git a/saleor/core/management/commands/populatedb.py b/saleor/core/management/commands/populatedb.pyindex 748d180794..6efc93fb8c 100644--- a/saleor/core/management/commands/populatedb.py+++ b/saleor/core/management/commands/populatedb.py@@ -5,7 +5,7 @@ from django.core.management import call_commandfrom django.core.management.base import BaseCommandfrom django.db import connection-from ....account.utils import create_superuser+from ....account.tests.fixtures.user import dangerously_get_or_create_superuserfrom ...utils.random_data import (add_address_to_admin,create_catalogue_promotions,@@ -83,6 +83,7 @@ class Command(BaseCommand):user_password = options["user_password"]staff_password = options["staff_password"]superuser_password = options["superuser_password"]+ superuser_email = "[email protected]"create_images = not options["withoutimages"]for msg in create_channels():@@ -123,13 +124,20 @@ class Command(BaseCommand):self.stdout.write(msg)if options["createsuperuser"]:- credentials = {- "email": "[email protected]",- "password": superuser_password,- }- msg = create_superuser(credentials)- self.stdout.write(msg)- add_address_to_admin(credentials["email"])+ superuser, created = dangerously_get_or_create_superuser(+ email=superuser_email,+ password=superuser_password,+ )+ if created:+ self.stdout.write(+ f"Superuser created successfully: "+ f"{superuser.email}, password: {superuser_password}"+ )+ else:+ self.stderr.write(+ f"Superuser already exists in database ({superuser.email})"+ )+ add_address_to_admin(superuser.email)if not options["skipsequencereset"]:self.sequence_reset()diff --git a/saleor/core/tests/test_core.py b/saleor/core/tests/test_core.pyindex ed9f284f14..949bef9614 100644--- a/saleor/core/tests/test_core.py+++ b/saleor/core/tests/test_core.py@@ -6,9 +6,10 @@ from django.core.management import CommandError, call_commandfrom django.db.utils import DataErrorfrom django.templatetags.static import staticfrom django.test import RequestFactory, override_settings+from django.utils.crypto import get_random_stringfrom ...account.models import Address, User-from ...account.utils import create_superuser+from ...account.tests.fixtures.user import dangerously_get_or_create_superuserfrom ...attribute.models import AttributeValuefrom ...channel.models import Channelfrom ...discount.models import (@@ -68,16 +69,19 @@ def test_get_client_ip(ip_address, expected_ip):def test_create_superuser(db, client, media_root):- credentials = {"email": "[email protected]", "password": "admin"}+ credentials = {+ "email": "[email protected]",+ "password": get_random_string(length=50),+ }# Test admin creationassert User.objects.all().count() == 0- create_superuser(credentials)+ dangerously_get_or_create_superuser(**credentials)assert User.objects.all().count() == 1admin = User.objects.all().first()assert admin.is_superuserassert not admin.avatar# Test duplicating- create_superuser(credentials)+ dangerously_get_or_create_superuser(**credentials)assert User.objects.all().count() == 1@@ -107,7 +111,7 @@ def test_create_channels_with_default_channel_slug(db):def test_create_fake_user(db):assert User.objects.all().count() == 0- random_data.create_fake_user("password")+ random_data.create_fake_user(get_random_string(length=50))assert User.objects.all().count() == 1user = User.objects.all().first()assert not user.is_superuser@@ -115,7 +119,7 @@ def test_create_fake_user(db):def test_create_fake_users(db):how_many = 5- for _ in random_data.create_users("password", how_many):+ for _ in random_data.create_users(get_random_string(length=50), how_many):passassert User.objects.all().count() == 5@@ -135,7 +139,7 @@ def test_create_fake_order(db, monkeypatch, image, media_root, warehouse):passfor _ in random_data.create_shipping_zones():pass- for _ in random_data.create_users("password", 3):+ for _ in random_data.create_users(get_random_string(length=50), 3):passfor _ in random_data.create_page_type():passdiff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex e730cb94f3..3acf33b048 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -13,6 +13,7 @@ from unittest.mock import patchimport graphenefrom django.conf import settings+from django.contrib.auth import password_validationfrom django.core.files import Filefrom django.db import connectionfrom django.db.models import F@@ -27,6 +28,7 @@ from ...account.models import Address, Group, Userfrom ...account.search import (update_user_search_vector,)+from ...account.tests.fixtures.user import dangerously_create_test_userfrom ...account.utils import store_user_addressfrom ...app.models import Appfrom ...attribute.models import (@@ -557,6 +559,7 @@ def create_fake_user(user_password, save=True, generate_id=False):)if save:+ password_validation.validate_password(user_password, user)user.set_password(user_password)user.save()user.addresses.add(address)@@ -1169,7 +1172,7 @@ def _create_staff_user(staff_password, email=None, superuser=False):if staff_user:return staff_user- staff_user = User.objects.create_user(+ staff_user = dangerously_create_test_user(first_name=first_name,last_name=last_name,email=email,diff --git a/saleor/graphql/account/mutations/account/account_register.py b/saleor/graphql/account/mutations/account/account_register.pyindex b8a22a1734..2af68a8ca4 100644--- a/saleor/graphql/account/mutations/account/account_register.py+++ b/saleor/graphql/account/mutations/account/account_register.py@@ -226,7 +226,12 @@ class AccountRegister(DeprecatedModelMutation):@classmethoddef save_and_create_task(cls, user_exists, instance, cleaned_input, context_data):- instance.set_password(cleaned_input["password"])+ instance.set_password(+ # nosemgrep: python.django.security.audit.unvalidated-password.unvalidated-password+ # Password is being validated via cls.clean_input(), which correctly invokes+ # django.contrib.auth.password_validation.validate_password()+ cleaned_input["password"]+ )instance.is_confirmed = Falseuser_created = Falsediff --git a/saleor/graphql/account/tests/mutations/authentication/test_set_password.py b/saleor/graphql/account/tests/mutations/authentication/test_set_password.pyindex 185c14e4f6..777c78dab6 100644--- a/saleor/graphql/account/tests/mutations/authentication/test_set_password.py+++ b/saleor/graphql/account/tests/mutations/authentication/test_set_password.py@@ -4,7 +4,7 @@ from freezegun import freeze_timefrom ......account import events as account_eventsfrom ......account.error_codes import AccountErrorCode-from ......account.models import User+from ......account.tests.fixtures.user import dangerously_create_test_userfrom ......core.tokens import token_generatorfrom .....core.utils import str_to_enumfrom .....tests.utils import get_graphql_content@@ -38,7 +38,7 @@ def test_set_password(mocked_cache, user_api_client, setup_mock_for_cache):# givensetup_mock_for_cache({}, mocked_cache)- customer_user = User.objects.create_user(+ customer_user = dangerously_create_test_user(email="[email protected]", password="old-password")token = token_generator.make_token(customer_user)@@ -74,7 +74,7 @@ def test_set_password_confirm_user_and_match_orders(# givensetup_mock_for_cache({}, mocked_cache)- customer_user = User.objects.create_user(+ customer_user = dangerously_create_test_user(email="[email protected]",password="old-password",is_confirmed=False,diff --git a/saleor/graphql/account/tests/mutations/permission_group/test_permission_group_update.py b/saleor/graphql/account/tests/mutations/permission_group/test_permission_group_update.pyindex ecf5fc8852..ec0a7041d2 100644--- a/saleor/graphql/account/tests/mutations/permission_group/test_permission_group_update.py+++ b/saleor/graphql/account/tests/mutations/permission_group/test_permission_group_update.py@@ -6,7 +6,8 @@ from django.utils.functional import SimpleLazyObjectfrom freezegun import freeze_timefrom ......account.error_codes import PermissionGroupErrorCode-from ......account.models import Group, User+from ......account.models import Group+from ......account.tests.fixtures.user import dangerously_create_test_userfrom ......channel.models import Channelfrom ......core.utils.json_serializer import CustomJsonEncoderfrom ......permission.enums import AccountPermissions, AppPermission, OrderPermissions@@ -1175,7 +1176,7 @@ def test_permission_group_update_mutation_out_of_scope_users(permission_manage_products,):staff_user = staff_users[0]- staff_user3 = User.objects.create_user(+ staff_user3 = dangerously_create_test_user(email="[email protected]",password="password",is_staff=True,diff --git a/saleor/graphql/account/tests/queries/test_customers_where_filtering.py b/saleor/graphql/account/tests/queries/test_customers_where_filtering.pyindex e538ba2f36..7dbc40ce9a 100644--- a/saleor/graphql/account/tests/queries/test_customers_where_filtering.py+++ b/saleor/graphql/account/tests/queries/test_customers_where_filtering.py@@ -6,6 +6,7 @@ from django.utils import timezonefrom freezegun import freeze_timefrom .....account.models import Address, User+from .....account.tests.fixtures.user import dangerously_create_test_userfrom .....order import OrderOriginfrom ....tests.utils import get_graphql_content@@ -94,7 +95,7 @@ def test_customers_filter_by_date_joined():# givenwith freeze_time((timezone.now() - datetime.timedelta(days=5)).isoformat()):- customer_2 = User.objects.create_user(+ customer_2 = dangerously_create_test_user("password",first_name="Leslie",@@ -102,7 +103,7 @@ def test_customers_filter_by_date_joined()with freeze_time((timezone.now() - datetime.timedelta(days=2)).isoformat()):- customer_3 = User.objects.create_user(+ customer_3 = dangerously_create_test_user("password",first_name="John",diff --git a/saleor/graphql/account/tests/test_account_utils.py b/saleor/graphql/account/tests/test_account_utils.pyindex 00510f0257..e33118c61a 100644--- a/saleor/graphql/account/tests/test_account_utils.py+++ b/saleor/graphql/account/tests/test_account_utils.py@@ -1,4 +1,5 @@from ....account.models import Group, User+from ....account.tests.fixtures.user import dangerously_create_test_userfrom ....app.models import Appfrom ....channel.models import Channelfrom ....permission.enums import (@@ -395,7 +396,7 @@ def test_get_out_of_scope_users_user_has_rights_to_manage_all_users():staff_user1 = staff_users[0]staff_user2 = staff_users[1]- staff_user3 = User.objects.create_user(+ staff_user3 = dangerously_create_test_user(email="[email protected]",password="password",is_staff=True,@@ -447,7 +448,7 @@ def test_get_out_of_scope_users_return_some_users():staff_user1 = staff_users[0]staff_user2 = staff_users[1]- staff_user3 = User.objects.create_user(+ staff_user3 = dangerously_create_test_user(email="[email protected]",password="password",is_staff=True,diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.pyindex fa082e0dac..8974e9d6bd 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py@@ -6,7 +6,7 @@ from django.test import override_settingsfrom django.utils import timezonefrom freezegun import freeze_time-from .....account.models import User+from .....account.tests.fixtures.user import dangerously_create_test_userfrom .....checkout.actions import call_checkout_eventfrom .....checkout.error_codes import CheckoutErrorCodefrom .....core.models import EventDelivery@@ -257,7 +257,7 @@ def test_checkout_customer_attach_user_to_checkout_with_user("""default_address = address.get_copy()- second_user = User.objects.create_user(+ second_user = dangerously_create_test_user("password",default_billing_address=default_address,diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.pyindex ce8e218799..54b4450f23 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py@@ -5,7 +5,7 @@ from django.test import override_settingsfrom django.utils import timezonefrom freezegun import freeze_time-from .....account.models import User+from .....account.tests.fixtures.user import dangerously_create_test_userfrom .....checkout.actions import call_checkout_eventfrom .....core.models import EventDeliveryfrom .....product.models import ProductChannelListing, ProductVariantChannelListing@@ -50,7 +50,7 @@ def test_checkout_customer_detach(user_api_client, checkout_with_item, customer_assert checkout.search_index_dirty is True# Mutation should fail when user calling it doesn't own the checkout.- other_user = User.objects.create_user("[email protected]", "password")+ other_user = dangerously_create_test_user("[email protected]", "password")checkout.user = other_usercheckout.save()response = user_api_client.post_graphql(diff --git a/saleor/graphql/csv/tests/queries/test_export_files.py b/saleor/graphql/csv/tests/queries/test_export_files.pyindex a68ac59505..3e146c0008 100644--- a/saleor/graphql/csv/tests/queries/test_export_files.py+++ b/saleor/graphql/csv/tests/queries/test_export_files.py@@ -3,7 +3,7 @@ import datetimeimport grapheneimport pytest-from .....account.models import User+from .....account.tests.fixtures.user import dangerously_create_test_userfrom .....app.models import Appfrom .....core import JobStatusfrom .....csv.models import ExportFile@@ -150,7 +150,7 @@ def test_filter_export_files_by_user(permission_manage_apps,staff_user,):- second_staff_user = User.objects.create_user(+ second_staff_user = dangerously_create_test_user(email="[email protected]",password="password",is_staff=True,diff --git a/saleor/graphql/tests/fixtures.py b/saleor/graphql/tests/fixtures.pyindex f2baadb220..e4219134cf 100644--- a/saleor/graphql/tests/fixtures.py+++ b/saleor/graphql/tests/fixtures.py@@ -12,6 +12,7 @@ from django.urls import reversefrom django.utils.functional import SimpleLazyObjectfrom ...account.models import User+from ...account.tests.fixtures.user import dangerously_create_test_userfrom ...core.jwt import create_access_tokenfrom ...plugins.manager import get_plugins_managerfrom ..utils import handled_errors_logger, unhandled_errors_logger@@ -209,7 +210,7 @@ def graphql_log_handler():@pytest.fixturedef superuser(db):- superuser = User.objects.create_user(+ superuser = dangerously_create_test_user("pass",is_staff=True,diff --git a/saleor/tests/e2e/conftest.py b/saleor/tests/e2e/conftest.pyindex edee632b54..c71f2472b7 100644--- a/saleor/tests/e2e/conftest.py+++ b/saleor/tests/e2e/conftest.py@@ -5,7 +5,7 @@ from django.core.serializers.json import DjangoJSONEncoderfrom django.test import TestCasefrom django.test.client import MULTIPART_CONTENT, Client-from ...account.models import User+from ...account.tests.fixtures.user import dangerously_create_test_userfrom ...app.models import Appfrom ...graphql.tests.fixtures import BaseApiClient@@ -47,7 +47,7 @@ class E2eApiClient(BaseApiClient):@pytest.fixturedef e2e_staff_api_client():- e2e_staff_user = User.objects.create_user(+ e2e_staff_user = dangerously_create_test_user(email="[email protected]",password="password",is_staff=True,@@ -59,7 +59,7 @@ def e2e_staff_api_client():@pytest.fixturedef e2e_logged_api_client():- e2e_customer = User.objects.create_user(+ e2e_customer = dangerously_create_test_user(email="[email protected]",password="password",first_name="Joe",@@ -87,7 +87,7 @@ def e2e_app_api_client():@pytest.fixturedef e2e_no_permission_staff_api_client():- e2e_no_permission_staff_user = User.objects.create_user(+ e2e_no_permission_staff_user = dangerously_create_test_user(email="[email protected]",password="password",is_staff=True,