From 8800561abb60524bf2c8e49864dc0479524c0c84 Mon Sep 17 00:00:00 2001 From: Mathias Ertl Date: Sat, 28 Dec 2024 12:39:31 +0100 Subject: [PATCH] deprecate `django_ca.extensions.parse_extension` (unused). --- ca/django_ca/extensions/parse.py | 2 ++ .../tests/extensions/test_extension_values.py | 19 +++++++++++++------ .../extensions/test_unknown_extension.py | 6 +++++- docs/source/changelog/TBR_2.2.0.rst | 7 +++++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ca/django_ca/extensions/parse.py b/ca/django_ca/extensions/parse.py index 43de86b6e..6ece0b7b3 100644 --- a/ca/django_ca/extensions/parse.py +++ b/ca/django_ca/extensions/parse.py @@ -25,6 +25,7 @@ KEY_USAGE_NAMES, TLS_FEATURE_NAMES, ) +from django_ca.deprecation import RemovedInDjangoCA230Warning, deprecate_function from django_ca.typehints import ( CertificateExtension, CertificateExtensionType, @@ -295,6 +296,7 @@ def _parse_tls_feature(value: Iterable[Union[x509.TLSFeatureType, str]]) -> x509 return x509.TLSFeature(features=features) +@deprecate_function(RemovedInDjangoCA230Warning) def parse_extension( # noqa: PLR0912 # there's just many extensions key: str, value: Union[CertificateExtension, CertificateExtensionType, ParsableExtension] ) -> CertificateExtension: diff --git a/ca/django_ca/tests/extensions/test_extension_values.py b/ca/django_ca/tests/extensions/test_extension_values.py index 384ab331d..4e7faa9d0 100644 --- a/ca/django_ca/tests/extensions/test_extension_values.py +++ b/ca/django_ca/tests/extensions/test_extension_values.py @@ -28,6 +28,7 @@ from django_ca.constants import EXTENSION_DEFAULT_CRITICAL, ExtendedKeyUsageOID from django_ca.extensions import extension_as_text, parse_extension from django_ca.extensions.utils import extension_as_admin_html +from django_ca.tests.base.assertions import assert_removed_in_230 from django_ca.tests.base.utils import dns, rdn, uri from django_ca.typehints import ( CertificateExtension, @@ -70,16 +71,22 @@ def assert_parsed(key: str, serialized: Any, extension_type: CertificateExtensio CertificateExtension, x509.Extension(oid=oid, critical=EXTENSION_DEFAULT_CRITICAL[oid], value=extension_type), ) - assert parse_extension(key, {"value": serialized}) == ext, name + + with assert_removed_in_230(): + assert parse_extension(key, {"value": serialized}) == ext, name ext = x509.Extension(oid=oid, critical=True, value=extension_type) # type: ignore[assignment] - assert parse_extension(key, {"value": serialized, "critical": True}) == ext, name + with assert_removed_in_230(): + assert parse_extension(key, {"value": serialized, "critical": True}) == ext, name ext = x509.Extension(oid=oid, critical=False, value=extension_type) # type: ignore[assignment] - assert parse_extension(key, {"value": serialized, "critical": False}) == ext, name + with assert_removed_in_230(): + assert parse_extension(key, {"value": serialized, "critical": False}) == ext, name - assert parse_extension(key, ext) is ext - assert parse_extension(key, extension_type).value is extension_type + with assert_removed_in_230(): + assert parse_extension(key, ext) is ext + with assert_removed_in_230(): + assert parse_extension(key, extension_type).value is extension_type class ExtensionTestCaseMixin: @@ -1346,7 +1353,7 @@ def test_as_text(self, precertificate_signed_certificate_timestamps_pub: x509.Ce def test_parse(self) -> None: """Test parsing.""" msg = r"^precertificate_signed_certificate_timestamps: Cannot parse extensions of this type\.$" - with pytest.raises(ValueError, match=msg): + with assert_removed_in_230(), pytest.raises(ValueError, match=msg): # TYPE NOTE: what we test parse_extension("precertificate_signed_certificate_timestamps", None) # type: ignore[arg-type] diff --git a/ca/django_ca/tests/extensions/test_unknown_extension.py b/ca/django_ca/tests/extensions/test_unknown_extension.py index ce4210746..b4ff8b32f 100644 --- a/ca/django_ca/tests/extensions/test_unknown_extension.py +++ b/ca/django_ca/tests/extensions/test_unknown_extension.py @@ -20,6 +20,7 @@ import pytest from django_ca.extensions import extension_as_text, parse_extension +from django_ca.tests.base.assertions import assert_removed_in_230 class TypeErrorTests(TestCase): @@ -41,7 +42,10 @@ def public_bytes(self) -> bytes: def test_parse_unknown_key(self) -> None: """Test exception for parsing an extension with an unsupported key.""" - with pytest.raises(ValueError, match=r"^wrong_key: Unknown extension key\.$"): + with ( + assert_removed_in_230(), + pytest.raises(ValueError, match=r"^wrong_key: Unknown extension key\.$"), + ): parse_extension("wrong_key", {}) def test_no_extension_as_text(self) -> None: diff --git a/docs/source/changelog/TBR_2.2.0.rst b/docs/source/changelog/TBR_2.2.0.rst index e44ef2d74..516518667 100644 --- a/docs/source/changelog/TBR_2.2.0.rst +++ b/docs/source/changelog/TBR_2.2.0.rst @@ -29,3 +29,10 @@ Python API ********** * ``django_ca.utils.get_storage()`` was be removed (deprecated since 2.0). + +******************* +Deprecation notices +******************* + +* ``django_ca.extensions.parse_extension()`` is deprecated and will be removed in ``django-ca==2.3.0``. Use + :doc:`Pydantic models ` instead.