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 ManageNameIDResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
30 XMLCh* expectedInResponseTo;
31 XMLCh* expectedVersion;
32 XMLCh* expectedConsent;
33 XMLCh* expectedDestination;
34 DateTime* expectedIssueInstant;
38 expectedID = XMLString::transcode("def456");
39 expectedInResponseTo = XMLString::transcode("abc123");
40 expectedVersion = XMLString::transcode("2.0");
41 expectedConsent = XMLString::transcode("urn:string:consent");
42 expectedDestination = XMLString::transcode("http://sp.example.org/endpoint");
43 expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
44 expectedIssueInstant->parseDateTime();
46 singleElementFile = data_path + "saml2/core/impl/ManageNameIDResponse.xml";
47 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ManageNameIDResponseOptionalAttributes.xml";
48 childElementsFile = data_path + "saml2/core/impl/ManageNameIDResponseChildElements.xml";
49 SAMLObjectBaseTestCase::setUp();
53 XMLString::release(&expectedID);
54 XMLString::release(&expectedInResponseTo);
55 XMLString::release(&expectedVersion);
56 XMLString::release(&expectedConsent);
57 XMLString::release(&expectedDestination);
58 delete expectedIssueInstant;
59 SAMLObjectBaseTestCase::tearDown();
62 void testSingleElementUnmarshall() {
63 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
64 ManageNameIDResponse* response = dynamic_cast<ManageNameIDResponse*>(xo.get());
65 TS_ASSERT(response!=nullptr);
67 assertEquals("ID attribute", expectedID, response->getID());
68 assertEquals("Version attribute", expectedVersion, response->getVersion());
69 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch());
71 TS_ASSERT(response->getIssuer()==nullptr);
72 TS_ASSERT(response->getSignature()==nullptr);
73 TS_ASSERT(response->getExtensions()==nullptr);
74 TS_ASSERT(response->getStatus()==nullptr);
77 void testSingleElementOptionalAttributesUnmarshall() {
78 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
79 ManageNameIDResponse* response = dynamic_cast<ManageNameIDResponse*>(xo.get());
80 TS_ASSERT(response!=nullptr);
82 assertEquals("Consent attribute", expectedConsent, response->getConsent());
83 assertEquals("Destination attribute", expectedDestination, response->getDestination());
84 assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
86 TS_ASSERT(response->getIssuer()==nullptr);
87 TS_ASSERT(response->getSignature()==nullptr);
88 TS_ASSERT(response->getExtensions()==nullptr);
89 TS_ASSERT(response->getStatus()==nullptr);
92 void testChildElementsUnmarshall() {
93 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
94 ManageNameIDResponse* response= dynamic_cast<ManageNameIDResponse*>(xo.get());
95 TS_ASSERT(response!=nullptr);
97 TS_ASSERT(response->getIssuer()!=nullptr);
98 TS_ASSERT(response->getSignature()==nullptr);
99 TS_ASSERT(response->getExtensions()==nullptr);
100 TS_ASSERT(response->getStatus()!=nullptr);
103 void testSingleElementMarshall() {
104 ManageNameIDResponse* response = ManageNameIDResponseBuilder::buildManageNameIDResponse();
105 TS_ASSERT(response!=nullptr);
107 response->setID(expectedID);
108 response->setIssueInstant(expectedIssueInstant);
109 //response->setVersion(expectedVersion);
110 assertEquals(expectedDOM, response);
113 void testSingleElementOptionalAttributesMarshall() {
114 ManageNameIDResponse* response = ManageNameIDResponseBuilder::buildManageNameIDResponse();
115 TS_ASSERT(response!=nullptr);
117 response->setID(expectedID);
118 response->setInResponseTo(expectedInResponseTo);
119 response->setIssueInstant(expectedIssueInstant);
120 //response->setVersion(expectedVersion);
121 response->setConsent(expectedConsent);
122 response->setDestination(expectedDestination);
123 response->setInResponseTo(expectedInResponseTo);
124 assertEquals(expectedOptionalAttributesDOM, response);
127 void testChildElementsMarshall() {
128 ManageNameIDResponse* response = ManageNameIDResponseBuilder::buildManageNameIDResponse();
129 TS_ASSERT(response!=nullptr);
131 response->setID(expectedID);
132 response->setIssueInstant(expectedIssueInstant);
133 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
134 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
135 response->addNamespace(*ns);
136 response->setIssuer(IssuerBuilder::buildIssuer());
137 response->setStatus(StatusBuilder::buildStatus());
139 assertEquals(expectedChildElementsDOM, response);