crypto: add tests for builder

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-03-30 16:34:45 +02:00
parent 1f89b94f66
commit 41914d9b7a
2 changed files with 17 additions and 1 deletions

View File

@ -1,7 +1,10 @@
"""Crypto tests""" """Crypto tests"""
import datetime
from django.test import TestCase from django.test import TestCase
from authentik.crypto.api import CertificateKeyPairSerializer from authentik.crypto.api import CertificateKeyPairSerializer
from authentik.crypto.builder import CertificateBuilder
from authentik.crypto.models import CertificateKeyPair from authentik.crypto.models import CertificateKeyPair
@ -29,3 +32,16 @@ class TestCrypto(TestCase):
} }
).is_valid() ).is_valid()
) )
def test_builder(self):
"""Test Builder"""
builder = CertificateBuilder()
builder.common_name = "test-cert"
builder.build(
subject_alt_names=[],
validity_days=3,
)
instance = builder.save()
now = datetime.datetime.today()
self.assertEqual(instance.name, "test-cert")
self.assertEqual((instance.certificate.not_valid_after - now).days, 2)

View File

@ -60,7 +60,7 @@ urlpatterns += [
path("-/health/ready/", ReadyView.as_view(), name="health-ready"), path("-/health/ready/", ReadyView.as_view(), name="health-ready"),
] ]
if settings.DEBUG: if settings.DEBUG: # pragma: no cover
urlpatterns = ( urlpatterns = (
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)