From ca0c8aefb6bc5bfaafaa3b6c41a5ab82c5b4dbae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Wed, 4 Dec 2024 17:18:02 +0300 Subject: [PATCH 1/4] Update Django dependency to version 5.1.5 --- .pre-commit-config.yaml | 2 +- aggregator/migrations/0004_add_local_django_community.py | 2 +- aggregator/models.py | 2 +- requirements/common.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 483be96a4..a89afbda5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,7 +36,7 @@ repos: rev: "1.22.2" hooks: - id: django-upgrade - args: [--target-version, "5.0"] + args: [--target-version, "5.1"] - repo: https://github.com/psf/black rev: 24.10.0 hooks: diff --git a/aggregator/migrations/0004_add_local_django_community.py b/aggregator/migrations/0004_add_local_django_community.py index 0b65e2c8e..c64259331 100644 --- a/aggregator/migrations/0004_add_local_django_community.py +++ b/aggregator/migrations/0004_add_local_django_community.py @@ -29,6 +29,6 @@ class Migration(migrations.Migration): ), migrations.AddConstraint( model_name='localdjangocommunity', - constraint=models.CheckConstraint(check=models.Q(models.Q(('event_site_url__isnull', False), ('website_url__isnull', False)), models.Q(('event_site_url__isnull', False), ('website_url__isnull', True)), models.Q(('event_site_url__isnull', True), ('website_url__isnull', False)), _connector='OR'), name='website_url_and_or_event_site_url'), + constraint=models.CheckConstraint(condition=models.Q(models.Q(('event_site_url__isnull', False), ('website_url__isnull', False)), models.Q(('event_site_url__isnull', False), ('website_url__isnull', True)), models.Q(('event_site_url__isnull', True), ('website_url__isnull', False)), _connector='OR'), name='website_url_and_or_event_site_url'), ), ] diff --git a/aggregator/models.py b/aggregator/models.py index cb8bc403b..9087b3a04 100644 --- a/aggregator/models.py +++ b/aggregator/models.py @@ -229,7 +229,7 @@ class Meta: verbose_name_plural = _("Local Django Communities") constraints = [ models.CheckConstraint( - check=( + condition=( models.Q(website_url__isnull=False, event_site_url__isnull=False) | models.Q(website_url__isnull=True, event_site_url__isnull=False) | models.Q(website_url__isnull=False, event_site_url__isnull=True) diff --git a/requirements/common.txt b/requirements/common.txt index aab92801d..60a92072a 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -7,7 +7,7 @@ django-push @ git+https://github.com/brutasse/django-push.git@22fda99641cfbd2f30 django-read-only==1.18.0 django-recaptcha==4.0.0 django-registration-redux==2.13 -Django==5.0.11 +Django==5.1.5 docutils==0.21.2 feedparser==6.0.11 Jinja2==3.1.5 From 1035c60dd0e7e4a2e6f605f1c69a3cbfda97548f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Tue, 21 Jan 2025 21:45:31 +0300 Subject: [PATCH 2/4] Remove PBKDF2WrappedSHA1PasswordHasher hasher https://github.com/django/djangoproject.com/issues/1633#issuecomment-2605472773 --- accounts/hashers.py | 12 ----------- .../migrations/0002_migrate_sha1_passwords.py | 14 +------------ accounts/test_hashers.py | 21 ------------------- djangoproject/settings/common.py | 5 ----- 4 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 accounts/hashers.py delete mode 100644 accounts/test_hashers.py diff --git a/accounts/hashers.py b/accounts/hashers.py deleted file mode 100644 index 59d0d7e17..000000000 --- a/accounts/hashers.py +++ /dev/null @@ -1,12 +0,0 @@ -from django.contrib.auth.hashers import PBKDF2PasswordHasher, SHA1PasswordHasher - - -class PBKDF2WrappedSHA1PasswordHasher(PBKDF2PasswordHasher): - algorithm = "pbkdf2_wrapped_sha1" - - def encode_sha1_hash(self, sha1_hash, salt, iterations=None): - return super().encode(sha1_hash, salt, iterations) - - def encode(self, password, salt, iterations=None): - _, _, sha1_hash = SHA1PasswordHasher().encode(password, salt).split("$", 2) - return self.encode_sha1_hash(sha1_hash, salt, iterations) diff --git a/accounts/migrations/0002_migrate_sha1_passwords.py b/accounts/migrations/0002_migrate_sha1_passwords.py index 3aa786b4a..31cdb19e4 100644 --- a/accounts/migrations/0002_migrate_sha1_passwords.py +++ b/accounts/migrations/0002_migrate_sha1_passwords.py @@ -1,17 +1,5 @@ from django.db import migrations -from ..hashers import PBKDF2WrappedSHA1PasswordHasher - - -def forwards_func(apps, schema_editor): - User = apps.get_model("auth", "User") - users = User.objects.filter(password__startswith="sha1$") - hasher = PBKDF2WrappedSHA1PasswordHasher() - for user in users: - algorithm, salt, sha1_hash = user.password.split("$", 2) - user.password = hasher.encode_sha1_hash(sha1_hash, salt) - user.save(update_fields=["password"]) - class Migration(migrations.Migration): @@ -21,5 +9,5 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(forwards_func), + migrations.RunPython(migrations.RunPython.noop), ] diff --git a/accounts/test_hashers.py b/accounts/test_hashers.py deleted file mode 100644 index 1cd73d05c..000000000 --- a/accounts/test_hashers.py +++ /dev/null @@ -1,21 +0,0 @@ -from django.test import SimpleTestCase - -from .hashers import PBKDF2WrappedSHA1PasswordHasher - - -class TestHasher(SimpleTestCase): - def test(self): - iterations = 10 # low value for testing - password = "a" - sha1_encoded = "sha1$YoBzLZeL3w2R$757b56ad30c5fac1b552f58ad3acfddb07b674e2" - expected_pbkdf2_encoded = ( - "pbkdf2_wrapped_sha1$10$YoBzLZeL3w2R$djfB2Y51/" - "PwFdzcMoIlwUXglb2wMBz2L+LZ8Hjs2wnk=" - ) - _, salt, sha1_hash = sha1_encoded.split("$", 3) - hasher = PBKDF2WrappedSHA1PasswordHasher() - pbkdf2_hash = hasher.encode_sha1_hash(sha1_hash, salt, iterations) - self.assertEqual(pbkdf2_hash, expected_pbkdf2_encoded) - self.assertEqual( - hasher.encode(password, salt, iterations), expected_pbkdf2_encoded - ) diff --git a/djangoproject/settings/common.py b/djangoproject/settings/common.py index 3c7dd4ffb..7ba635b60 100644 --- a/djangoproject/settings/common.py +++ b/djangoproject/settings/common.py @@ -157,11 +157,6 @@ "django_hosts.middleware.HostsResponseMiddleware", ] -PASSWORD_HASHERS = [ - "django.contrib.auth.hashers.PBKDF2PasswordHasher", - "accounts.hashers.PBKDF2WrappedSHA1PasswordHasher", -] - ROOT_URLCONF = "djangoproject.urls.www" SECRET_KEY = str(SECRETS["secret_key"]) From c4baca9dc613a52af3b1a6a0f7675f7f3f4762dc Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Wed, 22 Jan 2025 13:36:36 +0100 Subject: [PATCH 3/4] Fixed TracDBCreateDatabaseMixin after 5.1 update --- tracdb/testutils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tracdb/testutils.py b/tracdb/testutils.py index 1d15d48cc..8ac6192e8 100644 --- a/tracdb/testutils.py +++ b/tracdb/testutils.py @@ -36,6 +36,7 @@ def _replace_primary_key_field_with_autofield(model, schema_editor): new `testid` autofield. This makes the models easier to manipulate in the tests. """ old_pk_field = _get_pk_field(model) + del old_pk_field.unique new_pk_field = deepcopy(old_pk_field) new_pk_field.primary_key = False schema_editor.alter_field( From 91c92e587d094419605da0457c790709901577b8 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Wed, 22 Jan 2025 15:10:17 +0100 Subject: [PATCH 4/4] Add comment to rewritten migration --- accounts/migrations/0002_migrate_sha1_passwords.py | 1 + 1 file changed, 1 insertion(+) diff --git a/accounts/migrations/0002_migrate_sha1_passwords.py b/accounts/migrations/0002_migrate_sha1_passwords.py index 31cdb19e4..191170be7 100644 --- a/accounts/migrations/0002_migrate_sha1_passwords.py +++ b/accounts/migrations/0002_migrate_sha1_passwords.py @@ -9,5 +9,6 @@ class Migration(migrations.Migration): ] operations = [ + # See git history of this file for why this migration is empty migrations.RunPython(migrations.RunPython.noop), ]