a6093b18602352737807633b3515301e5c4ecd83
[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/Metadata.h>\r
20 #include <saml/saml2/metadata/MetadataProvider.h>\r
21 \r
22 using namespace opensaml::saml2md;\r
23 using namespace opensaml::saml2p;\r
24 \r
25 class FilesystemMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
26     XMLCh* entityID;\r
27     XMLCh* entityID2;\r
28     XMLCh* supportedProtocol;\r
29     XMLCh* supportedProtocol2;\r
30 \r
31 public:\r
32     void setUp() {\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
38     }\r
39     \r
40     void tearDown() {\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
46     }\r
47 \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
53 \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
58 \r
59         auto_ptr<MetadataProvider> metadataProvider(\r
60             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
61             );\r
62         try {\r
63             metadataProvider->init();\r
64         }\r
65         catch (XMLToolingException& ex) {\r
66             TS_TRACE(ex.what());\r
67             throw;\r
68         }\r
69         \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
77 \r
78         auto_ptr<SAML2ArtifactType0004> artifact(\r
79             new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)\r
80             );\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
84     }\r
85 \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
91 \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
96 \r
97         auto_ptr<MetadataProvider> metadataProvider(\r
98             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
99             );\r
100         try {\r
101             metadataProvider->init();\r
102         }\r
103         catch (XMLToolingException& ex) {\r
104             TS_TRACE(ex.what());\r
105             throw;\r
106         }\r
107 \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
114     }\r
115 \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
121 \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
126 \r
127         auto_ptr<MetadataProvider> metadataProvider(\r
128             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
129             );\r
130         try {\r
131             metadataProvider->init();\r
132         }\r
133         catch (XMLToolingException& ex) {\r
134             TS_TRACE(ex.what());\r
135             throw;\r
136         }\r
137 \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
144     }\r
145 };\r