Moved artifact source code into binding folders.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / metadata / FilesystemMetadataProviderTest.h
index 049ab31..3e736ba 100644 (file)
  */\r
 \r
 #include "internal.h"\r
+#include <saml/SAMLConfig.h>\r
+#include <saml/saml2/binding/SAML2ArtifactType0004.h>\r
+#include <saml/saml2/metadata/Metadata.h>\r
 #include <saml/saml2/metadata/MetadataProvider.h>\r
 \r
 using namespace opensaml::saml2md;\r
+using namespace opensaml::saml2p;\r
 \r
 class FilesystemMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
     XMLCh* entityID;\r
+    XMLCh* entityID2;\r
     XMLCh* supportedProtocol;\r
     XMLCh* supportedProtocol2;\r
-    MetadataProvider* metadataProvider;\r
 \r
 public:\r
     void setUp() {\r
         entityID=XMLString::transcode("urn:mace:incommon:washington.edu");\r
+        entityID2=XMLString::transcode("urn:mace:incommon:rochester.edu");\r
         supportedProtocol=XMLString::transcode("urn:oasis:names:tc:SAML:1.1:protocol");\r
         supportedProtocol2=XMLString::transcode("urn:mace:shibboleth:1.0");\r
-        \r
-        auto_ptr_XMLCh MP("MetadataProvider");\r
-        auto_ptr_XMLCh path("path");\r
-        auto_ptr_XMLCh validate("validate");\r
-        string s=data_path + "saml2/metadata/InCommon-metadata.xml";\r
-        auto_ptr_XMLCh file(s.c_str());\r
-        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().newDocument();\r
-        XercesJanitor<DOMDocument> janitor(doc);\r
-        DOMElement* root=doc->createElementNS(NULL,MP.get());\r
-        root->setAttributeNS(NULL,path.get(),file.get());\r
-        root->setAttributeNS(NULL,validate.get(),XMLConstants::XML_ZERO);\r
-        metadataProvider = NULL;\r
-        metadataProvider = SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,root);\r
-        metadataProvider->init();\r
-        \r
         SAMLObjectBaseTestCase::setUp();\r
     }\r
     \r
     void tearDown() {\r
         XMLString::release(&entityID);\r
+        XMLString::release(&entityID2);\r
         XMLString::release(&supportedProtocol);\r
-        delete metadataProvider;\r
+        XMLString::release(&supportedProtocol2);\r
         SAMLObjectBaseTestCase::tearDown();\r
     }\r
 \r
-    void testEntityDescriptor() {\r
-        Locker locker(metadataProvider);\r
+    void testFilesystemProvider() {\r
+        string config = data_path + "saml2/metadata/FilesystemMetadataProvider.xml";\r
+        ifstream in(config.c_str());\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
+        XercesJanitor<DOMDocument> janitor(doc);\r
+\r
+        auto_ptr_XMLCh path("path");\r
+        string s = data_path + "saml2/metadata/InCommon-metadata.xml";\r
+        auto_ptr_XMLCh file(s.c_str());\r
+        doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());\r
+\r
+        auto_ptr<MetadataProvider> metadataProvider(\r
+            SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
+            );\r
+        try {\r
+            metadataProvider->init();\r
+        }\r
+        catch (XMLToolingException& ex) {\r
+            TS_TRACE(ex.what());\r
+            throw;\r
+        }\r
+        \r
+        Locker locker(metadataProvider.get());\r
         const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);\r
         TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
         assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());\r
         TSM_ASSERT_EQUALS("Unexpected number of roles", 1, descriptor->getIDPSSODescriptors().size());\r
         TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol)!=NULL);\r
         TSM_ASSERT("Role lookup failed", descriptor->getIDPSSODescriptor(supportedProtocol2)!=NULL);\r
+\r
+        auto_ptr<SAML2ArtifactType0004> artifact(\r
+            new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)\r
+            );\r
+        descriptor = metadataProvider->getEntityDescriptor(artifact.get());\r
+        TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
+        assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());\r
     }\r
 \r
+    void testFilesystemWithBlacklists() {\r
+        string config = data_path + "saml2/metadata/FilesystemWithBlacklists.xml";\r
+        ifstream in(config.c_str());\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
+        XercesJanitor<DOMDocument> janitor(doc);\r
+\r
+        auto_ptr_XMLCh path("path");\r
+        string s = data_path + "saml2/metadata/InCommon-metadata.xml";\r
+        auto_ptr_XMLCh file(s.c_str());\r
+        doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());\r
+\r
+        auto_ptr<MetadataProvider> metadataProvider(\r
+            SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
+            );\r
+        try {\r
+            metadataProvider->init();\r
+        }\r
+        catch (XMLToolingException& ex) {\r
+            TS_TRACE(ex.what());\r
+            throw;\r
+        }\r
+\r
+        Locker locker(metadataProvider.get());\r
+        const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID);\r
+        TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);\r
+        descriptor = metadataProvider->getEntityDescriptor(entityID2);\r
+        TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
+        assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());\r
+    }\r
+\r
+    void testFilesystemWithWhitelists() {\r
+        string config = data_path + "saml2/metadata/FilesystemWithWhitelists.xml";\r
+        ifstream in(config.c_str());\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
+        XercesJanitor<DOMDocument> janitor(doc);\r
+\r
+        auto_ptr_XMLCh path("path");\r
+        string s = data_path + "saml2/metadata/InCommon-metadata.xml";\r
+        auto_ptr_XMLCh file(s.c_str());\r
+        doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());\r
+\r
+        auto_ptr<MetadataProvider> metadataProvider(\r
+            SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())\r
+            );\r
+        try {\r
+            metadataProvider->init();\r
+        }\r
+        catch (XMLToolingException& ex) {\r
+            TS_TRACE(ex.what());\r
+            throw;\r
+        }\r
+\r
+        Locker locker(metadataProvider.get());\r
+        const EntityDescriptor* descriptor = metadataProvider->getEntityDescriptor(entityID2);\r
+        TSM_ASSERT("Retrieved entity descriptor was not null", descriptor==NULL);\r
+        descriptor = metadataProvider->getEntityDescriptor(entityID);\r
+        TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);\r
+        assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());\r
+    }\r
 };\r