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