diff --git a/authentik/crypto/builder.py b/authentik/crypto/builder.py index 55799a496..51ad4defb 100644 --- a/authentik/crypto/builder.py +++ b/authentik/crypto/builder.py @@ -33,7 +33,7 @@ class CertificateBuilder: def save(self) -> Optional[CertificateKeyPair]: """Save generated certificate as model""" if not self.__certificate: - return None + raise ValueError("Certificated hasn't been built yet") return CertificateKeyPair.objects.create( name=self.common_name, certificate_data=self.certificate, diff --git a/authentik/crypto/tests.py b/authentik/crypto/tests.py index 59df86b32..00dd0c30a 100644 --- a/authentik/crypto/tests.py +++ b/authentik/crypto/tests.py @@ -37,6 +37,8 @@ class TestCrypto(TestCase): """Test Builder""" builder = CertificateBuilder() builder.common_name = "test-cert" + with self.assertRaises(ValueError): + builder.save() builder.build( subject_alt_names=[], validity_days=3, diff --git a/authentik/lib/tests/test_utils_reflection.py b/authentik/lib/tests/test_utils_reflection.py new file mode 100644 index 000000000..4123cba61 --- /dev/null +++ b/authentik/lib/tests/test_utils_reflection.py @@ -0,0 +1,16 @@ +"""Test Reflection utils""" + +from datetime import datetime + +from django.test import TestCase + +from authentik.lib.utils.reflection import path_to_class + + +class TestReflectionUtils(TestCase): + """Test Reflection-utils""" + + def test_path_to_class(self): + """Test path_to_class""" + self.assertIsNone(path_to_class(None)) + self.assertEqual(path_to_class("datetime.datetime"), datetime)