public function validateXML() { if (!isset($this->metadataXML)) { throw new Exception('Metadata not available.'); } $doc = new DOMDocument(); $res = $doc->loadXML($this->metadataXML); if ($res !== TRUE) { throw new Exception('Failed to parse Metadata XML: ' . $this->metadataXML); } # echo '<pre>'; print_r($res); $val = SimpleSAML_Utilities::validateXML($doc, 'saml-schema-metadata-2.0.xsd'); if ($val) { $this->setResult(sspmod_fedlab_Tester::STATUS_FATAL, 'metadata', 'metadata_schemavalid', 'Metadata MUST be schema valid', $val); } else { $this->setResult(sspmod_fedlab_Tester::STATUS_OK, 'metadata', 'metadata_schemavalid', 'Metadata MUST be schema valid'); } }
} $metadata = $doc->firstChild; /* Check that the metadata is an EntityDescriptor */ if (!SimpleSAML_Utilities::isDOMElementOfType($metadata, 'EntityDescriptor', '@md')) { $t->data['status'] = 'notentitydescriptor'; $t->show(); exit; } /* Check that the entity id of the metadata matches the URL. */ $entityId = $metadata->getAttribute('entityID'); if ($entityId !== $url) { $t->data['status'] = 'entityid'; $t->data['errortext'] = 'Entity id: ' . $entityId . "\n" . 'URL: ' . $url . "\n"; $t->show(); exit; } /* Validate the metadata against the metadata schema (if enabled). */ if ($metaConfig->getBoolean('metashare.validateschema')) { $errors = SimpleSAML_Utilities::validateXML($doc, 'saml-schema-metadata-2.0.xsd'); if ($errors !== '') { $t->data['status'] = 'validation'; $t->data['errortext'] = $errors; $t->show(); exit; } } /* Add the metadata to the metadata store. */ $store->addMetadata($metadata); $t->data['status'] = 'ok'; $t->show(); exit;