Postpone 3.13 support for now

see #3350
This commit is contained in:
Antoine Nguyen
2024-11-28 16:36:07 +01:00
parent a076766f83
commit d3190cceef
6 changed files with 15 additions and 54 deletions
+5 -5
View File
@@ -72,7 +72,7 @@ jobs:
strategy:
matrix:
database: ['postgres', 'mysql']
python-version: [3.9, '3.10', '3.11', '3.12', '3.13']
python-version: [3.9, '3.10', '3.11', '3.12']
fail-fast: false
steps:
@@ -109,7 +109,7 @@ jobs:
pip install -r mysql-requirements.txt
echo "DB=mysql" >> $GITHUB_ENV
- name: Test with pytest
if: ${{ matrix.python-version != '3.13' || matrix.database != 'postgres' }}
if: ${{ matrix.python-version != '3.12' || matrix.database != 'postgres' }}
run: |
python ./tests.py
cd test_project
@@ -127,7 +127,7 @@ jobs:
OIDC_RSA_PRIVATE_KEY: ${{ vars.OIDC_RSA_PRIVATE_KEY }}
- name: Test with pytest and coverage
if: ${{ matrix.python-version == '3.13' && matrix.database == 'postgres' }}
if: ${{ matrix.python-version == '3.12' && matrix.database == 'postgres' }}
run: |
python ./tests.py
cd test_project
@@ -182,10 +182,10 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.13
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.13'
python-version: '3.12'
- name: Build frontend
shell: bash -l {0}
run: |
+2 -12
View File
@@ -1,4 +1,4 @@
from django.core.checks import register, Error, Info, Warning
from django.core.checks import register, Info, Warning
from django.conf import settings
from django.utils.translation import gettext as _
@@ -6,14 +6,6 @@ from modoboa.core.utils import generate_rsa_private_key
from modoboa.parameters.tools import get_global_parameter
from modoboa.core.password_hashers import get_password_hasher
EOO1 = Error(
_("The password scheme you use is not available anymore."),
hint=_(
"The password scheme you were using has been removed, please upgrade to a stronger one"
),
id="modoboa.EOO1",
)
W001 = Warning(
_(
"You have USE_TZ set to False, this may result in issues during "
@@ -59,8 +51,6 @@ def check_password_hasher(app_configs, **kwargs):
msgs = []
scheme_in_use = get_global_parameter("password_scheme", app="core")
hasher = get_password_hasher(scheme_in_use)
if not hasher.available:
msgs.append(EOO1)
elif hasher.deprecated:
if hasher.deprecated:
msgs.append(W002)
return msgs
+1 -9
View File
@@ -116,15 +116,7 @@ class User(AbstractUser):
"password_scheme", raise_exception=False
)
raw_value = smart_bytes(raw_value)
hasher = get_password_hasher(scheme.upper())()
if not hasher.available:
raise InternalError(
_(
"The configured password scheme (%s) is not available anymore. Please update your configuration"
)
% (scheme)
)
return hasher.encrypt(raw_value)
return get_password_hasher(scheme.upper())().encrypt(raw_value)
def set_password(self, raw_value: str, curvalue: Optional[str] = None) -> None:
"""Password update.
+2 -13
View File
@@ -6,10 +6,7 @@ Contains weak hashers (the original ones) available with Modoboa.
import base64
try:
import crypt
except ImportError:
crypt = None
import crypt
import hashlib
from random import Random
import string
@@ -69,10 +66,6 @@ class PasswordHasher(metaclass=MetaHasher):
return base64.b64encode(pwhash)
return pwhash
@property
def available(self) -> bool:
return True
def encrypt(self, clearvalue: str) -> str:
"""Encrypt a password.
@@ -113,7 +106,7 @@ class PasswordHasher(metaclass=MetaHasher):
@classmethod
def get_password_hashers(cls):
"""Return all the PasswordHasher supported by Modoboa"""
return [hasher for hasher in cls.__subclasses__() if hasher().available]
return [hasher for hasher in cls.__subclasses__()]
class PLAINHasher(PasswordHasher):
@@ -141,10 +134,6 @@ class CRYPTHasher(PasswordHasher):
_weak = True
deprecated = True
@property
def available(self) -> bool:
return crypt is not None
@property
def scheme(self):
return "{CRYPT}"
+1 -10
View File
@@ -16,7 +16,6 @@ except ImportError:
from modoboa.core import constants
from modoboa.core.password_hashers import get_password_hasher
from modoboa.core.password_hashers.utils import get_dovecot_schemes
from modoboa.lib.exceptions import InternalError
from modoboa.lib.tests import NO_SMTP, ModoTestCase
from .. import factories, models
@@ -253,17 +252,9 @@ class AuthenticationTestCase(ModoTestCase):
supported_schemes = get_dovecot_schemes()[0]
self.assertEqual(supported_schemes, ["{MD5-CRYPT}", "{PLAIN}"])
def test_unavailable_password_scheme(self):
self.set_global_parameter("password_scheme", "crypt")
def test_deprecated_password_scheme(self):
hasher = get_password_hasher("crypt")
self.assertEqual(hasher.label, "crypt (weak, deprecated)")
if hasher().available:
return
username = "user@test.com"
password = "toto"
user = models.User.objects.get(username=username)
with self.assertRaises(InternalError):
user.set_password(password)
def test_fido_auth_begin(self):
url = reverse("core:fido_auth_begin")
+4 -5
View File
@@ -6,7 +6,7 @@ from django.test.utils import override_settings
from modoboa.core import checks
from modoboa.lib.tests import SimpleModoTestCase
from modoboa.core.password_scheme.base import CRYPTHasher
from modoboa.core.password_hashers.base import CRYPTHasher
class CheckSessionCookieSecureTest(SimpleModoTestCase):
@@ -38,9 +38,8 @@ class CheckSessionCookieSecureTest(SimpleModoTestCase):
self.assertEqual(len(msgs), 0)
def test_password_hasher_checks(self):
msgs = checks.check_password_hasher(None)
self.assertEqual(msgs, [])
self.set_global_parameter("password_scheme", "crypt")
msgs = checks.check_password_hasher(None)
if CRYPTHasher().available:
self.assertEqual(msgs, [checks.W002])
else:
self.assertEqual(msgs, [checks.E001])
self.assertEqual(msgs, [checks.E001])