authentik.sources.saml.tests.test_request

SAML Source AuthnRequest tests

 1"""SAML Source AuthnRequest tests"""
 2
 3from django.test import RequestFactory, TestCase
 4
 5from authentik.core.tests.utils import create_test_flow
 6from authentik.lib.generators import generate_id
 7from authentik.sources.saml.models import SAMLSource
 8from authentik.sources.saml.processors.request import RequestProcessor
 9
10
11class TestRequestProcessor(TestCase):
12    """Test SAML AuthnRequest generation"""
13
14    def setUp(self):
15        self.factory = RequestFactory()
16        self.source = SAMLSource.objects.create(
17            name=generate_id(),
18            slug=generate_id(),
19            issuer="authentik",
20            sso_url="https://idp.example.com/sso",
21            pre_authentication_flow=create_test_flow(),
22        )
23
24    def test_force_authn_flag(self):
25        """Test that ForceAuthn attribute is set when force_authn is True"""
26        self.source.force_authn = True
27        self.source.save()
28
29        request = self.factory.get("/")
30        request.session = {}
31
32        processor = RequestProcessor(self.source, request, "")
33        auth_n = processor.get_auth_n()
34
35        self.assertEqual(auth_n.attrib.get("ForceAuthn"), "true")
class TestRequestProcessor(django.test.testcases.TestCase):
12class TestRequestProcessor(TestCase):
13    """Test SAML AuthnRequest generation"""
14
15    def setUp(self):
16        self.factory = RequestFactory()
17        self.source = SAMLSource.objects.create(
18            name=generate_id(),
19            slug=generate_id(),
20            issuer="authentik",
21            sso_url="https://idp.example.com/sso",
22            pre_authentication_flow=create_test_flow(),
23        )
24
25    def test_force_authn_flag(self):
26        """Test that ForceAuthn attribute is set when force_authn is True"""
27        self.source.force_authn = True
28        self.source.save()
29
30        request = self.factory.get("/")
31        request.session = {}
32
33        processor = RequestProcessor(self.source, request, "")
34        auth_n = processor.get_auth_n()
35
36        self.assertEqual(auth_n.attrib.get("ForceAuthn"), "true")

Test SAML AuthnRequest generation

def setUp(self):
15    def setUp(self):
16        self.factory = RequestFactory()
17        self.source = SAMLSource.objects.create(
18            name=generate_id(),
19            slug=generate_id(),
20            issuer="authentik",
21            sso_url="https://idp.example.com/sso",
22            pre_authentication_flow=create_test_flow(),
23        )

Hook method for setting up the test fixture before exercising it.

def test_force_authn_flag(self):
25    def test_force_authn_flag(self):
26        """Test that ForceAuthn attribute is set when force_authn is True"""
27        self.source.force_authn = True
28        self.source.save()
29
30        request = self.factory.get("/")
31        request.session = {}
32
33        processor = RequestProcessor(self.source, request, "")
34        auth_n = processor.get_auth_n()
35
36        self.assertEqual(auth_n.attrib.get("ForceAuthn"), "true")

Test that ForceAuthn attribute is set when force_authn is True