2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 #include <saml/saml2/core/Protocols.h>
23 #include <saml/util/SAMLConstants.h>
25 using namespace opensaml::saml2p;
26 using namespace opensaml::saml2;
28 class ArtifactResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
30 XMLCh* expectedInResponseTo;
31 XMLCh* expectedVersion;
32 XMLCh* expectedConsent;
33 XMLCh* expectedDestination;
34 DateTime* expectedIssueInstant;
36 // The payload will be an AuthnRequest in this test.
37 // AuthnRequest marshaller autogenerates ID, Version and IssueInstant if they are nullptr,
38 // so have to agree on something to put in the control XML
39 XMLCh* authnRequestID;
43 expectedID = XMLString::transcode("def456");
44 expectedInResponseTo = XMLString::transcode("abc123");
45 expectedVersion = XMLString::transcode("2.0");
46 expectedConsent = XMLString::transcode("urn:string:consent");
47 expectedDestination = XMLString::transcode("http://sp.example.org/endpoint");
48 expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
49 expectedIssueInstant->parseDateTime();
51 authnRequestID = XMLString::transcode("test1");
53 singleElementFile = data_path + "saml2/core/impl/ArtifactResponse.xml";
54 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ArtifactResponseOptionalAttributes.xml";
55 childElementsFile = data_path + "saml2/core/impl/ArtifactResponseChildElements.xml";
56 SAMLObjectBaseTestCase::setUp();
60 XMLString::release(&expectedID);
61 XMLString::release(&expectedInResponseTo);
62 XMLString::release(&expectedVersion);
63 XMLString::release(&expectedConsent);
64 XMLString::release(&expectedDestination);
65 XMLString::release(&authnRequestID);
66 delete expectedIssueInstant;
67 SAMLObjectBaseTestCase::tearDown();
70 void testSingleElementUnmarshall() {
71 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
72 ArtifactResponse* response = dynamic_cast<ArtifactResponse*>(xo.get());
73 TS_ASSERT(response!=nullptr);
75 assertEquals("ID attribute", expectedID, response->getID());
76 assertEquals("Version attribute", expectedVersion, response->getVersion());
77 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch());
79 TS_ASSERT(response->getIssuer()==nullptr);
80 TS_ASSERT(response->getSignature()==nullptr);
81 TS_ASSERT(response->getExtensions()==nullptr);
82 TS_ASSERT(response->getStatus()==nullptr);
83 TS_ASSERT(response->getPayload()==nullptr);
86 void testSingleElementOptionalAttributesUnmarshall() {
87 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
88 ArtifactResponse* response = dynamic_cast<ArtifactResponse*>(xo.get());
89 TS_ASSERT(response!=nullptr);
91 assertEquals("Consent attribute", expectedConsent, response->getConsent());
92 assertEquals("Destination attribute", expectedDestination, response->getDestination());
93 assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
95 TS_ASSERT(response->getIssuer()==nullptr);
96 TS_ASSERT(response->getSignature()==nullptr);
97 TS_ASSERT(response->getExtensions()==nullptr);
98 TS_ASSERT(response->getStatus()==nullptr);
99 TS_ASSERT(response->getPayload()==nullptr);
102 void testChildElementsUnmarshall() {
103 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
104 ArtifactResponse* response= dynamic_cast<ArtifactResponse*>(xo.get());
105 TS_ASSERT(response!=nullptr);
107 TS_ASSERT(response->getIssuer()!=nullptr);
108 TS_ASSERT(response->getSignature()==nullptr);
109 TS_ASSERT(response->getExtensions()==nullptr);
110 TS_ASSERT(response->getStatus()!=nullptr);
111 TS_ASSERT(response->getPayload()!=nullptr);
114 void testSingleElementMarshall() {
115 ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();
116 TS_ASSERT(response!=nullptr);
118 response->setID(expectedID);
119 response->setIssueInstant(expectedIssueInstant);
120 //response->setVersion(expectedVersion);
121 assertEquals(expectedDOM, response);
124 void testSingleElementOptionalAttributesMarshall() {
125 ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();
126 TS_ASSERT(response!=nullptr);
128 response->setID(expectedID);
129 response->setInResponseTo(expectedInResponseTo);
130 response->setIssueInstant(expectedIssueInstant);
131 //response->setVersion(expectedVersion);
132 response->setConsent(expectedConsent);
133 response->setDestination(expectedDestination);
134 response->setInResponseTo(expectedInResponseTo);
135 assertEquals(expectedOptionalAttributesDOM, response);
138 void testChildElementsMarshall() {
139 ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();
140 TS_ASSERT(response!=nullptr);
142 response->setID(expectedID);
143 response->setIssueInstant(expectedIssueInstant);
144 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
145 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
146 response->addNamespace(*ns);
147 response->setIssuer(IssuerBuilder::buildIssuer());
148 response->setStatus(StatusBuilder::buildStatus());
150 AuthnRequest* authnRequest = AuthnRequestBuilder::buildAuthnRequest();
151 authnRequest->setIssueInstant(expectedIssueInstant);
152 authnRequest->setID(authnRequestID);
153 response->setPayload(authnRequest);
155 assertEquals(expectedChildElementsDOM, response);