authentik.enterprise.stages.account_lockdown.tests.test_blueprint

Tests for the packaged account-lockdown blueprint.

 1"""Tests for the packaged account-lockdown blueprint."""
 2
 3from unittest.mock import patch
 4
 5from django.test import TransactionTestCase
 6
 7from authentik.blueprints.models import BlueprintInstance
 8from authentik.blueprints.v1.importer import Importer
 9from authentik.blueprints.v1.tasks import blueprints_find, check_blueprint_v1_file
10from authentik.enterprise.license import LicenseKey
11from authentik.flows.models import Flow
12
13BLUEPRINT_PATH = "example/flow-default-account-lockdown.yaml"
14
15
16class TestAccountLockdownBlueprint(TransactionTestCase):
17    """Test the packaged account-lockdown blueprint behavior."""
18
19    def test_blueprint_is_not_auto_instantiated(self):
20        """Test the packaged blueprint is opt-in and skipped by discovery."""
21        BlueprintInstance.objects.filter(path=BLUEPRINT_PATH).delete()
22        blueprint = next(item for item in blueprints_find() if item.path == BLUEPRINT_PATH)
23
24        check_blueprint_v1_file(blueprint)
25
26        self.assertFalse(BlueprintInstance.objects.filter(path=BLUEPRINT_PATH).exists())
27
28    def test_blueprint_requires_licensed_context(self):
29        """Test manual import only creates flows when enterprise is licensed."""
30        content = BlueprintInstance(path=BLUEPRINT_PATH).retrieve()
31        license_key = LicenseKey("test", 253402300799, "Test license", 1000, 1000)
32
33        with patch("authentik.enterprise.license.LicenseKey.get_total", return_value=license_key):
34            importer = Importer.from_string(content, {"goauthentik.io/enterprise/licensed": False})
35            valid, logs = importer.validate()
36            self.assertTrue(valid, logs)
37            self.assertTrue(importer.apply())
38            self.assertFalse(Flow.objects.filter(slug="default-account-lockdown").exists())
39            self.assertFalse(Flow.objects.filter(slug="default-account-lockdown-complete").exists())
40
41            importer = Importer.from_string(content, {"goauthentik.io/enterprise/licensed": True})
42            valid, logs = importer.validate()
43            self.assertTrue(valid, logs)
44            self.assertTrue(importer.apply())
45            self.assertTrue(Flow.objects.filter(slug="default-account-lockdown").exists())
46            self.assertTrue(Flow.objects.filter(slug="default-account-lockdown-complete").exists())
BLUEPRINT_PATH = 'example/flow-default-account-lockdown.yaml'
class TestAccountLockdownBlueprint(django.test.testcases.TransactionTestCase):
17class TestAccountLockdownBlueprint(TransactionTestCase):
18    """Test the packaged account-lockdown blueprint behavior."""
19
20    def test_blueprint_is_not_auto_instantiated(self):
21        """Test the packaged blueprint is opt-in and skipped by discovery."""
22        BlueprintInstance.objects.filter(path=BLUEPRINT_PATH).delete()
23        blueprint = next(item for item in blueprints_find() if item.path == BLUEPRINT_PATH)
24
25        check_blueprint_v1_file(blueprint)
26
27        self.assertFalse(BlueprintInstance.objects.filter(path=BLUEPRINT_PATH).exists())
28
29    def test_blueprint_requires_licensed_context(self):
30        """Test manual import only creates flows when enterprise is licensed."""
31        content = BlueprintInstance(path=BLUEPRINT_PATH).retrieve()
32        license_key = LicenseKey("test", 253402300799, "Test license", 1000, 1000)
33
34        with patch("authentik.enterprise.license.LicenseKey.get_total", return_value=license_key):
35            importer = Importer.from_string(content, {"goauthentik.io/enterprise/licensed": False})
36            valid, logs = importer.validate()
37            self.assertTrue(valid, logs)
38            self.assertTrue(importer.apply())
39            self.assertFalse(Flow.objects.filter(slug="default-account-lockdown").exists())
40            self.assertFalse(Flow.objects.filter(slug="default-account-lockdown-complete").exists())
41
42            importer = Importer.from_string(content, {"goauthentik.io/enterprise/licensed": True})
43            valid, logs = importer.validate()
44            self.assertTrue(valid, logs)
45            self.assertTrue(importer.apply())
46            self.assertTrue(Flow.objects.filter(slug="default-account-lockdown").exists())
47            self.assertTrue(Flow.objects.filter(slug="default-account-lockdown-complete").exists())

Test the packaged account-lockdown blueprint behavior.

def test_blueprint_is_not_auto_instantiated(self):
20    def test_blueprint_is_not_auto_instantiated(self):
21        """Test the packaged blueprint is opt-in and skipped by discovery."""
22        BlueprintInstance.objects.filter(path=BLUEPRINT_PATH).delete()
23        blueprint = next(item for item in blueprints_find() if item.path == BLUEPRINT_PATH)
24
25        check_blueprint_v1_file(blueprint)
26
27        self.assertFalse(BlueprintInstance.objects.filter(path=BLUEPRINT_PATH).exists())

Test the packaged blueprint is opt-in and skipped by discovery.

def test_blueprint_requires_licensed_context(self):
29    def test_blueprint_requires_licensed_context(self):
30        """Test manual import only creates flows when enterprise is licensed."""
31        content = BlueprintInstance(path=BLUEPRINT_PATH).retrieve()
32        license_key = LicenseKey("test", 253402300799, "Test license", 1000, 1000)
33
34        with patch("authentik.enterprise.license.LicenseKey.get_total", return_value=license_key):
35            importer = Importer.from_string(content, {"goauthentik.io/enterprise/licensed": False})
36            valid, logs = importer.validate()
37            self.assertTrue(valid, logs)
38            self.assertTrue(importer.apply())
39            self.assertFalse(Flow.objects.filter(slug="default-account-lockdown").exists())
40            self.assertFalse(Flow.objects.filter(slug="default-account-lockdown-complete").exists())
41
42            importer = Importer.from_string(content, {"goauthentik.io/enterprise/licensed": True})
43            valid, logs = importer.validate()
44            self.assertTrue(valid, logs)
45            self.assertTrue(importer.apply())
46            self.assertTrue(Flow.objects.filter(slug="default-account-lockdown").exists())
47            self.assertTrue(Flow.objects.filter(slug="default-account-lockdown-complete").exists())

Test manual import only creates flows when enterprise is licensed.