From c554cbd69f9b786a5d72c9bb51be27386501cabb Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Wed, 18 Dec 2024 16:43:44 +0100 Subject: [PATCH] :white_check_mark: Run XSD validation in eherkenning metadata test --- tests/test_eherkenning_metadata.py | 13 +++++++++++++ tests/utils.py | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tests/test_eherkenning_metadata.py b/tests/test_eherkenning_metadata.py index c2fe4d9..44742c2 100644 --- a/tests/test_eherkenning_metadata.py +++ b/tests/test_eherkenning_metadata.py @@ -1,3 +1,5 @@ +from pathlib import Path + from django.test import TestCase import pytest @@ -12,6 +14,13 @@ ) from .mixins import EherkenningMetadataMixin +from .utils import validate_against_xsd + +_repo_root = Path(__file__).parent.parent.resolve() + +SAML_METADATA_XSD = ( + _repo_root / "digid_eherkenning" / "xsd" / "saml-schema-metadata-2.0.xsd" +) NAME_SPACES = { "md": "urn:oasis:names:tc:SAML:2.0:metadata", @@ -162,6 +171,10 @@ def test_generate_metadata_all_options_specified(self): self.eherkenning_config.save() eherkenning_metadata = generate_eherkenning_metadata() + + with self.subTest("passes XSD validation"): + validate_against_xsd(eherkenning_metadata, SAML_METADATA_XSD) + self.assertEqual(eherkenning_metadata[:5], b" None: + """ + Validate the XML against a schema. + + See https://lxml.de/validation.html + """ + xmlschema = etree.XMLSchema(_load_schema(xsd_schema)) + doc = etree.parse(BytesIO(xml)) + xmlschema.assertValid(doc)