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