2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <saml/SAMLConfig.h>
19 #include <saml/saml2/binding/SAML2ArtifactType0004.h>
20 #include <saml/saml2/metadata/Metadata.h>
21 #include <saml/saml2/metadata/MetadataProvider.h>
23 using namespace opensaml::saml2md;
24 using namespace opensaml::saml2p;
25 using namespace opensaml;
27 class XMLMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
30 XMLCh* supportedProtocol;
31 XMLCh* supportedProtocol2;
35 entityID=XMLString::transcode("urn:mace:incommon:washington.edu");
36 entityID2=XMLString::transcode("urn:mace:incommon:rochester.edu");
37 supportedProtocol=XMLString::transcode("urn:oasis:names:tc:SAML:1.1:protocol");
38 supportedProtocol2=XMLString::transcode("urn:mace:shibboleth:1.0");
39 SAMLObjectBaseTestCase::setUp();
43 XMLString::release(&entityID);
44 XMLString::release(&entityID2);
45 XMLString::release(&supportedProtocol);
46 XMLString::release(&supportedProtocol2);
47 SAMLObjectBaseTestCase::tearDown();
50 void testXMLProvider() {
51 string config = data_path + "saml2/metadata/XMLMetadataProvider.xml";
52 ifstream in(config.c_str());
53 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
54 XercesJanitor<DOMDocument> janitor(doc);
56 auto_ptr_XMLCh path("path");
57 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
58 auto_ptr_XMLCh file(s.c_str());
59 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
61 auto_ptr<MetadataProvider> metadataProvider(
62 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
65 metadataProvider->init();
67 catch (XMLToolingException& ex) {
72 Locker locker(metadataProvider.get());
73 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(MetadataProvider::Criteria(entityID)).first;
74 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
75 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
76 TSM_ASSERT_EQUALS("Unexpected number of roles", 1, descriptor->getIDPSSODescriptors().size());
77 TSM_ASSERT("Role lookup failed", find_if(descriptor->getIDPSSODescriptors(), isValidForProtocol(supportedProtocol))!=NULL);
78 TSM_ASSERT("Role lookup failed", find_if(descriptor->getIDPSSODescriptors(), isValidForProtocol(supportedProtocol2))!=NULL);
80 auto_ptr<SAML2ArtifactType0004> artifact(
81 new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)
83 descriptor = metadataProvider->getEntityDescriptor(MetadataProvider::Criteria(artifact.get())).first;
84 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
85 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
88 void testXMLWithBlacklists() {
89 string config = data_path + "saml2/metadata/XMLWithBlacklists.xml";
90 ifstream in(config.c_str());
91 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
92 XercesJanitor<DOMDocument> janitor(doc);
94 auto_ptr_XMLCh path("path");
95 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
96 auto_ptr_XMLCh file(s.c_str());
97 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
99 auto_ptr<MetadataProvider> metadataProvider(
100 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
103 metadataProvider->init();
105 catch (XMLToolingException& ex) {
110 Locker locker(metadataProvider.get());
111 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(MetadataProvider::Criteria(entityID)).first;
112 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
113 descriptor = metadataProvider->getEntityDescriptor(MetadataProvider::Criteria(entityID2)).first;
114 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
115 assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());
118 void testXMLWithWhitelists() {
119 string config = data_path + "saml2/metadata/XMLWithWhitelists.xml";
120 ifstream in(config.c_str());
121 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
122 XercesJanitor<DOMDocument> janitor(doc);
124 auto_ptr_XMLCh path("path");
125 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
126 auto_ptr_XMLCh file(s.c_str());
127 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
129 auto_ptr<MetadataProvider> metadataProvider(
130 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
133 metadataProvider->init();
135 catch (XMLToolingException& ex) {
140 Locker locker(metadataProvider.get());
141 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(MetadataProvider::Criteria(entityID2)).first;
142 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
143 descriptor = metadataProvider->getEntityDescriptor(MetadataProvider::Criteria(entityID)).first;
144 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
145 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());