diff --git a/ca/ca/test_settings.py b/ca/ca/test_settings.py index f67a3aa34..97bd7b569 100644 --- a/ca/ca/test_settings.py +++ b/ca/ca/test_settings.py @@ -141,6 +141,7 @@ # 'django.contrib.admindocs', "django_object_actions", "django_ca", + "ninja", ) TEMPLATES = [ diff --git a/ca/django_ca/api/endpoints.py b/ca/django_ca/api/endpoints.py index 7c1ce8d3c..9654416ab 100644 --- a/ca/django_ca/api/endpoints.py +++ b/ca/django_ca/api/endpoints.py @@ -40,7 +40,6 @@ from django_ca.models import Certificate, CertificateAuthority from django_ca.profiles import profiles from django_ca.querysets import CertificateAuthorityQuerySet, CertificateQuerySet -from django_ca.typehints import ExtensionDict api = NinjaAPI(title="django-ca API", version=__version__, urls_namespace="django_ca:api") @@ -94,14 +93,15 @@ def sign_certificate(request: WSGIRequest, serial: str, data: SignCertificateSch profile = profiles[data.profile] subject = x509.Name.from_rfc4514_string(data.subject) algorithm = expires = None + extensions: List[x509.Extension[x509.ExtensionType]] = [] + if data.algorithm is not None: algorithm = constants.HASH_ALGORITHM_TYPES[data.algorithm]() if data.expires is not None: expires = data.expires if data.extensions is not None: - extensions: List[x509.Extension[x509.ExtensionType]] = [] for key, extension_data in data.extensions.items(): - extensions.append(parse_extension(key, extension_data.dict())) + extensions.append(parse_extension(key, extension_data.dict())) # type: ignore[arg-type] cert = Certificate.objects.create_cert( ca, diff --git a/ca/django_ca/api/schemas.py b/ca/django_ca/api/schemas.py index 01d5fe23b..e1f8ed6b8 100644 --- a/ca/django_ca/api/schemas.py +++ b/ca/django_ca/api/schemas.py @@ -29,6 +29,8 @@ class SubjectAlternativeNameSchema(Schema): + """Schema for a Subject Alternative Name extension.""" + critical: bool = constants.EXTENSION_DEFAULT_CRITICAL[ExtensionOID.SUBJECT_ALTERNATIVE_NAME] value: List[str] diff --git a/ca/django_ca/tests/api/test_sign_cert.py b/ca/django_ca/tests/api/test_sign_cert.py index 216283e5d..3a8ea026e 100644 --- a/ca/django_ca/tests/api/test_sign_cert.py +++ b/ca/django_ca/tests/api/test_sign_cert.py @@ -141,7 +141,6 @@ def test_sign_certificate_with_extensions(self) -> None: # Test extensions extensions = cert.x509_extensions - print(extensions[ExtensionOID.SUBJECT_ALTERNATIVE_NAME]) self.assertEqual( extensions[ExtensionOID.SUBJECT_ALTERNATIVE_NAME], self.subject_alternative_name( diff --git a/ca/django_ca/tests/base/__init__.py b/ca/django_ca/tests/base/__init__.py index ca3d9bea6..b07b7e24a 100644 --- a/ca/django_ca/tests/base/__init__.py +++ b/ca/django_ca/tests/base/__init__.py @@ -384,9 +384,9 @@ def uri(url: str) -> x509.UniformResourceIdentifier: # just a shortcut return x509.UniformResourceIdentifier(url) -def ip( +def ip( # pylint: disable=invalid-name # just a shortcut name: Union[ipaddress.IPv4Address, ipaddress.IPv6Address, ipaddress.IPv4Network, ipaddress.IPv6Network] -) -> x509.IPAddress: # just a shortcut +) -> x509.IPAddress: """Shortcut to get a :py:class:`cg:cryptography.x509.IPAddress`.""" return x509.IPAddress(name) diff --git a/docs/Makefile b/docs/Makefile index 04f76445c..2ec48f0fb 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -18,7 +18,7 @@ source/_files/docker-compose.yml: cp ../docker-compose.yml source/_files/ source/_files/openapi.json: - python ../ca/manage.py export_openapi_schema --api django_ca.api.endpoints.api > source/_files/openapi.json + DJANGO_SETTINGS_MODULE=ca.test_settings python ../ca/manage.py export_openapi_schema --api django_ca.api.endpoints.api > source/_files/openapi.json # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). diff --git a/pyproject.toml b/pyproject.toml index 34b8a5d0f..d08adbb79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -126,6 +126,7 @@ module = [ # https://github.com/docker/docker-py/issues/2796 "docker", "enchant.tokenize", + "httpcore", # psycopg and psycopg_c are not installed in isolated mypy envs (tox, ...) "psycopg", "psycopg_c",