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/saml2/core/SAML2ArtifactType0004.h>
\r
19 #include <saml/saml2/metadata/Metadata.h>
\r
20 #include <saml/saml2/metadata/MetadataProvider.h>
\r
22 using namespace opensaml::saml2md;
\r
23 using namespace opensaml::saml2p;
\r
25 class FilesystemMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
28 XMLCh* supportedProtocol;
\r
29 XMLCh* supportedProtocol2;
\r
33 entityID=XMLString::transcode("urn:mace:incommon:washington.edu");
\r
34 entityID2=XMLString::transcode("urn:mace:incommon:rochester.edu");
\r
35 supportedProtocol=XMLString::transcode("urn:oasis:names:tc:SAML:1.1:protocol");
\r
36 supportedProtocol2=XMLString::transcode("urn:mace:shibboleth:1.0");
\r
37 SAMLObjectBaseTestCase::setUp();
\r
41 XMLString::release(&entityID);
\r
42 XMLString::release(&entityID2);
\r
43 XMLString::release(&supportedProtocol);
\r
44 XMLString::release(&supportedProtocol2);
\r
45 SAMLObjectBaseTestCase::tearDown();
\r
48 void testFilesystemProvider() {
\r
49 string config = data_path + "saml2/metadata/FilesystemMetadataProvider.xml";
\r
50 ifstream in(config.c_str());
\r
51 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
52 XercesJanitor<DOMDocument> janitor(doc);
\r
54 auto_ptr_XMLCh path("path");
\r
55 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
56 auto_ptr_XMLCh file(s.c_str());
\r
57 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
59 auto_ptr<MetadataProvider> metadataProvider(
\r
60 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
63 metadataProvider->init();
\r
65 catch (XMLToolingException& ex) {
\r
66 TS_TRACE(ex.what());
\r
70 Locker locker(metadataProvider.get());
\r
71 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
72 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
73 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r
74 TSM_ASSERT_EQUALS("Unexpected number of roles", 1, descriptor->getIDPSSODescriptors().size());
\r
75 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol)!=NULL);
\r
76 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol2)!=NULL);
\r
78 auto_ptr<SAML2ArtifactType0004> artifact(
\r
79 new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)
\r
81 descriptor = metadataProvider->getEntityDescriptor(artifact.get());
\r
82 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
83 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r
86 void testFilesystemWithBlacklists() {
\r
87 string config = data_path + "saml2/metadata/FilesystemWithBlacklists.xml";
\r
88 ifstream in(config.c_str());
\r
89 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
90 XercesJanitor<DOMDocument> janitor(doc);
\r
92 auto_ptr_XMLCh path("path");
\r
93 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
94 auto_ptr_XMLCh file(s.c_str());
\r
95 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
97 auto_ptr<MetadataProvider> metadataProvider(
\r
98 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
101 metadataProvider->init();
\r
103 catch (XMLToolingException& ex) {
\r
104 TS_TRACE(ex.what());
\r
108 Locker locker(metadataProvider.get());
\r
109 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
110 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
\r
111 descriptor = metadataProvider->getEntityDescriptor(entityID2);
\r
112 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
113 assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());
\r
116 void testFilesystemWithWhitelists() {
\r
117 string config = data_path + "saml2/metadata/FilesystemWithWhitelists.xml";
\r
118 ifstream in(config.c_str());
\r
119 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
120 XercesJanitor<DOMDocument> janitor(doc);
\r
122 auto_ptr_XMLCh path("path");
\r
123 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
124 auto_ptr_XMLCh file(s.c_str());
\r
125 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
127 auto_ptr<MetadataProvider> metadataProvider(
\r
128 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
131 metadataProvider->init();
\r
133 catch (XMLToolingException& ex) {
\r
134 TS_TRACE(ex.what());
\r
138 Locker locker(metadataProvider.get());
\r
139 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID2);
\r
140 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
\r
141 descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
142 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
143 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r