public function testUnmarshalling() { $mdNamespace = Constants::NS_MD; $document = DOMDocumentFactory::fromString(<<<XML <md:Test xmlns:md="{$mdNamespace}" Binding="urn:something" Location="https://whatever/" xmlns:test="urn:test" test:attr="value" /> XML ); $endpointType = new EndpointType($document->firstChild); $this->assertEquals(true, $endpointType->hasAttributeNS('urn:test', 'attr')); $this->assertEquals('value', $endpointType->getAttributeNS('urn:test', 'attr')); $this->assertEquals(false, $endpointType->hasAttributeNS('urn:test', 'invalid')); $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'invalid')); $endpointType->removeAttributeNS('urn:test', 'attr'); $this->assertEquals(false, $endpointType->hasAttributeNS('urn:test', 'attr')); $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'attr')); $endpointType->setAttributeNS('urn:test2', 'test2:attr2', 'value2'); $this->assertEquals('value2', $endpointType->getAttributeNS('urn:test2', 'attr2')); $document->loadXML('<root />'); $endpointTypeElement = $endpointType->toXML($document->firstChild, 'md:Test'); $endpointTypeElements = Utils::xpQuery($endpointTypeElement, '/root/saml_metadata:Test'); $this->assertCount(1, $endpointTypeElements); $endpointTypeElement = $endpointTypeElements[0]; $this->assertEquals('value2', $endpointTypeElement->getAttributeNS('urn:test2', 'attr2')); $this->assertEquals(false, $endpointTypeElement->hasAttributeNS('urn:test', 'attr')); }
/** * Append this attribute value to an element. * * @param \DOMElement $parent The element we should append this attribute value to. * @return \DOMElement The generated AttributeValue element. */ public function toXML(\DOMElement $parent) { assert('$this->element instanceof \\DOMElement'); assert('$this->element->namespaceURI === \\SAML2\\Constants::NS_SAML && $this->element->localName === "AttributeValue"'); $v = Utils::copyElement($this->element, $parent); return $v; }
public function testMarshalling() { $indexedEndpointType = new IndexedEndpointType(); $indexedEndpointType->Binding = 'TestBinding'; $indexedEndpointType->Location = 'TestLocation'; $indexedEndpointType->index = 42; $indexedEndpointType->isDefault = false; $document = DOMDocumentFactory::fromString('<root />'); $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test'); $indexedEndpointElements = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test'); $this->assertCount(1, $indexedEndpointElements); $indexedEndpointElement = $indexedEndpointElements[0]; $this->assertEquals('TestBinding', $indexedEndpointElement->getAttribute('Binding')); $this->assertEquals('TestLocation', $indexedEndpointElement->getAttribute('Location')); $this->assertEquals('42', $indexedEndpointElement->getAttribute('index')); $this->assertEquals('false', $indexedEndpointElement->getAttribute('isDefault')); $indexedEndpointType->isDefault = true; $document->loadXML('<root />'); $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test'); $indexedEndpointTypeElement = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test'); $this->assertCount(1, $indexedEndpointTypeElement); $this->assertEquals('true', $indexedEndpointTypeElement[0]->getAttribute('isDefault')); $indexedEndpointType->isDefault = null; $document->loadXML('<root />'); $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test'); $indexedEndpointTypeElement = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test'); $this->assertCount(1, $indexedEndpointTypeElement); $this->assertTrue(!$indexedEndpointTypeElement[0]->hasAttribute('isDefault')); }
public function testMarshallingOfSimpleRequest() { $document = new \DOMDocument(); $document->loadXML(<<<AUTHNREQUEST <samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_306f8ec5b618f361c70b6ffb1480eade" Version="2.0" IssueInstant="2004-12-05T09:21:59Z" Destination="https://idp.example.org/SAML2/SSO/Artifact" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" AssertionConsumerServiceURL="https://sp.example.com/SAML2/SSO/Artifact"> <saml:Issuer>https://sp.example.com/SAML2</saml:Issuer> </samlp:AuthnRequest> AUTHNREQUEST ); $authnRequest = new AuthnRequest($document->documentElement); $expectedIssueInstant = Utils::xsDateTimeToTimestamp('2004-12-05T09:21:59Z'); $this->assertEquals($expectedIssueInstant, $authnRequest->getIssueInstant()); $this->assertEquals('https://idp.example.org/SAML2/SSO/Artifact', $authnRequest->getDestination()); $this->assertEquals('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact', $authnRequest->getProtocolBinding()); $this->assertEquals('https://sp.example.com/SAML2/SSO/Artifact', $authnRequest->getAssertionConsumerServiceURL()); $this->assertEquals('https://sp.example.com/SAML2', $authnRequest->getIssuer()); }
/** * Initialize an EntitiesDescriptor. * * @param \DOMElement|null $xml The XML element we should load. */ public function __construct(\DOMElement $xml = null) { parent::__construct($xml); if ($xml === null) { return; } if ($xml->hasAttribute('ID')) { $this->ID = $xml->getAttribute('ID'); } if ($xml->hasAttribute('validUntil')) { $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil')); } if ($xml->hasAttribute('cacheDuration')) { $this->cacheDuration = $xml->getAttribute('cacheDuration'); } if ($xml->hasAttribute('Name')) { $this->Name = $xml->getAttribute('Name'); } $this->Extensions = Extensions::getList($xml); foreach (Utils::xpQuery($xml, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) { if ($node->localName === 'EntityDescriptor') { $this->children[] = new EntityDescriptor($node); } else { $this->children[] = new EntitiesDescriptor($node); } } }
/** * Initialize an RequestedAttribute. * * @param \DOMElement|null $xml The XML element we should load. */ public function __construct(\DOMElement $xml = null) { parent::__construct($xml); if ($xml === null) { return; } $this->isRequired = Utils::parseBoolean($xml, 'isRequired', null); }
/** * Create a Scope. * * @param \DOMElement|null $xml The XML element we should load. */ public function __construct(\DOMElement $xml = null) { if ($xml === null) { return; } $this->scope = $xml->textContent; $this->regexp = Utils::parseBoolean($xml, 'regexp', null); }
/** * Get a list of Extensions in the given element. * * @param \DOMElement $parent The element that may contain the samlp:Extensions element. * @return array Array of extensions. */ public static function getList(\DOMElement $parent) { $ret = array(); foreach (Utils::xpQuery($parent, './saml_protocol:Extensions/*') as $node) { $ret[] = new Chunk($node); } return $ret; }
/** * Convert this AdditionalMetadataLocation to XML. * * @param \DOMElement $parent The element we should append to. * @return \DOMElement This AdditionalMetadataLocation-element. */ public function toXML(\DOMElement $parent) { assert('is_string($this->namespace)'); assert('is_string($this->location)'); $e = Utils::addString($parent, Constants::NS_MD, 'md:AdditionalMetadataLocation', $this->location); $e->setAttribute('namespace', $this->namespace); return $e; }
/** * Initialize an IndexedEndpointType. * * @param \DOMElement|null $xml The XML element we should load. * @throws \Exception */ public function __construct(\DOMElement $xml = null) { parent::__construct($xml); if ($xml === null) { return; } if (!$xml->hasAttribute('index')) { throw new \Exception('Missing index on ' . $xml->tagName); } $this->index = (int) $xml->getAttribute('index'); $this->isDefault = Utils::parseBoolean($xml, 'isDefault', null); }
/** * Create a EntityAttributes element. * * @param \DOMElement|null $xml The XML element we should load. */ public function __construct(\DOMElement $xml = null) { if ($xml === null) { return; } foreach (Utils::xpQuery($xml, './saml_assertion:Attribute|./saml_assertion:Assertion') as $node) { if ($node->localName === 'Attribute') { $this->children[] = new Attribute($node); } else { $this->children[] = new Chunk($node); } } }
/** * Test creating a basic Keywords element. */ public function testMarshalling() { $keywords = new Keywords(); $keywords->lang = "en"; $keywords->Keywords = array("KLM", "royal", "Dutch", "air lines"); $document = DOMDocumentFactory::fromString('<root />'); $xml = $keywords->toXML($document->firstChild); $keywordElements = Utils::xpQuery($xml, '/root/*[local-name()=\'Keywords\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']'); $this->assertCount(1, $keywordElements); $keywordElement = $keywordElements[0]; $this->assertEquals("KLM royal Dutch air+lines", $keywordElement->textContent); $this->assertEquals("en", $keywordElement->getAttribute('xml:lang')); }
public function testMarshalling() { $document = DOMDocumentFactory::fromString('<root/>'); $additionalMetadataLocation = new AdditionalMetadataLocation(); $additionalMetadataLocation->namespace = 'NamespaceAttribute'; $additionalMetadataLocation->location = 'TheLocation'; $additionalMetadataLocationElement = $additionalMetadataLocation->toXML($document->firstChild); $additionalMetadataLocationElements = Utils::xpQuery($additionalMetadataLocationElement, '/root/saml_metadata:AdditionalMetadataLocation'); $this->assertCount(1, $additionalMetadataLocationElements); $additionalMetadataLocationElement = $additionalMetadataLocationElements[0]; $this->assertEquals('TheLocation', $additionalMetadataLocationElement->textContent); $this->assertEquals('NamespaceAttribute', $additionalMetadataLocationElement->getAttribute("namespace")); }
/** * Marshalling a scope which is in regexp form. */ public function testMarshallingRegexp() { $scope = new Scope(); $scope->scope = "^(.*\\.)?example\\.edu\$"; $scope->regexp = TRUE; $document = DOMDocumentFactory::fromString('<root />'); $scopeElement = $scope->toXML($document->firstChild); $scopeElements = Utils::xpQuery($scopeElement, '/root/shibmd:Scope'); $this->assertCount(1, $scopeElements); $scopeElement = $scopeElements[0]; $this->assertEquals('^(.*\\.)?example\\.edu$', $scopeElement->nodeValue); $this->assertEquals('urn:mace:shibboleth:metadata:1.0', $scopeElement->namespaceURI); $this->assertEquals('true', $scopeElement->getAttribute('regexp')); }
/** * Initialize a SPSSODescriptor. * * @param \DOMElement|null $xml The XML element we should load. */ public function __construct(\DOMElement $xml = null) { parent::__construct('md:SPSSODescriptor', $xml); if ($xml === null) { return; } $this->AuthnRequestsSigned = Utils::parseBoolean($xml, 'AuthnRequestsSigned', null); $this->WantAssertionsSigned = Utils::parseBoolean($xml, 'WantAssertionsSigned', null); foreach (Utils::xpQuery($xml, './saml_metadata:AssertionConsumerService') as $ep) { $this->AssertionConsumerService[] = new IndexedEndpointType($ep); } foreach (Utils::xpQuery($xml, './saml_metadata:AttributeConsumingService') as $acs) { $this->AttributeConsumingService[] = new AttributeConsumingService($acs); } }
/** * Add this IDPSSODescriptor to an EntityDescriptor. * * @param \DOMElement $parent The EntityDescriptor we should append this AuthnAuthorityDescriptor to. * @return \DOMElement */ public function toXML(\DOMElement $parent) { assert('is_array($this->AuthnQueryService)'); assert('!empty($this->AuthnQueryService)'); assert('is_array($this->AssertionIDRequestService)'); assert('is_array($this->NameIDFormat)'); $e = parent::toXML($parent); foreach ($this->AuthnQueryService as $ep) { $ep->toXML($e, 'md:AuthnQueryService'); } foreach ($this->AssertionIDRequestService as $ep) { $ep->toXML($e, 'md:AssertionIDRequestService'); } Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->NameIDFormat); return $e; }
public function testMarshalling() { $attribute = new Attribute(); $attribute->Name = 'TheName'; $attribute->NameFormat = 'TheNameFormat'; $attribute->FriendlyName = 'TheFriendlyName'; $attribute->AttributeValue = array(new AttributeValue('FirstValue'), new AttributeValue('SecondValue')); $document = DOMDocumentFactory::fromString('<root />'); $attributeElement = $attribute->toXML($document->firstChild); $attributeElements = Utils::xpQuery($attributeElement, '/root/saml_assertion:Attribute'); $this->assertCount(1, $attributeElements); $attributeElement = $attributeElements[0]; $this->assertEquals('TheName', $attributeElement->getAttribute('Name')); $this->assertEquals('TheNameFormat', $attributeElement->getAttribute('NameFormat')); $this->assertEquals('TheFriendlyName', $attributeElement->getAttribute('FriendlyName')); }
public function testMarshalling() { $subjectConfirmation = new SubjectConfirmation(); $subjectConfirmation->Method = 'SomeMethod'; $subjectConfirmation->NameID = new NameID(); $subjectConfirmation->NameID->value = 'SomeNameIDValue'; $subjectConfirmation->SubjectConfirmationData = new SubjectConfirmationData(); $document = DOMDocumentFactory::fromString('<root />'); $subjectConfirmationElement = $subjectConfirmation->toXML($document->firstChild); $subjectConfirmationElements = Utils::xpQuery($subjectConfirmationElement, '//saml_assertion:SubjectConfirmation'); $this->assertCount(1, $subjectConfirmationElements); $subjectConfirmationElement = $subjectConfirmationElements[0]; $this->assertEquals('SomeMethod', $subjectConfirmationElement->getAttribute("Method")); $this->assertCount(1, Utils::xpQuery($subjectConfirmationElement, "./saml_assertion:NameID")); $this->assertCount(1, Utils::xpQuery($subjectConfirmationElement, "./saml_assertion:SubjectConfirmationData")); }
/** * Test creating a basic Logo element. */ public function testMarshalling() { $logo = new Logo(); $logo->lang = "nl"; $logo->width = 300; $logo->height = 200; $logo->url = "https://static.example.org/images/logos/logo300x200.png"; $document = DOMDocumentFactory::fromString('<root />'); $xml = $logo->toXML($document->firstChild); $logoElements = Utils::xpQuery($xml, '/root/*[local-name()=\'Logo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']'); $this->assertCount(1, $logoElements); $logoElement = $logoElements[0]; $this->assertEquals("https://static.example.org/images/logos/logo300x200.png", $logoElement->textContent); $this->assertEquals("nl", $logoElement->getAttribute("xml:lang")); $this->assertEquals(300, $logoElement->getAttribute("width")); $this->assertEquals(200, $logoElement->getAttribute("height")); }
/** * Convert this Organization to XML. * * @param \DOMElement $parent The element we should add this organization to. * @return \DOMElement This Organization-element. */ public function toXML(\DOMElement $parent) { assert('is_array($this->Extensions)'); assert('is_array($this->OrganizationName)'); assert('!empty($this->OrganizationName)'); assert('is_array($this->OrganizationDisplayName)'); assert('!empty($this->OrganizationDisplayName)'); assert('is_array($this->OrganizationURL)'); assert('!empty($this->OrganizationURL)'); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Constants::NS_MD, 'md:Organization'); $parent->appendChild($e); Extensions::addList($e, $this->Extensions); Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationName', true, $this->OrganizationName); Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationDisplayName', true, $this->OrganizationDisplayName); Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationURL', true, $this->OrganizationURL); return $e; }
/** * Convert this element to XML. * * @param \DOMElement $parent The element we should append to. * @return \DOMElement */ public function toXML(\DOMElement $parent) { assert('is_string($this->registrationAuthority)'); assert('is_int($this->registrationInstant) || is_null($this->registrationInstant)'); assert('is_array($this->RegistrationPolicy)'); if (empty($this->registrationAuthority)) { throw new \Exception('Missing required registration authority.'); } $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS_MDRPI, 'mdrpi:RegistrationInfo'); $parent->appendChild($e); $e->setAttribute('registrationAuthority', $this->registrationAuthority); if ($this->registrationInstant !== null) { $e->setAttribute('registrationInstant', gmdate('Y-m-d\\TH:i:s\\Z', $this->registrationInstant)); } Utils::addStrings($e, Common::NS_MDRPI, 'mdrpi:RegistrationPolicy', true, $this->RegistrationPolicy); return $e; }
public function testMarshalling() { $nameId = new NameID(); $nameId->NameQualifier = 'TheNameQualifier'; $nameId->SPNameQualifier = 'TheSPNameQualifier'; $nameId->Format = 'TheFormat'; $nameId->SPProvidedID = 'TheSPProvidedID'; $nameId->value = 'TheNameIDValue'; $nameIdElement = $nameId->toXML(); $nameIdElements = Utils::xpQuery($nameIdElement, '/saml_assertion:NameID'); $this->assertCount(1, $nameIdElements); $nameIdElement = $nameIdElements[0]; $this->assertEquals('TheNameQualifier', $nameIdElement->getAttribute("NameQualifier")); $this->assertEquals('TheSPNameQualifier', $nameIdElement->getAttribute("SPNameQualifier")); $this->assertEquals('TheFormat', $nameIdElement->getAttribute("Format")); $this->assertEquals('TheSPProvidedID', $nameIdElement->getAttribute("SPProvidedID")); $this->assertEquals('TheNameIDValue', $nameIdElement->textContent); }
/** * Initialize an Attribute. * * @param \DOMElement|null $xml The XML element we should load. * @throws \Exception */ public function __construct(\DOMElement $xml = null) { if ($xml === null) { return; } if (!$xml->hasAttribute('Name')) { throw new \Exception('Missing Name on Attribute.'); } $this->Name = $xml->getAttribute('Name'); if ($xml->hasAttribute('NameFormat')) { $this->NameFormat = $xml->getAttribute('NameFormat'); } if ($xml->hasAttribute('FriendlyName')) { $this->FriendlyName = $xml->getAttribute('FriendlyName'); } foreach (Utils::xpQuery($xml, './saml_assertion:AttributeValue') as $av) { $this->AttributeValue[] = new AttributeValue($av); } }
/** * Store a NameID to attribute. * * @param array &$state The request state. */ public function process(&$state) { assert('is_array($state)'); if (!isset($state['saml:NameID'][\SAML2\Constants::NAMEID_PERSISTENT])) { SimpleSAML\Logger::warning('Unable to generate eduPersonTargetedID because no persistent NameID was available.'); return; } $nameID = $state['saml:NameID'][\SAML2\Constants::NAMEID_PERSISTENT]; if ($this->nameId) { $doc = \SAML2\DOMDocumentFactory::create(); $root = $doc->createElement('root'); $doc->appendChild($root); \SAML2\Utils::addNameId($root, $nameID); $value = $doc->saveXML($root->firstChild); } else { $value = $nameID['Value']; } $state['Attributes'][$this->attribute] = array($value); }
public function testMarshalling() { $subjectConfirmationData = new SubjectConfirmationData(); $subjectConfirmationData->NotBefore = 987654321; $subjectConfirmationData->NotOnOrAfter = 1234567890; $subjectConfirmationData->Recipient = 'https://sp.example.org/asdf'; $subjectConfirmationData->InResponseTo = 'SomeRequestID'; $subjectConfirmationData->Address = '127.0.0.1'; $document = DOMDocumentFactory::fromString('<root />'); $subjectConfirmationDataElement = $subjectConfirmationData->toXML($document->firstChild); $subjectConfirmationDataElements = Utils::xpQuery($subjectConfirmationDataElement, '//saml_assertion:SubjectConfirmationData'); $this->assertCount(1, $subjectConfirmationDataElements); $subjectConfirmationDataElement = $subjectConfirmationDataElements[0]; $this->assertEquals('2001-04-19T04:25:21Z', $subjectConfirmationDataElement->getAttribute("NotBefore")); $this->assertEquals('2009-02-13T23:31:30Z', $subjectConfirmationDataElement->getAttribute("NotOnOrAfter")); $this->assertEquals('https://sp.example.org/asdf', $subjectConfirmationDataElement->getAttribute("Recipient")); $this->assertEquals('SomeRequestID', $subjectConfirmationDataElement->getAttribute("InResponseTo")); $this->assertEquals('127.0.0.1', $subjectConfirmationDataElement->getAttribute("Address")); }
/** * Convert this element to XML. * * @param \DOMElement $parent The element we should append to. * @return \DOMElement */ public function toXML(\DOMElement $parent) { assert('is_string($this->publisher)'); assert('is_int($this->creationInstant) || is_null($this->creationInstant)'); assert('is_string($this->publicationId) || is_null($this->publicationId)'); assert('is_array($this->UsagePolicy)'); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS_MDRPI, 'mdrpi:PublicationInfo'); $parent->appendChild($e); $e->setAttribute('publisher', $this->publisher); if ($this->creationInstant !== null) { $e->setAttribute('creationInstant', gmdate('Y-m-d\\TH:i:s\\Z', $this->creationInstant)); } if ($this->publicationId !== null) { $e->setAttribute('publicationId', $this->publicationId); } Utils::addStrings($e, Common::NS_MDRPI, 'mdrpi:UsagePolicy', true, $this->UsagePolicy); return $e; }
/** * Initialize an KeyDescriptor. * * @param \DOMElement|null $xml The XML element we should load. * @throws \Exception */ public function __construct(\DOMElement $xml = null) { if ($xml === null) { return; } if ($xml->hasAttribute('use')) { $this->use = $xml->getAttribute('use'); } $keyInfo = Utils::xpQuery($xml, './ds:KeyInfo'); if (count($keyInfo) > 1) { throw new \Exception('More than one ds:KeyInfo in the KeyDescriptor.'); } elseif (empty($keyInfo)) { throw new \Exception('No ds:KeyInfo in the KeyDescriptor.'); } $this->KeyInfo = new KeyInfo($keyInfo[0]); foreach (Utils::xpQuery($xml, './saml_metadata:EncryptionMethod') as $em) { $this->EncryptionMethod[] = new Chunk($em); } }
public function testMarshalling() { $roleDescriptor = new RoleDescriptorMock(); $roleDescriptor->ID = 'SomeID'; $roleDescriptor->validUntil = 1234567890; $roleDescriptor->cacheDuration = 'PT5000S'; $roleDescriptor->protocolSupportEnumeration = array('protocol1', 'protocol2'); $roleDescriptor->errorURL = 'https://example.org/error'; $document = DOMDocumentFactory::fromString('<root />'); $roleDescriptorElement = $roleDescriptor->toXML($document->firstChild); $roleDescriptorElement = Utils::xpQuery($roleDescriptorElement, '/root/md:RoleDescriptor'); $this->assertCount(1, $roleDescriptorElement); $roleDescriptorElement = $roleDescriptorElement[0]; $this->assertEquals('SomeID', $roleDescriptorElement->getAttribute("ID")); $this->assertEquals('2009-02-13T23:31:30Z', $roleDescriptorElement->getAttribute("validUntil")); $this->assertEquals('PT5000S', $roleDescriptorElement->getAttribute("cacheDuration")); $this->assertEquals('protocol1 protocol2', $roleDescriptorElement->getAttribute("protocolSupportEnumeration")); $this->assertEquals('myns:MyElement', $roleDescriptorElement->getAttributeNS(Constants::NS_XSI, "type")); $this->assertEquals('http://example.org/mynsdefinition', $roleDescriptorElement->lookupNamespaceURI("myns")); }
public function testMarshalling() { $registrationInfo = new RegistrationInfo(); $registrationInfo->registrationAuthority = 'https://ExampleAuthority'; $registrationInfo->registrationInstant = 1234567890; $registrationInfo->RegistrationPolicy = array('en' => 'http://EnglishRegistrationPolicy', 'nl' => 'https://DutchRegistratiebeleid'); $document = DOMDocumentFactory::fromString('<root />'); $xml = $registrationInfo->toXML($document->firstChild); $registrationInfoElements = Utils::xpQuery($xml, '/root/*[local-name()=\'RegistrationInfo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:rpi\']'); $this->assertCount(1, $registrationInfoElements); $registrationInfoElement = $registrationInfoElements[0]; $this->assertEquals('https://ExampleAuthority', $registrationInfoElement->getAttribute("registrationAuthority")); $this->assertEquals('2009-02-13T23:31:30Z', $registrationInfoElement->getAttribute("registrationInstant")); $usagePolicyElements = Utils::xpQuery($registrationInfoElement, './*[local-name()=\'RegistrationPolicy\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:rpi\']'); $this->assertCount(2, $usagePolicyElements); $this->assertEquals('en', $usagePolicyElements[0]->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang")); $this->assertEquals('http://EnglishRegistrationPolicy', $usagePolicyElements[0]->textContent); $this->assertEquals('nl', $usagePolicyElements[1]->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang")); $this->assertEquals('https://DutchRegistratiebeleid', $usagePolicyElements[1]->textContent); }
public function testMarshalling() { $attribute1 = new Attribute(); $attribute1->Name = 'urn:simplesamlphp:v1:simplesamlphp'; $attribute1->NameFormat = 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri'; $attribute1->AttributeValue = array(new AttributeValue('FirstValue'), new AttributeValue('SecondValue')); $attribute2 = new Attribute(); $attribute2->Name = 'foo'; $attribute2->NameFormat = 'urn:simplesamlphp:v1'; $attribute2->AttributeValue = array(new AttributeValue('bar')); $entityAttributes = new EntityAttributes(); $entityAttributes->children[] = $attribute1; $entityAttributes->children[] = $attribute2; $document = DOMDocumentFactory::fromString('<root />'); $xml = $entityAttributes->toXML($document->firstChild); $entityAttributesElements = Utils::xpQuery($xml, '/root/*[local-name()=\'EntityAttributes\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:attribute\']'); $this->assertCount(1, $entityAttributesElements); $entityAttributesElement = $entityAttributesElements[0]; $attributeElements = Utils::xpQuery($entityAttributesElement, './*[local-name()=\'Attribute\' and namespace-uri()=\'urn:oasis:names:tc:SAML:2.0:assertion\']'); $this->assertCount(2, $attributeElements); }