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/metadata/MetadataProvider.h>
\r
20 using namespace opensaml::saml2md;
\r
22 class FilesystemMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
25 XMLCh* supportedProtocol;
\r
26 XMLCh* supportedProtocol2;
\r
30 entityID=XMLString::transcode("urn:mace:incommon:washington.edu");
\r
31 entityID2=XMLString::transcode("urn:mace:incommon:rochester.edu");
\r
32 supportedProtocol=XMLString::transcode("urn:oasis:names:tc:SAML:1.1:protocol");
\r
33 supportedProtocol2=XMLString::transcode("urn:mace:shibboleth:1.0");
\r
34 SAMLObjectBaseTestCase::setUp();
\r
38 XMLString::release(&entityID);
\r
39 XMLString::release(&entityID2);
\r
40 XMLString::release(&supportedProtocol);
\r
41 XMLString::release(&supportedProtocol2);
\r
42 SAMLObjectBaseTestCase::tearDown();
\r
45 void testFilesystemProvider() {
\r
46 string config = data_path + "saml2/metadata/FilesystemMetadataProvider.xml";
\r
47 ifstream in(config.c_str());
\r
48 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
49 XercesJanitor<DOMDocument> janitor(doc);
\r
51 auto_ptr_XMLCh path("path");
\r
52 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
53 auto_ptr_XMLCh file(s.c_str());
\r
54 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
56 auto_ptr<MetadataProvider> metadataProvider(
\r
57 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
59 metadataProvider->init();
\r
62 Locker locker(metadataProvider.get());
\r
63 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
64 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
65 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r
66 TSM_ASSERT_EQUALS("Unexpected number of roles", 1, descriptor->getIDPSSODescriptors().size());
\r
67 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol)!=NULL);
\r
68 TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol2)!=NULL);
\r
71 void testFilesystemWithBlacklists() {
\r
72 string config = data_path + "saml2/metadata/FilesystemWithBlacklists.xml";
\r
73 ifstream in(config.c_str());
\r
74 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
75 XercesJanitor<DOMDocument> janitor(doc);
\r
77 auto_ptr_XMLCh path("path");
\r
78 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
79 auto_ptr_XMLCh file(s.c_str());
\r
80 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
82 auto_ptr<MetadataProvider> metadataProvider(
\r
83 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
85 metadataProvider->init();
\r
88 Locker locker(metadataProvider.get());
\r
89 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
90 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
\r
91 descriptor = metadataProvider->getEntityDescriptor(entityID2);
\r
92 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
93 assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());
\r
96 void testFilesystemWithWhitelists() {
\r
97 string config = data_path + "saml2/metadata/FilesystemWithWhitelists.xml";
\r
98 ifstream in(config.c_str());
\r
99 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
100 XercesJanitor<DOMDocument> janitor(doc);
\r
102 auto_ptr_XMLCh path("path");
\r
103 string s = data_path + "saml2/metadata/InCommon-metadata.xml";
\r
104 auto_ptr_XMLCh file(s.c_str());
\r
105 doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
\r
107 auto_ptr<MetadataProvider> metadataProvider(
\r
108 SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
\r
110 metadataProvider->init();
\r
113 Locker locker(metadataProvider.get());
\r
114 const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID2);
\r
115 TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);
\r
116 descriptor = metadataProvider->getEntityDescriptor(entityID);
\r
117 TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);
\r
118 assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
\r