Skip to content

Commit

Permalink
deprecate django_ca.extensions.parse_extension (unused).
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasertl committed Dec 28, 2024
1 parent 14a5c0c commit 8800561
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ca/django_ca/extensions/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 13 additions & 6 deletions ca/django_ca/tests/extensions/test_extension_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]

Expand Down
6 changes: 5 additions & 1 deletion ca/django_ca/tests/extensions/test_unknown_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions docs/source/changelog/TBR_2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 </python/pydantic>` instead.

0 comments on commit 8800561

Please sign in to comment.