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;
26 class XMLMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
29 XMLCh* supportedProtocol;
30 XMLCh* supportedProtocol2;
34 entityID=XMLString::transcode("urn:mace:incommon:washington.edu");
35 entityID2=XMLString::transcode("urn:mace:incommon:rochester.edu");
36 supportedProtocol=XMLString::transcode("urn:oasis:names:tc:SAML:1.1:protocol");
37 supportedProtocol2=XMLString::transcode("urn:mace:shibboleth:1.0");
38 SAMLObjectBaseTestCase::setUp();
42 XMLString::release(&entityID);
43 XMLString::release(&entityID2);
44 XMLString::release(&supportedProtocol);
45 XMLString::release(&supportedProtocol2);
46 SAMLObjectBaseTestCase::tearDown();
49 void testXMLProvider() {
50 string config = data_path + "saml2/metadata/XMLMetadataProvider.xml";
51 ifstream in(config.c_str());
52 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
53 XercesJanitor<DOMDocument> janitor(doc);
55 auto_ptr_XMLCh path("path");
56 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
57 auto_ptr_XMLCh file(s.c_str());
58 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
60 auto_ptr<MetadataProvider> metadataProvider(
61 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
64 metadataProvider->init();
66 catch (XMLToolingException& ex) {
71 Locker locker(metadataProvider.get());
72 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
73 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
74 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
75 TSM_ASSERT_EQUALS("Unexpected number of roles", 1, descriptor->getIDPSSODescriptors().size());
76 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol)!=NULL);
77 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol2)!=NULL);
79 auto_ptr<SAML2ArtifactType0004> artifact(
80 new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)
82 descriptor = metadataProvider->getEntityDescriptor(artifact.get());
83 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
84 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
87 void testXMLWithBlacklists() {
88 string config = data_path + "saml2/metadata/XMLWithBlacklists.xml";
89 ifstream in(config.c_str());
90 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
91 XercesJanitor<DOMDocument> janitor(doc);
93 auto_ptr_XMLCh path("path");
94 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
95 auto_ptr_XMLCh file(s.c_str());
96 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
98 auto_ptr<MetadataProvider> metadataProvider(
99 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
102 metadataProvider->init();
104 catch (XMLToolingException& ex) {
109 Locker locker(metadataProvider.get());
110 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
111 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
112 descriptor = metadataProvider->getEntityDescriptor(entityID2);
113 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
114 assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());
117 void testXMLWithWhitelists() {
118 string config = data_path + "saml2/metadata/XMLWithWhitelists.xml";
119 ifstream in(config.c_str());
120 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
121 XercesJanitor<DOMDocument> janitor(doc);
123 auto_ptr_XMLCh path("path");
124 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
125 auto_ptr_XMLCh file(s.c_str());
126 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
128 auto_ptr<MetadataProvider> metadataProvider(
129 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
132 metadataProvider->init();
134 catch (XMLToolingException& ex) {
139 Locker locker(metadataProvider.get());
140 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID2);
141 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
142 descriptor = metadataProvider->getEntityDescriptor(entityID);
143 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
144 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());