a6da0a78fafa63e192e526cc9f496bdb7a512740
[shibboleth/cpp-opensaml.git] / samltest / saml2 / metadata / FilesystemMetadataProviderTest.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 #include "internal.h"\r
18 #include <saml/saml2/metadata/MetadataProvider.h>\r
19 \r
20 using namespace opensaml::saml2md;\r
21 \r
22 class FilesystemMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
23     XMLCh* entityID;\r
24     XMLCh* entityID2;\r
25     XMLCh* supportedProtocol;\r
26     XMLCh* supportedProtocol2;\r
27 \r
28 public:\r
29     void setUp() {\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
35     }\r
36     \r
37     void tearDown() {\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
43     }\r
44 \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
50 \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
55 \r
56         auto_ptr<MetadataProvider> metadataProvider(\r
57             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
58             );\r
59         metadataProvider->init();\r
60         \r
61 \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
69     }\r
70 \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
76 \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
81 \r
82         auto_ptr<MetadataProvider> metadataProvider(\r
83             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
84             );\r
85         metadataProvider->init();\r
86         \r
87 \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
94     }\r
95 \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
101 \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
106 \r
107         auto_ptr<MetadataProvider> metadataProvider(\r
108             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
109             );\r
110         metadataProvider->init();\r
111         \r
112 \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
119     }\r
120 };\r