a9c1f838b70c0f06045dda84cb24c9c7062c92df
[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         metadataProvider->init();\r
62         \r
63 \r
64         Locker locker(metadataProvider.get());\r
65         const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);\r
66         TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
67         assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());\r
68         TSM_ASSERT_EQUALS("Unexpected number of roles", 1, descriptor->getIDPSSODescriptors().size());\r
69         TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol)!=NULL);\r
70         TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol2)!=NULL);\r
71 \r
72         auto_ptr<SAML2ArtifactType0004> artifact(\r
73             new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)\r
74             );\r
75         descriptor = metadataProvider->getEntityDescriptor(artifact.get());\r
76         TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
77         assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());\r
78     }\r
79 \r
80     void testFilesystemWithBlacklists() {\r
81         string config = data_path + "saml2/metadata/FilesystemWithBlacklists.xml";\r
82         ifstream in(config.c_str());\r
83         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
84         XercesJanitor<DOMDocument> janitor(doc);\r
85 \r
86         auto_ptr_XMLCh path("path");\r
87         string s = data_path + "saml2/metadata/InCommon-metadata.xml";\r
88         auto_ptr_XMLCh file(s.c_str());\r
89         doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());\r
90 \r
91         auto_ptr<MetadataProvider> metadataProvider(\r
92             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
93             );\r
94         metadataProvider->init();\r
95         \r
96 \r
97         Locker locker(metadataProvider.get());\r
98         const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);\r
99         TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);\r
100         descriptor = metadataProvider->getEntityDescriptor(entityID2);\r
101         TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
102         assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());\r
103     }\r
104 \r
105     void testFilesystemWithWhitelists() {\r
106         string config = data_path + "saml2/metadata/FilesystemWithWhitelists.xml";\r
107         ifstream in(config.c_str());\r
108         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
109         XercesJanitor<DOMDocument> janitor(doc);\r
110 \r
111         auto_ptr_XMLCh path("path");\r
112         string s = data_path + "saml2/metadata/InCommon-metadata.xml";\r
113         auto_ptr_XMLCh file(s.c_str());\r
114         doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());\r
115 \r
116         auto_ptr<MetadataProvider> metadataProvider(\r
117             SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
118             );\r
119         metadataProvider->init();\r
120         \r
121 \r
122         Locker locker(metadataProvider.get());\r
123         const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID2);\r
124         TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);\r
125         descriptor = metadataProvider->getEntityDescriptor(entityID);\r
126         TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
127         assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());\r
128     }\r
129 };\r