Fix linefeeds
[shibboleth/cpp-opensaml.git] / samltest / saml1 / binding / SAML1POSTTest.h
index 27e96ee..6872867 100644 (file)
-/*\r
- *  Copyright 2001-2005 Internet2\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-#include "binding.h"\r
-\r
-#include <saml/saml1/core/Protocols.h>\r
-\r
-using namespace opensaml::saml1p;\r
-using namespace opensaml::saml1;\r
-\r
-class SAML1POSTTest : public CxxTest::TestSuite, public SAMLBindingBaseTestCase {\r
-public:\r
-    void setUp() {\r
-        m_fields.clear();\r
-        SAMLBindingBaseTestCase::setUp();\r
-    }\r
-\r
-    void tearDown() {\r
-        m_fields.clear();\r
-        SAMLBindingBaseTestCase::tearDown();\r
-    }\r
-\r
-    void testSAML1POSTTrusted() {\r
-        try {\r
-            // Read message to use from file.\r
-            string path = data_path + "saml1/binding/SAML1Response.xml";\r
-            ifstream in(path.c_str());\r
-            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
-            XercesJanitor<DOMDocument> janitor(doc);\r
-            auto_ptr<Response> toSend(\r
-                dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))\r
-                );\r
-            janitor.release();\r
-\r
-            // Freshen timestamp.\r
-            toSend->setIssueInstant(time(NULL));\r
-    \r
-            // Encode message.\r
-            auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));\r
-            encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state",m_creds);\r
-            toSend.release();\r
-            \r
-            // Decode message.\r
-            string relayState;\r
-            const RoleDescriptor* issuer=NULL;\r
-            bool trusted=false;\r
-            QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);\r
-            auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));\r
-            Locker locker(m_metadata);\r
-            auto_ptr<Response> response(\r
-                dynamic_cast<Response*>(\r
-                    decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust)\r
-                    )\r
-                );\r
-            \r
-            // Test the results.\r
-            TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");\r
-            TSM_ASSERT("SAML Response not decoded successfully.", response.get());\r
-            TSM_ASSERT("Message was not verified.", issuer && trusted);\r
-            auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());\r
-            TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));\r
-            TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);\r
-        }\r
-        catch (XMLToolingException& ex) {\r
-            TS_TRACE(ex.what());\r
-            throw;\r
-        }\r
-    }\r
-\r
-    void testSAML1POSTUntrusted() {\r
-        try {\r
-            // Read message to use from file.\r
-            string path = data_path + "saml1/binding/SAML1Response.xml";\r
-            ifstream in(path.c_str());\r
-            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
-            XercesJanitor<DOMDocument> janitor(doc);\r
-            auto_ptr<Response> toSend(\r
-                dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))\r
-                );\r
-            janitor.release();\r
-\r
-            // Freshen timestamp and clear ID.\r
-            toSend->setIssueInstant(time(NULL));\r
-            toSend->setResponseID(NULL);\r
-    \r
-            // Encode message.\r
-            auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));\r
-            encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state");\r
-            toSend.release();\r
-            \r
-            // Decode message.\r
-            string relayState;\r
-            const RoleDescriptor* issuer=NULL;\r
-            bool trusted=false;\r
-            QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);\r
-            auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));\r
-            Locker locker(m_metadata);\r
-            auto_ptr<Response> response(\r
-                dynamic_cast<Response*>(\r
-                    decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole)\r
-                    )\r
-                );\r
-            \r
-            // Test the results.\r
-            TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");\r
-            TSM_ASSERT("SAML Response not decoded successfully.", response.get());\r
-            TSM_ASSERT("Message was verified.", issuer && !trusted);\r
-            auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());\r
-            TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));\r
-            TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);\r
-\r
-            // Trigger a replay.\r
-            TSM_ASSERT_THROWS("Did not catch the replay.", \r
-                decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust),\r
-                BindingException);\r
-        }\r
-        catch (XMLToolingException& ex) {\r
-            TS_TRACE(ex.what());\r
-            throw;\r
-        }\r
-    }\r
-\r
-    const char* getMethod() const {\r
-        return "POST";\r
-    } \r
-\r
-    const char* getRequestURL() const {\r
-        return "https://sp.example.org/SAML/POST";\r
-    }\r
-    \r
-    const char* getQueryString() const {\r
-        return NULL;\r
-    }\r
-};\r
+/*
+ *  Copyright 2001-2005 Internet2
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "binding.h"
+
+#include <saml/saml1/core/Protocols.h>
+
+using namespace opensaml::saml1p;
+using namespace opensaml::saml1;
+
+class SAML1POSTTest : public CxxTest::TestSuite, public SAMLBindingBaseTestCase {
+public:
+    void setUp() {
+        m_fields.clear();
+        SAMLBindingBaseTestCase::setUp();
+    }
+
+    void tearDown() {
+        m_fields.clear();
+        SAMLBindingBaseTestCase::tearDown();
+    }
+
+    void testSAML1POSTTrusted() {
+        try {
+            // Read message to use from file.
+            string path = data_path + "saml1/binding/SAML1Response.xml";
+            ifstream in(path.c_str());
+            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
+            XercesJanitor<DOMDocument> janitor(doc);
+            auto_ptr<Response> toSend(
+                dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
+                );
+            janitor.release();
+
+            // Freshen timestamp.
+            toSend->setIssueInstant(time(NULL));
+    
+            // Encode message.
+            auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));
+            encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state",m_creds);
+            toSend.release();
+            
+            // Decode message.
+            string relayState;
+            const RoleDescriptor* issuer=NULL;
+            bool trusted=false;
+            QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
+            auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));
+            Locker locker(m_metadata);
+            auto_ptr<Response> response(
+                dynamic_cast<Response*>(
+                    decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust)
+                    )
+                );
+            
+            // Test the results.
+            TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
+            TSM_ASSERT("SAML Response not decoded successfully.", response.get());
+            TSM_ASSERT("Message was not verified.", issuer && trusted);
+            auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
+            TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
+            TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
+        }
+        catch (XMLToolingException& ex) {
+            TS_TRACE(ex.what());
+            throw;
+        }
+    }
+
+    void testSAML1POSTUntrusted() {
+        try {
+            // Read message to use from file.
+            string path = data_path + "saml1/binding/SAML1Response.xml";
+            ifstream in(path.c_str());
+            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
+            XercesJanitor<DOMDocument> janitor(doc);
+            auto_ptr<Response> toSend(
+                dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
+                );
+            janitor.release();
+
+            // Freshen timestamp and clear ID.
+            toSend->setIssueInstant(time(NULL));
+            toSend->setResponseID(NULL);
+    
+            // Encode message.
+            auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));
+            encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state");
+            toSend.release();
+            
+            // Decode message.
+            string relayState;
+            const RoleDescriptor* issuer=NULL;
+            bool trusted=false;
+            QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
+            auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));
+            Locker locker(m_metadata);
+            auto_ptr<Response> response(
+                dynamic_cast<Response*>(
+                    decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole)
+                    )
+                );
+            
+            // Test the results.
+            TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
+            TSM_ASSERT("SAML Response not decoded successfully.", response.get());
+            TSM_ASSERT("Message was verified.", issuer && !trusted);
+            auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
+            TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
+            TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
+
+            // Trigger a replay.
+            TSM_ASSERT_THROWS("Did not catch the replay.", 
+                decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust),
+                BindingException);
+        }
+        catch (XMLToolingException& ex) {
+            TS_TRACE(ex.what());
+            throw;
+        }
+    }
+
+    const char* getMethod() const {
+        return "POST";
+    } 
+
+    const char* getRequestURL() const {
+        return "https://sp.example.org/SAML/POST";
+    }
+    
+    const char* getQueryString() const {
+        return NULL;
+    }
+};