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