|
2 | 2 |
|
3 | 3 | from base64 import b64encode
|
4 | 4 |
|
| 5 | +from defusedxml.lxml import fromstring |
5 | 6 | from django.http.request import QueryDict
|
6 | 7 | from django.test import TestCase
|
| 8 | +from lxml import etree # nosec |
7 | 9 |
|
8 | 10 | from authentik.blueprints.tests import apply_blueprint
|
9 | 11 | from authentik.core.tests.utils import create_test_admin_user, create_test_cert, create_test_flow
|
10 | 12 | from authentik.crypto.models import CertificateKeyPair
|
11 | 13 | from authentik.events.models import Event, EventAction
|
12 | 14 | from authentik.lib.generators import generate_id
|
13 | 15 | from authentik.lib.tests.utils import get_request
|
| 16 | +from authentik.lib.xml import lxml_from_string |
14 | 17 | from authentik.providers.saml.models import SAMLPropertyMapping, SAMLProvider
|
15 | 18 | from authentik.providers.saml.processors.assertion import AssertionProcessor
|
16 | 19 | from authentik.providers.saml.processors.authn_request_parser import AuthNRequestParser
|
17 | 20 | from authentik.sources.saml.exceptions import MismatchedRequestID
|
18 | 21 | from authentik.sources.saml.models import SAMLSource
|
19 | 22 | from authentik.sources.saml.processors.constants import (
|
| 23 | + NS_MAP, |
20 | 24 | SAML_BINDING_REDIRECT,
|
21 | 25 | SAML_NAME_ID_FORMAT_EMAIL,
|
22 | 26 | SAML_NAME_ID_FORMAT_UNSPECIFIED,
|
@@ -185,6 +189,19 @@ def test_request_signed_both(self):
|
185 | 189 | self.assertEqual(response.count(response_proc._assertion_id), 2)
|
186 | 190 | self.assertEqual(response.count(response_proc._response_id), 2)
|
187 | 191 |
|
| 192 | + schema = etree.XMLSchema( |
| 193 | + etree.parse("schemas/saml-schema-protocol-2.0.xsd", parser=etree.XMLParser()) # nosec |
| 194 | + ) |
| 195 | + self.assertTrue(schema.validate(lxml_from_string(response))) |
| 196 | + |
| 197 | + response_xml = fromstring(response) |
| 198 | + self.assertEqual( |
| 199 | + len(response_xml.xpath("//saml:Assertion/ds:Signature", namespaces=NS_MAP)), 1 |
| 200 | + ) |
| 201 | + self.assertEqual( |
| 202 | + len(response_xml.xpath("//samlp:Response/ds:Signature", namespaces=NS_MAP)), 1 |
| 203 | + ) |
| 204 | + |
188 | 205 | # Now parse the response (source)
|
189 | 206 | http_request.POST = QueryDict(mutable=True)
|
190 | 207 | http_request.POST["SAMLResponse"] = b64encode(response.encode()).decode()
|
|
0 commit comments