diff --git a/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php b/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php index d9aa96a5a60c8d9778655eb78f0769c300b96aff..01ab8be31bb99aec6b72c0d46213213c21099940 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 */