Correct eol-style property.
[shibboleth/cpp-opensaml.git] / samltest / saml1 / binding / SAML1ArtifactTest.h
index 1449fdb..7dbff70 100644 (file)
-/*\r
- *  Copyright 2001-2009 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/binding/ArtifactMap.h>\r
-#include <saml/saml1/core/Assertions.h>\r
-#include <saml/saml1/core/Protocols.h>\r
-#include <saml/saml1/binding/SAMLArtifactType0001.h>\r
-#include <xmltooling/signature/Signature.h>\r
-#include <xmltooling/validation/ValidatorSuite.h>\r
-\r
-using namespace opensaml::saml1p;\r
-using namespace opensaml::saml1;\r
-\r
-class SAML1ArtifactTest : public CxxTest::TestSuite,\r
-        public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {\r
-public:\r
-    void setUp() {\r
-        SAMLBindingBaseTestCase::setUp();\r
-    }\r
-\r
-    void tearDown() {\r
-        SAMLBindingBaseTestCase::tearDown();\r
-    }\r
-\r
-    void testSAML1Artifact() {\r
-        try {\r
-            xmltooling::QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);\r
-            SecurityPolicy policy(m_metadata, &idprole, m_trust, false);\r
-            policy.getRules().assign(m_rules.begin(), m_rules.end());\r
-\r
-            // Read message to use from file.\r
-            string path = data_path + "saml1/binding/SAML1Assertion.xml";\r
-            ifstream in(path.c_str());\r
-            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
-            XercesJanitor<DOMDocument> janitor(doc);\r
-            auto_ptr<saml1::Assertion> toSend(\r
-                dynamic_cast<saml1::Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))\r
-                );\r
-            janitor.release();\r
-\r
-            CredentialCriteria cc;\r
-            cc.setUsage(Credential::SIGNING_CREDENTIAL);\r
-            Locker clocker(m_creds);\r
-            const Credential* cred = m_creds->resolve(&cc);\r
-            TSM_ASSERT("Retrieved credential was null", cred!=NULL);\r
-\r
-            // Encode message.\r
-            auto_ptr<MessageEncoder> encoder(\r
-                SAMLConfig::getConfig().MessageEncoderManager.newPlugin(\r
-                    samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, pair<const DOMElement*,const XMLCh*>(NULL,NULL)\r
-                    )\r
-                );\r
-            Locker locker(m_metadata);\r
-            encoder->encode(\r
-                *this,\r
-                toSend.get(),\r
-                "https://sp.example.org/SAML/SSO",\r
-                m_metadata->getEntityDescriptor(MetadataProvider::Criteria("https://sp.example.org/")).first,\r
-                "state",\r
-                this,\r
-                cred\r
-                );\r
-            toSend.release();\r
-            \r
-            // Decode message.\r
-            string relayState;\r
-            auto_ptr<MessageDecoder> decoder(\r
-                SAMLConfig::getConfig().MessageDecoderManager.newPlugin(\r
-                    samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, pair<const DOMElement*,const XMLCh*>(NULL,NULL)\r
-                    )\r
-                );\r
-            decoder->setArtifactResolver(this);\r
-            auto_ptr<Response> response(dynamic_cast<Response*>(decoder->decode(relayState,*this,policy)));\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.", policy.isAuthenticated());\r
-            auto_ptr_char entityID(policy.getIssuer()->getName());\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
-            policy.reset();\r
-            TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), BindingException);\r
-        }\r
-        catch (XMLToolingException& ex) {\r
-            TS_TRACE(ex.what());\r
-            throw;\r
-        }\r
-    }\r
-\r
-    SAMLArtifact* generateSAML1Artifact(const EntityDescriptor* relyingParty) const {\r
-        return new SAMLArtifactType0001(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"));\r
-    }\r
-    \r
-    saml2p::SAML2Artifact* generateSAML2Artifact(const EntityDescriptor* relyingParty) const {\r
-        throw BindingException("Not implemented.");\r
-    }\r
-    \r
-    Response* resolve(\r
-        const vector<SAMLArtifact*>& artifacts,\r
-        const IDPSSODescriptor& idpDescriptor,\r
-        SecurityPolicy& policy\r
-        ) const {\r
-        TSM_ASSERT_EQUALS("Too many artifacts.", artifacts.size(), 1);\r
-        XMLObject* xmlObject =\r
-            SAMLConfig::getConfig().getArtifactMap()->retrieveContent(artifacts.front(), "https://sp.example.org/");\r
-        saml1::Assertion* assertion = dynamic_cast<saml1::Assertion*>(xmlObject);\r
-        TSM_ASSERT("Not an assertion.", assertion!=NULL);\r
-        auto_ptr<Response> response(ResponseBuilder::buildResponse());\r
-        response->getAssertions().push_back(assertion);\r
-        Status* status = StatusBuilder::buildStatus();\r
-        response->setStatus(status);\r
-        StatusCode* sc = StatusCodeBuilder::buildStatusCode();\r
-        status->setStatusCode(sc);\r
-        sc->setValue(&StatusCode::SUCCESS);\r
-        response->setSignature(SignatureBuilder::buildSignature());\r
-        vector<Signature*> sigs(1,response->getSignature());\r
-        CredentialCriteria cc;\r
-        cc.setUsage(Credential::SIGNING_CREDENTIAL);\r
-        Locker clocker(m_creds);\r
-        const Credential* cred = m_creds->resolve(&cc);\r
-        TSM_ASSERT("Retrieved credential was null", cred!=NULL);\r
-        response->marshall((DOMDocument*)NULL,&sigs,cred);\r
-        SchemaValidators.validate(response.get());\r
-        policy.evaluate(*(response.get()), this);\r
-        return response.release();\r
-    }\r
-\r
-    saml2p::ArtifactResponse* resolve(\r
-        const saml2p::SAML2Artifact& artifact,\r
-        const SSODescriptorType& ssoDescriptor,\r
-        SecurityPolicy& policy\r
-        ) const {\r
-        throw BindingException("Not implemented.");\r
-    }\r
-};\r
+/*
+ *  Copyright 2001-2009 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/binding/ArtifactMap.h>
+#include <saml/saml1/core/Assertions.h>
+#include <saml/saml1/core/Protocols.h>
+#include <saml/saml1/binding/SAMLArtifactType0001.h>
+#include <xmltooling/signature/Signature.h>
+#include <xmltooling/validation/ValidatorSuite.h>
+
+using namespace opensaml::saml1p;
+using namespace opensaml::saml1;
+
+class SAML1ArtifactTest : public CxxTest::TestSuite,
+        public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {
+public:
+    void setUp() {
+        SAMLBindingBaseTestCase::setUp();
+    }
+
+    void tearDown() {
+        SAMLBindingBaseTestCase::tearDown();
+    }
+
+    void testSAML1Artifact() {
+        try {
+            xmltooling::QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
+            SecurityPolicy policy(m_metadata, &idprole, m_trust, false);
+            policy.getRules().assign(m_rules.begin(), m_rules.end());
+
+            // Read message to use from file.
+            string path = data_path + "saml1/binding/SAML1Assertion.xml";
+            ifstream in(path.c_str());
+            DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
+            XercesJanitor<DOMDocument> janitor(doc);
+            auto_ptr<saml1::Assertion> toSend(
+                dynamic_cast<saml1::Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
+                );
+            janitor.release();
+
+            CredentialCriteria cc;
+            cc.setUsage(Credential::SIGNING_CREDENTIAL);
+            Locker clocker(m_creds);
+            const Credential* cred = m_creds->resolve(&cc);
+            TSM_ASSERT("Retrieved credential was null", cred!=NULL);
+
+            // Encode message.
+            auto_ptr<MessageEncoder> encoder(
+                SAMLConfig::getConfig().MessageEncoderManager.newPlugin(
+                    samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, pair<const DOMElement*,const XMLCh*>(NULL,NULL)
+                    )
+                );
+            Locker locker(m_metadata);
+            encoder->encode(
+                *this,
+                toSend.get(),
+                "https://sp.example.org/SAML/SSO",
+                m_metadata->getEntityDescriptor(MetadataProvider::Criteria("https://sp.example.org/")).first,
+                "state",
+                this,
+                cred
+                );
+            toSend.release();
+            
+            // Decode message.
+            string relayState;
+            auto_ptr<MessageDecoder> decoder(
+                SAMLConfig::getConfig().MessageDecoderManager.newPlugin(
+                    samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, pair<const DOMElement*,const XMLCh*>(NULL,NULL)
+                    )
+                );
+            decoder->setArtifactResolver(this);
+            auto_ptr<Response> response(dynamic_cast<Response*>(decoder->decode(relayState,*this,policy)));
+            
+            // 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.", policy.isAuthenticated());
+            auto_ptr_char entityID(policy.getIssuer()->getName());
+            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.
+            policy.reset();
+            TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), BindingException);
+        }
+        catch (XMLToolingException& ex) {
+            TS_TRACE(ex.what());
+            throw;
+        }
+    }
+
+    SAMLArtifact* generateSAML1Artifact(const EntityDescriptor* relyingParty) const {
+        return new SAMLArtifactType0001(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"));
+    }
+    
+    saml2p::SAML2Artifact* generateSAML2Artifact(const EntityDescriptor* relyingParty) const {
+        throw BindingException("Not implemented.");
+    }
+    
+    Response* resolve(
+        const vector<SAMLArtifact*>& artifacts,
+        const IDPSSODescriptor& idpDescriptor,
+        SecurityPolicy& policy
+        ) const {
+        TSM_ASSERT_EQUALS("Too many artifacts.", artifacts.size(), 1);
+        XMLObject* xmlObject =
+            SAMLConfig::getConfig().getArtifactMap()->retrieveContent(artifacts.front(), "https://sp.example.org/");
+        saml1::Assertion* assertion = dynamic_cast<saml1::Assertion*>(xmlObject);
+        TSM_ASSERT("Not an assertion.", assertion!=NULL);
+        auto_ptr<Response> response(ResponseBuilder::buildResponse());
+        response->getAssertions().push_back(assertion);
+        Status* status = StatusBuilder::buildStatus();
+        response->setStatus(status);
+        StatusCode* sc = StatusCodeBuilder::buildStatusCode();
+        status->setStatusCode(sc);
+        sc->setValue(&StatusCode::SUCCESS);
+        response->setSignature(SignatureBuilder::buildSignature());
+        vector<Signature*> sigs(1,response->getSignature());
+        CredentialCriteria cc;
+        cc.setUsage(Credential::SIGNING_CREDENTIAL);
+        Locker clocker(m_creds);
+        const Credential* cred = m_creds->resolve(&cc);
+        TSM_ASSERT("Retrieved credential was null", cred!=NULL);
+        response->marshall((DOMDocument*)NULL,&sigs,cred);
+        SchemaValidators.validate(response.get());
+        policy.evaluate(*(response.get()), this);
+        return response.release();
+    }
+
+    saml2p::ArtifactResponse* resolve(
+        const saml2p::SAML2Artifact& artifact,
+        const SSODescriptorType& ssoDescriptor,
+        SecurityPolicy& policy
+        ) const {
+        throw BindingException("Not implemented.");
+    }
+};