From 47ca566d06811ce4228ba7e8710341e1b6e15308 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 12 Jul 2020 18:33:42 +0200 Subject: [PATCH] sources/saml: fix MetadataProcessor not working, add unittests --- passbook/sources/saml/processors/metadata.py | 6 ++--- passbook/sources/saml/tests.py | 26 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 passbook/sources/saml/tests.py diff --git a/passbook/sources/saml/processors/metadata.py b/passbook/sources/saml/processors/metadata.py index 299356e90..6d7e7c576 100644 --- a/passbook/sources/saml/processors/metadata.py +++ b/passbook/sources/saml/processors/metadata.py @@ -82,10 +82,10 @@ class MetadataProcessor: sp_sso_descriptor.append(name_id_format) assertion_consumer_service = SubElement( - sp_sso_descriptor, f"{{{NS_SAML_METADATA}}}" + sp_sso_descriptor, f"{{{NS_SAML_METADATA}}}AssertionConsumerService" ) - assertion_consumer_service.attrib["isDefault"] = True - assertion_consumer_service.attrib["index"] = 0 + assertion_consumer_service.attrib["isDefault"] = "true" + assertion_consumer_service.attrib["index"] = "0" assertion_consumer_service.attrib["Binding"] = SAML_BINDING_POST assertion_consumer_service.attrib["Location"] = self.source.build_full_url( self.http_request diff --git a/passbook/sources/saml/tests.py b/passbook/sources/saml/tests.py new file mode 100644 index 000000000..c5bc7b28c --- /dev/null +++ b/passbook/sources/saml/tests.py @@ -0,0 +1,26 @@ +"""SAML Source tests""" +from defusedxml import ElementTree +from django.test import RequestFactory, TestCase + +from passbook.crypto.models import CertificateKeyPair +from passbook.sources.saml.models import SAMLSource +from passbook.sources.saml.processors.metadata import MetadataProcessor + + +class TestMetadataProcessor(TestCase): + """Test MetadataProcessor""" + + def setUp(self): + self.source = SAMLSource.objects.create( + slug="provider", + issuer="passbook", + signing_kp=CertificateKeyPair.objects.first(), + ) + self.factory = RequestFactory() + + def test_metadata(self): + """Test Metadata generation being valid""" + request = self.factory.get("/") + xml = MetadataProcessor(self.source, request).build_entity_descriptor() + metadata = ElementTree.fromstring(xml) + self.assertEqual(metadata.attrib["entityID"], "passbook")