authentik.sources.kerberos.tests.test_kadm5

Kerberos kadm5 client library tests

 1"""Kerberos kadm5 client library tests"""
 2
 3from django.test import TestCase
 4from kadmin import exceptions as kadmin_exceptions
 5
 6from authentik.lib.generators import generate_id
 7from authentik.sources.kerberos.models import KAdminType, KerberosSource, Krb5ConfContext
 8
 9
10class TestKAdm5Libraries(TestCase):
11    """python-kadmin-rs loads the kadm5 client library only when it connects, so a missing library
12    shows up nowhere else. The sync tests already load the MIT one against the test KDC, so only the
13    Heimdal one is tried here"""
14
15    def test_heimdal_library_loads(self):
16        """Without a KDC connecting fails, but not because the library is missing"""
17        realm = generate_id().upper()
18        source = KerberosSource.objects.create(
19            name=generate_id(),
20            slug=generate_id(),
21            realm=realm,
22            krb5_conf=(
23                "[libdefaults]\n"
24                f"    default_realm = {realm}\n"
25                "    dns_lookup_kdc = false\n"
26                "    dns_lookup_realm = false\n"
27            ),
28            kadmin_type=KAdminType.HEIMDAL,
29            sync_users=True,
30            sync_principal=f"sync@{realm}",
31            sync_password=generate_id(),
32        )
33        with (
34            Krb5ConfContext(source),
35            self.assertRaises(kadmin_exceptions.PyKAdminException) as ctx,
36        ):
37            source.connection()
38        self.assertNotIsInstance(ctx.exception, kadmin_exceptions.LibraryLoadError)
class TestKAdm5Libraries(django.test.testcases.TestCase):
11class TestKAdm5Libraries(TestCase):
12    """python-kadmin-rs loads the kadm5 client library only when it connects, so a missing library
13    shows up nowhere else. The sync tests already load the MIT one against the test KDC, so only the
14    Heimdal one is tried here"""
15
16    def test_heimdal_library_loads(self):
17        """Without a KDC connecting fails, but not because the library is missing"""
18        realm = generate_id().upper()
19        source = KerberosSource.objects.create(
20            name=generate_id(),
21            slug=generate_id(),
22            realm=realm,
23            krb5_conf=(
24                "[libdefaults]\n"
25                f"    default_realm = {realm}\n"
26                "    dns_lookup_kdc = false\n"
27                "    dns_lookup_realm = false\n"
28            ),
29            kadmin_type=KAdminType.HEIMDAL,
30            sync_users=True,
31            sync_principal=f"sync@{realm}",
32            sync_password=generate_id(),
33        )
34        with (
35            Krb5ConfContext(source),
36            self.assertRaises(kadmin_exceptions.PyKAdminException) as ctx,
37        ):
38            source.connection()
39        self.assertNotIsInstance(ctx.exception, kadmin_exceptions.LibraryLoadError)

python-kadmin-rs loads the kadm5 client library only when it connects, so a missing library shows up nowhere else. The sync tests already load the MIT one against the test KDC, so only the Heimdal one is tried here

def test_heimdal_library_loads(self):
16    def test_heimdal_library_loads(self):
17        """Without a KDC connecting fails, but not because the library is missing"""
18        realm = generate_id().upper()
19        source = KerberosSource.objects.create(
20            name=generate_id(),
21            slug=generate_id(),
22            realm=realm,
23            krb5_conf=(
24                "[libdefaults]\n"
25                f"    default_realm = {realm}\n"
26                "    dns_lookup_kdc = false\n"
27                "    dns_lookup_realm = false\n"
28            ),
29            kadmin_type=KAdminType.HEIMDAL,
30            sync_users=True,
31            sync_principal=f"sync@{realm}",
32            sync_password=generate_id(),
33        )
34        with (
35            Krb5ConfContext(source),
36            self.assertRaises(kadmin_exceptions.PyKAdminException) as ctx,
37        ):
38            source.connection()
39        self.assertNotIsInstance(ctx.exception, kadmin_exceptions.LibraryLoadError)

Without a KDC connecting fails, but not because the library is missing