X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-opensaml.git;a=blobdiff_plain;f=samltest%2Fsaml2%2Fcore%2Fimpl%2FArtifactResponse20Test.h;h=23a001787b8142edde27f60728de105f4cf8765d;hp=2e46e217a5cf065625bd9f4fad45978bcd5f4c1a;hb=1ffcb743f90aeb3da11054316f3d005ff7edbf7b;hpb=e8d75900802dfa84c06290f88e365fd355ce6881 diff --git a/samltest/saml2/core/impl/ArtifactResponse20Test.h b/samltest/saml2/core/impl/ArtifactResponse20Test.h index 2e46e21..23a0017 100644 --- a/samltest/saml2/core/impl/ArtifactResponse20Test.h +++ b/samltest/saml2/core/impl/ArtifactResponse20Test.h @@ -1,155 +1,155 @@ -/* - * Copyright 2001-2006 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 "internal.h" -#include -#include - -using namespace opensaml::saml2p; -using namespace opensaml::saml2; - -class ArtifactResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase { - XMLCh* expectedID; - XMLCh* expectedInResponseTo; - XMLCh* expectedVersion; - XMLCh* expectedConsent; - XMLCh* expectedDestination; - DateTime* expectedIssueInstant; - - // The payload will be an AuthnRequest in this test. - // AuthnRequest marshaller autogenerates ID, Version and IssueInstant if they are NULL, - // so have to agree on something to put in the control XML - XMLCh* authnRequestID; - -public: - void setUp() { - expectedID = XMLString::transcode("def456"); - expectedInResponseTo = XMLString::transcode("abc123"); - expectedVersion = XMLString::transcode("2.0"); - expectedConsent = XMLString::transcode("urn:string:consent"); - expectedDestination = XMLString::transcode("http://sp.example.org/endpoint"); - expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z")); - expectedIssueInstant->parseDateTime(); - - authnRequestID = XMLString::transcode("test1"); - - singleElementFile = data_path + "saml2/core/impl/ArtifactResponse.xml"; - singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ArtifactResponseOptionalAttributes.xml"; - childElementsFile = data_path + "saml2/core/impl/ArtifactResponseChildElements.xml"; - SAMLObjectBaseTestCase::setUp(); - } - - void tearDown() { - XMLString::release(&expectedID); - XMLString::release(&expectedInResponseTo); - XMLString::release(&expectedVersion); - XMLString::release(&expectedConsent); - XMLString::release(&expectedDestination); - XMLString::release(&authnRequestID); - delete expectedIssueInstant; - SAMLObjectBaseTestCase::tearDown(); - } - - void testSingleElementUnmarshall() { - auto_ptr xo(unmarshallElement(singleElementFile)); - ArtifactResponse* response = dynamic_cast(xo.get()); - TS_ASSERT(response!=NULL); - - assertEquals("ID attribute", expectedID, response->getID()); - assertEquals("Version attribute", expectedVersion, response->getVersion()); - TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch()); - - TS_ASSERT(response->getIssuer()==NULL); - TS_ASSERT(response->getSignature()==NULL); - TS_ASSERT(response->getExtensions()==NULL); - TS_ASSERT(response->getStatus()==NULL); - TS_ASSERT(response->getPayload()==NULL); - } - - void testSingleElementOptionalAttributesUnmarshall() { - auto_ptr xo(unmarshallElement(singleElementOptionalAttributesFile)); - ArtifactResponse* response = dynamic_cast(xo.get()); - TS_ASSERT(response!=NULL); - - assertEquals("Consent attribute", expectedConsent, response->getConsent()); - assertEquals("Destination attribute", expectedDestination, response->getDestination()); - assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo()); - - TS_ASSERT(response->getIssuer()==NULL); - TS_ASSERT(response->getSignature()==NULL); - TS_ASSERT(response->getExtensions()==NULL); - TS_ASSERT(response->getStatus()==NULL); - TS_ASSERT(response->getPayload()==NULL); - } - - void testChildElementsUnmarshall() { - auto_ptr xo(unmarshallElement(childElementsFile)); - ArtifactResponse* response= dynamic_cast(xo.get()); - TS_ASSERT(response!=NULL); - - TS_ASSERT(response->getIssuer()!=NULL); - TS_ASSERT(response->getSignature()==NULL); - TS_ASSERT(response->getExtensions()==NULL); - TS_ASSERT(response->getStatus()!=NULL); - TS_ASSERT(response->getPayload()!=NULL); - } - - void testSingleElementMarshall() { - ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse(); - TS_ASSERT(response!=NULL); - - response->setID(expectedID); - response->setIssueInstant(expectedIssueInstant); - //response->setVersion(expectedVersion); - assertEquals(expectedDOM, response); - } - - void testSingleElementOptionalAttributesMarshall() { - ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse(); - TS_ASSERT(response!=NULL); - - response->setID(expectedID); - response->setInResponseTo(expectedInResponseTo); - response->setIssueInstant(expectedIssueInstant); - //response->setVersion(expectedVersion); - response->setConsent(expectedConsent); - response->setDestination(expectedDestination); - response->setInResponseTo(expectedInResponseTo); - assertEquals(expectedOptionalAttributesDOM, response); - } - - void testChildElementsMarshall() { - ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse(); - TS_ASSERT(response!=NULL); - - response->setID(expectedID); - response->setIssueInstant(expectedIssueInstant); - // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file - Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX); - response->addNamespace(*ns); - response->setIssuer(IssuerBuilder::buildIssuer()); - response->setStatus(StatusBuilder::buildStatus()); - - AuthnRequest* authnRequest = AuthnRequestBuilder::buildAuthnRequest(); - authnRequest->setIssueInstant(expectedIssueInstant); - authnRequest->setID(authnRequestID); - response->setPayload(authnRequest); - - assertEquals(expectedChildElementsDOM, response); - delete ns; - } - -}; +/* + * Copyright 2001-2006 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 "internal.h" +#include +#include + +using namespace opensaml::saml2p; +using namespace opensaml::saml2; + +class ArtifactResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase { + XMLCh* expectedID; + XMLCh* expectedInResponseTo; + XMLCh* expectedVersion; + XMLCh* expectedConsent; + XMLCh* expectedDestination; + DateTime* expectedIssueInstant; + + // The payload will be an AuthnRequest in this test. + // AuthnRequest marshaller autogenerates ID, Version and IssueInstant if they are NULL, + // so have to agree on something to put in the control XML + XMLCh* authnRequestID; + +public: + void setUp() { + expectedID = XMLString::transcode("def456"); + expectedInResponseTo = XMLString::transcode("abc123"); + expectedVersion = XMLString::transcode("2.0"); + expectedConsent = XMLString::transcode("urn:string:consent"); + expectedDestination = XMLString::transcode("http://sp.example.org/endpoint"); + expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z")); + expectedIssueInstant->parseDateTime(); + + authnRequestID = XMLString::transcode("test1"); + + singleElementFile = data_path + "saml2/core/impl/ArtifactResponse.xml"; + singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ArtifactResponseOptionalAttributes.xml"; + childElementsFile = data_path + "saml2/core/impl/ArtifactResponseChildElements.xml"; + SAMLObjectBaseTestCase::setUp(); + } + + void tearDown() { + XMLString::release(&expectedID); + XMLString::release(&expectedInResponseTo); + XMLString::release(&expectedVersion); + XMLString::release(&expectedConsent); + XMLString::release(&expectedDestination); + XMLString::release(&authnRequestID); + delete expectedIssueInstant; + SAMLObjectBaseTestCase::tearDown(); + } + + void testSingleElementUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementFile)); + ArtifactResponse* response = dynamic_cast(xo.get()); + TS_ASSERT(response!=NULL); + + assertEquals("ID attribute", expectedID, response->getID()); + assertEquals("Version attribute", expectedVersion, response->getVersion()); + TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch()); + + TS_ASSERT(response->getIssuer()==NULL); + TS_ASSERT(response->getSignature()==NULL); + TS_ASSERT(response->getExtensions()==NULL); + TS_ASSERT(response->getStatus()==NULL); + TS_ASSERT(response->getPayload()==NULL); + } + + void testSingleElementOptionalAttributesUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementOptionalAttributesFile)); + ArtifactResponse* response = dynamic_cast(xo.get()); + TS_ASSERT(response!=NULL); + + assertEquals("Consent attribute", expectedConsent, response->getConsent()); + assertEquals("Destination attribute", expectedDestination, response->getDestination()); + assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo()); + + TS_ASSERT(response->getIssuer()==NULL); + TS_ASSERT(response->getSignature()==NULL); + TS_ASSERT(response->getExtensions()==NULL); + TS_ASSERT(response->getStatus()==NULL); + TS_ASSERT(response->getPayload()==NULL); + } + + void testChildElementsUnmarshall() { + auto_ptr xo(unmarshallElement(childElementsFile)); + ArtifactResponse* response= dynamic_cast(xo.get()); + TS_ASSERT(response!=NULL); + + TS_ASSERT(response->getIssuer()!=NULL); + TS_ASSERT(response->getSignature()==NULL); + TS_ASSERT(response->getExtensions()==NULL); + TS_ASSERT(response->getStatus()!=NULL); + TS_ASSERT(response->getPayload()!=NULL); + } + + void testSingleElementMarshall() { + ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse(); + TS_ASSERT(response!=NULL); + + response->setID(expectedID); + response->setIssueInstant(expectedIssueInstant); + //response->setVersion(expectedVersion); + assertEquals(expectedDOM, response); + } + + void testSingleElementOptionalAttributesMarshall() { + ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse(); + TS_ASSERT(response!=NULL); + + response->setID(expectedID); + response->setInResponseTo(expectedInResponseTo); + response->setIssueInstant(expectedIssueInstant); + //response->setVersion(expectedVersion); + response->setConsent(expectedConsent); + response->setDestination(expectedDestination); + response->setInResponseTo(expectedInResponseTo); + assertEquals(expectedOptionalAttributesDOM, response); + } + + void testChildElementsMarshall() { + ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse(); + TS_ASSERT(response!=NULL); + + response->setID(expectedID); + response->setIssueInstant(expectedIssueInstant); + // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file + Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX); + response->addNamespace(*ns); + response->setIssuer(IssuerBuilder::buildIssuer()); + response->setStatus(StatusBuilder::buildStatus()); + + AuthnRequest* authnRequest = AuthnRequestBuilder::buildAuthnRequest(); + authnRequest->setIssueInstant(expectedIssueInstant); + authnRequest->setID(authnRequestID); + response->setPayload(authnRequest); + + assertEquals(expectedChildElementsDOM, response); + delete ns; + } + +};