2 * Copyright 2001-2006 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 ManageNameIDResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
26 XMLCh* expectedInResponseTo;
27 XMLCh* expectedVersion;
28 XMLCh* expectedConsent;
29 XMLCh* expectedDestination;
30 DateTime* expectedIssueInstant;
34 expectedID = XMLString::transcode("def456");
35 expectedInResponseTo = XMLString::transcode("abc123");
36 expectedVersion = XMLString::transcode("2.0");
37 expectedConsent = XMLString::transcode("urn:string:consent");
38 expectedDestination = XMLString::transcode("http://sp.example.org/endpoint");
39 expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
40 expectedIssueInstant->parseDateTime();
42 singleElementFile = data_path + "saml2/core/impl/ManageNameIDResponse.xml";
43 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ManageNameIDResponseOptionalAttributes.xml";
44 childElementsFile = data_path + "saml2/core/impl/ManageNameIDResponseChildElements.xml";
45 SAMLObjectBaseTestCase::setUp();
49 XMLString::release(&expectedID);
50 XMLString::release(&expectedInResponseTo);
51 XMLString::release(&expectedVersion);
52 XMLString::release(&expectedConsent);
53 XMLString::release(&expectedDestination);
54 delete expectedIssueInstant;
55 SAMLObjectBaseTestCase::tearDown();
58 void testSingleElementUnmarshall() {
59 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
60 ManageNameIDResponse* response = dynamic_cast<ManageNameIDResponse*>(xo.get());
61 TS_ASSERT(response!=NULL);
63 assertEquals("ID attribute", expectedID, response->getID());
64 assertEquals("Version attribute", expectedVersion, response->getVersion());
65 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch());
67 TS_ASSERT(response->getIssuer()==NULL);
68 TS_ASSERT(response->getSignature()==NULL);
69 TS_ASSERT(response->getExtensions()==NULL);
70 TS_ASSERT(response->getStatus()==NULL);
73 void testSingleElementOptionalAttributesUnmarshall() {
74 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
75 ManageNameIDResponse* response = dynamic_cast<ManageNameIDResponse*>(xo.get());
76 TS_ASSERT(response!=NULL);
78 assertEquals("Consent attribute", expectedConsent, response->getConsent());
79 assertEquals("Destination attribute", expectedDestination, response->getDestination());
80 assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
82 TS_ASSERT(response->getIssuer()==NULL);
83 TS_ASSERT(response->getSignature()==NULL);
84 TS_ASSERT(response->getExtensions()==NULL);
85 TS_ASSERT(response->getStatus()==NULL);
88 void testChildElementsUnmarshall() {
89 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
90 ManageNameIDResponse* response= dynamic_cast<ManageNameIDResponse*>(xo.get());
91 TS_ASSERT(response!=NULL);
93 TS_ASSERT(response->getIssuer()!=NULL);
94 TS_ASSERT(response->getSignature()==NULL);
95 TS_ASSERT(response->getExtensions()==NULL);
96 TS_ASSERT(response->getStatus()!=NULL);
99 void testSingleElementMarshall() {
100 ManageNameIDResponse* response = ManageNameIDResponseBuilder::buildManageNameIDResponse();
101 TS_ASSERT(response!=NULL);
103 response->setID(expectedID);
104 response->setIssueInstant(expectedIssueInstant);
105 //response->setVersion(expectedVersion);
106 assertEquals(expectedDOM, response);
109 void testSingleElementOptionalAttributesMarshall() {
110 ManageNameIDResponse* response = ManageNameIDResponseBuilder::buildManageNameIDResponse();
111 TS_ASSERT(response!=NULL);
113 response->setID(expectedID);
114 response->setInResponseTo(expectedInResponseTo);
115 response->setIssueInstant(expectedIssueInstant);
116 //response->setVersion(expectedVersion);
117 response->setConsent(expectedConsent);
118 response->setDestination(expectedDestination);
119 response->setInResponseTo(expectedInResponseTo);
120 assertEquals(expectedOptionalAttributesDOM, response);
123 void testChildElementsMarshall() {
124 ManageNameIDResponse* response = ManageNameIDResponseBuilder::buildManageNameIDResponse();
125 TS_ASSERT(response!=NULL);
127 response->setID(expectedID);
128 response->setIssueInstant(expectedIssueInstant);
129 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
130 Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);
131 response->addNamespace(*ns);
132 response->setIssuer(IssuerBuilder::buildIssuer());
133 response->setStatus(StatusBuilder::buildStatus());
135 assertEquals(expectedChildElementsDOM, response);