2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <saml/saml2/core/Protocols.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
24 class ArtifactResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
26 XMLCh* expectedInResponseTo;
27 XMLCh* expectedVersion;
28 XMLCh* expectedConsent;
29 XMLCh* expectedDestination;
30 DateTime* expectedIssueInstant;
32 // The payload will be an AuthnRequest in this test.
33 // AuthnRequest marshaller autogenerates ID, Version and IssueInstant if they are NULL,
34 // so have to agree on something to put in the control XML
35 XMLCh* authnRequestID;
39 expectedID = XMLString::transcode("def456");
40 expectedInResponseTo = XMLString::transcode("abc123");
41 expectedVersion = XMLString::transcode("2.0");
42 expectedConsent = XMLString::transcode("urn:string:consent");
43 expectedDestination = XMLString::transcode("http://sp.example.org/endpoint");
44 expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
45 expectedIssueInstant->parseDateTime();
47 authnRequestID = XMLString::transcode("test1");
49 singleElementFile = data_path + "saml2/core/impl/ArtifactResponse.xml";
50 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ArtifactResponseOptionalAttributes.xml";
51 childElementsFile = data_path + "saml2/core/impl/ArtifactResponseChildElements.xml";
52 SAMLObjectBaseTestCase::setUp();
56 XMLString::release(&expectedID);
57 XMLString::release(&expectedInResponseTo);
58 XMLString::release(&expectedVersion);
59 XMLString::release(&expectedConsent);
60 XMLString::release(&expectedDestination);
61 XMLString::release(&authnRequestID);
62 delete expectedIssueInstant;
63 SAMLObjectBaseTestCase::tearDown();
66 void testSingleElementUnmarshall() {
67 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
68 ArtifactResponse* response = dynamic_cast<ArtifactResponse*>(xo.get());
69 TS_ASSERT(response!=NULL);
71 assertEquals("ID attribute", expectedID, response->getID());
72 assertEquals("Version attribute", expectedVersion, response->getVersion());
73 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch());
75 TS_ASSERT(response->getIssuer()==NULL);
76 TS_ASSERT(response->getSignature()==NULL);
77 TS_ASSERT(response->getExtensions()==NULL);
78 TS_ASSERT(response->getStatus()==NULL);
79 TS_ASSERT(response->getPayload()==NULL);
82 void testSingleElementOptionalAttributesUnmarshall() {
83 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
84 ArtifactResponse* response = dynamic_cast<ArtifactResponse*>(xo.get());
85 TS_ASSERT(response!=NULL);
87 assertEquals("Consent attribute", expectedConsent, response->getConsent());
88 assertEquals("Destination attribute", expectedDestination, response->getDestination());
89 assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
91 TS_ASSERT(response->getIssuer()==NULL);
92 TS_ASSERT(response->getSignature()==NULL);
93 TS_ASSERT(response->getExtensions()==NULL);
94 TS_ASSERT(response->getStatus()==NULL);
95 TS_ASSERT(response->getPayload()==NULL);
98 void testChildElementsUnmarshall() {
99 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
100 ArtifactResponse* response= dynamic_cast<ArtifactResponse*>(xo.get());
101 TS_ASSERT(response!=NULL);
103 TS_ASSERT(response->getIssuer()!=NULL);
104 TS_ASSERT(response->getSignature()==NULL);
105 TS_ASSERT(response->getExtensions()==NULL);
106 TS_ASSERT(response->getStatus()!=NULL);
107 TS_ASSERT(response->getPayload()!=NULL);
110 void testSingleElementMarshall() {
111 ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();
112 TS_ASSERT(response!=NULL);
114 response->setID(expectedID);
115 response->setIssueInstant(expectedIssueInstant);
116 //response->setVersion(expectedVersion);
117 assertEquals(expectedDOM, response);
120 void testSingleElementOptionalAttributesMarshall() {
121 ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();
122 TS_ASSERT(response!=NULL);
124 response->setID(expectedID);
125 response->setInResponseTo(expectedInResponseTo);
126 response->setIssueInstant(expectedIssueInstant);
127 //response->setVersion(expectedVersion);
128 response->setConsent(expectedConsent);
129 response->setDestination(expectedDestination);
130 response->setInResponseTo(expectedInResponseTo);
131 assertEquals(expectedOptionalAttributesDOM, response);
134 void testChildElementsMarshall() {
135 ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();
136 TS_ASSERT(response!=NULL);
138 response->setID(expectedID);
139 response->setIssueInstant(expectedIssueInstant);
140 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
141 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
142 response->addNamespace(*ns);
143 response->setIssuer(IssuerBuilder::buildIssuer());
144 response->setStatus(StatusBuilder::buildStatus());
146 AuthnRequest* authnRequest = AuthnRequestBuilder::buildAuthnRequest();
147 authnRequest->setIssueInstant(expectedIssueInstant);
148 authnRequest->setID(authnRequestID);
149 response->setPayload(authnRequest);
151 assertEquals(expectedChildElementsDOM, response);