2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "internal.h"
\r
18 #include <saml/SAMLConfig.h>
\r
19 #include <saml/saml2/binding/SAML2ArtifactType0004.h>
\r
20 #include <saml/saml2/metadata/Metadata.h>
\r
21 #include <saml/saml2/metadata/MetadataProvider.h>
\r
23 using namespace opensaml::saml2md;
\r
24 using namespace opensaml::saml2p;
\r
26 class FilesystemMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
29 XMLCh* supportedProtocol;
\r
30 XMLCh* supportedProtocol2;
\r
34 entityID=XMLString::transcode("urn:mace:incommon:washington.edu");
\r
35 entityID2=XMLString::transcode("urn:mace:incommon:rochester.edu");
\r
36 supportedProtocol=XMLString::transcode("urn:oasis:names:tc:SAML:1.1:protocol");
\r
37 supportedProtocol2=XMLString::transcode("urn:mace:shibboleth:1.0");
\r
38 SAMLObjectBaseTestCase::setUp();
\r
42 XMLString::release(&entityID);
\r
43 XMLString::release(&entityID2);
\r
44 XMLString::release(&supportedProtocol);
\r
45 XMLString::release(&supportedProtocol2);
\r
46 SAMLObjectBaseTestCase::tearDown();
\r
49 void testFilesystemProvider() {
\r
50 string config = data_path + "saml2/metadata/FilesystemMetadataProvider.xml";
\r
51 ifstream in(config.c_str());
\r
52 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
53 XercesJanitor<DOMDocument> janitor(doc);
\r
55 auto_ptr_XMLCh path("path");
\r
56 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
57 auto_ptr_XMLCh file(s.c_str());
\r
58 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
60 auto_ptr<MetadataProvider> metadataProvider(
\r
61 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
64 metadataProvider->init();
\r
66 catch (XMLToolingException& ex) {
\r
67 TS_TRACE(ex.what());
\r
71 Locker locker(metadataProvider.get());
\r
72 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
73 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
74 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r
75 TSM_ASSERT_EQUALS("Unexpected number of roles", 1, descriptor->getIDPSSODescriptors().size());
\r
76 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol)!=NULL);
\r
77 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol2)!=NULL);
\r
79 auto_ptr<SAML2ArtifactType0004> artifact(
\r
80 new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)
\r
82 descriptor = metadataProvider->getEntityDescriptor(artifact.get());
\r
83 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
84 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r
87 void testFilesystemWithBlacklists() {
\r
88 string config = data_path + "saml2/metadata/FilesystemWithBlacklists.xml";
\r
89 ifstream in(config.c_str());
\r
90 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
91 XercesJanitor<DOMDocument> janitor(doc);
\r
93 auto_ptr_XMLCh path("path");
\r
94 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
95 auto_ptr_XMLCh file(s.c_str());
\r
96 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
98 auto_ptr<MetadataProvider> metadataProvider(
\r
99 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
102 metadataProvider->init();
\r
104 catch (XMLToolingException& ex) {
\r
105 TS_TRACE(ex.what());
\r
109 Locker locker(metadataProvider.get());
\r
110 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
111 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
\r
112 descriptor = metadataProvider->getEntityDescriptor(entityID2);
\r
113 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
114 assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());
\r
117 void testFilesystemWithWhitelists() {
\r
118 string config = data_path + "saml2/metadata/FilesystemWithWhitelists.xml";
\r
119 ifstream in(config.c_str());
\r
120 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
121 XercesJanitor<DOMDocument> janitor(doc);
\r
123 auto_ptr_XMLCh path("path");
\r
124 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
125 auto_ptr_XMLCh file(s.c_str());
\r
126 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
128 auto_ptr<MetadataProvider> metadataProvider(
\r
129 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
132 metadataProvider->init();
\r
134 catch (XMLToolingException& ex) {
\r
135 TS_TRACE(ex.what());
\r
139 Locker locker(metadataProvider.get());
\r
140 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID2);
\r
141 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
\r
142 descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
143 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
144 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r