Skip to content
Snippets Groups Projects
Commit 0d1599a2 authored by dombenson's avatar dombenson Committed by Thijs Kinkhorst
Browse files

Support metadataxml in config (#820)

* Support metadata XML directly in config
Also consider 'xml' as a key, in addition to 'url' and 'file'.
When provided, attempt to load this directly as a metadata XML string.
This is useful when working with dynamic configuration and external polling of metadata updates.

* Test loading XML from a fixed string
No preexisting test in this area
Adjust XML loader to only get global config in file mode - otherwise it is
unused, and it might pollute the test usage.
Test that an actully invalid config throws an exception, but that minimal valid
(albeit useless) XML is accepted.
parent f651c6a2
No related branches found
No related tags found
No related merge requests found
...@@ -32,15 +32,17 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_ ...@@ -32,15 +32,17 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_
*/ */
protected function __construct($config) protected function __construct($config)
{ {
// get the configuration $src = $srcXml = null;
$globalConfig = SimpleSAML_Configuration::getInstance();
if (array_key_exists('file', $config)) { if (array_key_exists('file', $config)) {
// get the configuration
$globalConfig = SimpleSAML_Configuration::getInstance();
$src = $globalConfig->resolvePath($config['file']); $src = $globalConfig->resolvePath($config['file']);
} elseif (array_key_exists('url', $config)) { } elseif (array_key_exists('url', $config)) {
$src = $config['url']; $src = $config['url'];
} elseif (array_key_exists('xml', $config)) {
$srcXml = $config['xml'];
} else { } else {
throw new Exception("Missing either 'file' or 'url' in XML metadata source configuration."); throw new Exception("Missing one of 'file', 'url' and 'xml' in XML metadata source configuration.");
} }
...@@ -50,7 +52,13 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_ ...@@ -50,7 +52,13 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_
$IdP20 = array(); $IdP20 = array();
$AAD = array(); $AAD = array();
$entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($src); if(isset($src)) {
$entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($src);
} elseif(isset($srcXml)) {
$entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($srcXml);
} else {
throw new Exception("Neither source file path/URI nor string data provided");
}
foreach ($entities as $entityId => $entity) { foreach ($entities as $entityId => $entity) {
$md = $entity->getMetadata1xSP(); $md = $entity->getMetadata1xSP();
if ($md !== null) { if ($md !== null) {
......
<?php
/**
* Class SimpleSAML_Metadata_MetaDataStorageSourceTest
*/
class SimpleSAML_Metadata_MetaDataStorageSourceTest extends PHPUnit_Framework_TestCase
{
/**
* Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig XML bad source
* @expectedException Exception
*/
public function testBadXMLSource() {
SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "foo"=>"baa"]);
}
/**
* Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig invalid static XML source
* @expectedException Exception
*/
public function testInvalidStaticXMLSource() {
$strTestXML = "
<EntityDescriptor ID=\"_12345678-90ab-cdef-1234-567890abcdef\" entityID=\"https://saml.idp/entityid\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\">
</EntityDescriptor>
";
SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
}
/**
* Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig XML static XML source
*/
public function testStaticXMLSource() {
$testEntityId = "https://saml.idp/entityid";
$strTestXML = "
<EntityDescriptor ID=\"_12345678-90ab-cdef-1234-567890abcdef\" entityID=\"$testEntityId\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\">
<RoleDescriptor xsi:type=\"fed:ApplicationServiceType\"
protocolSupportEnumeration=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512 http://schemas.xmlsoap.org/ws/2005/02/trust http://docs.oasis-open.org/wsfed/federation/200706\"
ServiceDisplayName=\"SimpleSAMLphp Test\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:fed=\"http://docs.oasis-open.org/wsfed/federation/200706\">
<NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</NameIDFormat>
<SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" Location=\"https://saml.idp/sso/\"/>
<SingleLogoutService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" Location=\"https://saml.idp/logout/\"/>
</RoleDescriptor>
<IDPSSODescriptor protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\"/>
</EntityDescriptor>
";
// The primary test here is that - in contrast to the others above - this loads without error
// As a secondary thing, check that the entity ID from the static source provided can be extracted
$source = SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
$idpSet = $source->getMetadataSet("saml20-idp-remote");
$this->assertArrayHasKey($testEntityId, $idpSet, "Did not extract expected IdP entity ID from static XML source");
// Finally verify that a different entity ID does not get loaded
$this->assertCount(1, $idpSet, "Unexpectedly got metadata for an alternate entity than that defined");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment