From 6d80abf1b984090779617eea58d5e73dfc806ea8 Mon Sep 17 00:00:00 2001 From: Thijs Kinkhorst <thijs@kinkhorst.com> Date: Thu, 24 May 2018 13:53:09 +0000 Subject: [PATCH] Add tests for AttributeConsumingService isDefault and index options --- .../SimpleSAML/Metadata/SAMLBuilderTest.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php b/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php index d9aa96a5a..01ab8be31 100644 --- a/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php +++ b/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php @@ -136,6 +136,92 @@ class SimpleSAML_Metadata_SAMLBuilderTest extends TestCase } } + /** + * Test the working of the isDefault config option + */ + public function testAttributeConsumingServiceDefault() + { + $entityId = 'https://entity.example.com/id'; + $set = 'saml20-sp-remote'; + + $metadata = array( + 'entityid' => $entityId, + 'name' => array('en' => 'Test SP'), + 'metadata-set' => $set, + 'attributes' => array( + 'eduPersonTargetedID' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10', + 'eduPersonPrincipalName' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6', + ), + ); + + $samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId); + $samlBuilder->addMetadata($set, $metadata); + + $spDesc = $samlBuilder->getEntityDescriptor(); + $acs = $spDesc->getElementsByTagName("AttributeConsumingService"); + $acs1 = $acs->item(0); + $this->assertFalse($acs1->hasAttribute("isDefault")); + + $metadata['attributes.isDefault'] = true; + + $samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId); + $samlBuilder->addMetadata($set, $metadata); + $spDesc = $samlBuilder->getEntityDescriptor(); + $acs = $spDesc->getElementsByTagName("AttributeConsumingService"); + $acs1 = $acs->item(0); + $this->assertTrue($acs1->hasAttribute("isDefault")); + $this->assertEquals("true", $acs1->getAttribute("isDefault")); + + $metadata['attributes.isDefault'] = false; + + $samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId); + $samlBuilder->addMetadata($set, $metadata); + $spDesc = $samlBuilder->getEntityDescriptor(); + $acs = $spDesc->getElementsByTagName("AttributeConsumingService"); + $acs1 = $acs->item(0); + $this->assertTrue($acs1->hasAttribute("isDefault")); + $this->assertEquals("false", $acs1->getAttribute("isDefault")); + } + + /** + * Test the index option is used correctly. + */ + public function testAttributeConsumingServiceIndex() + { + $entityId = 'https://entity.example.com/id'; + $set = 'saml20-sp-remote'; + + $metadata = array( + 'entityid' => $entityId, + 'name' => array('en' => 'Test SP'), + 'metadata-set' => $set, + 'attributes' => array( + 'eduPersonTargetedID' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10', + 'eduPersonPrincipalName' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6', + ), + ); + + $samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId); + $samlBuilder->addMetadata($set, $metadata); + + $spDesc = $samlBuilder->getEntityDescriptor(); + $acs = $spDesc->getElementsByTagName("AttributeConsumingService"); + $acs1 = $acs->item(0); + $this->assertTrue($acs1->hasAttribute("index")); + $this->assertEquals("0", $acs1->getAttribute("index")); + + $metadata['attributes.index'] = 15; + + $samlBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId); + $samlBuilder->addMetadata($set, $metadata); + + $spDesc = $samlBuilder->getEntityDescriptor(); + $acs = $spDesc->getElementsByTagName("AttributeConsumingService"); + $acs1 = $acs->item(0); + $this->assertTrue($acs1->hasAttribute("index")); + $this->assertEquals("15", $acs1->getAttribute("index")); + } + /** * Test the required protocolSupportEnumeration in AttributeAuthorityDescriptor */ -- GitLab