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 NameIDMappingResponse20Test : 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/NameIDMappingResponse.xml";
43 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/NameIDMappingResponseOptionalAttributes.xml";
44 childElementsFile = data_path + "saml2/core/impl/NameIDMappingResponseChildElements.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 NameIDMappingResponse* response = dynamic_cast<NameIDMappingResponse*>(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);
71 TS_ASSERT(response->getNameID()==NULL);
72 TS_ASSERT(response->getEncryptedID()==NULL);
75 void testSingleElementOptionalAttributesUnmarshall() {
76 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
77 NameIDMappingResponse* response = dynamic_cast<NameIDMappingResponse*>(xo.get());
78 TS_ASSERT(response!=NULL);
80 assertEquals("Consent attribute", expectedConsent, response->getConsent());
81 assertEquals("Destination attribute", expectedDestination, response->getDestination());
82 assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
84 TS_ASSERT(response->getIssuer()==NULL);
85 TS_ASSERT(response->getSignature()==NULL);
86 TS_ASSERT(response->getExtensions()==NULL);
87 TS_ASSERT(response->getStatus()==NULL);
88 TS_ASSERT(response->getNameID()==NULL);
89 TS_ASSERT(response->getEncryptedID()==NULL);
92 void testChildElementsUnmarshall() {
93 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
94 NameIDMappingResponse* response= dynamic_cast<NameIDMappingResponse*>(xo.get());
95 TS_ASSERT(response!=NULL);
97 TS_ASSERT(response->getIssuer()!=NULL);
98 TS_ASSERT(response->getSignature()==NULL);
99 TS_ASSERT(response->getExtensions()==NULL);
100 TS_ASSERT(response->getStatus()!=NULL);
101 TS_ASSERT(response->getNameID()!=NULL);
102 TS_ASSERT(response->getEncryptedID()==NULL);
105 void testSingleElementMarshall() {
106 NameIDMappingResponse* response = NameIDMappingResponseBuilder::buildNameIDMappingResponse();
107 TS_ASSERT(response!=NULL);
109 response->setID(expectedID);
110 response->setIssueInstant(expectedIssueInstant);
111 //response->setVersion(expectedVersion);
112 assertEquals(expectedDOM, response);
115 void testSingleElementOptionalAttributesMarshall() {
116 NameIDMappingResponse* response = NameIDMappingResponseBuilder::buildNameIDMappingResponse();
117 TS_ASSERT(response!=NULL);
119 response->setID(expectedID);
120 response->setInResponseTo(expectedInResponseTo);
121 response->setIssueInstant(expectedIssueInstant);
122 //response->setVersion(expectedVersion);
123 response->setConsent(expectedConsent);
124 response->setDestination(expectedDestination);
125 response->setInResponseTo(expectedInResponseTo);
126 assertEquals(expectedOptionalAttributesDOM, response);
129 void testChildElementsMarshall() {
130 NameIDMappingResponse* response = NameIDMappingResponseBuilder::buildNameIDMappingResponse();
131 TS_ASSERT(response!=NULL);
133 response->setID(expectedID);
134 response->setIssueInstant(expectedIssueInstant);
135 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
136 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
137 response->addNamespace(*ns);
138 response->setIssuer(IssuerBuilder::buildIssuer());
139 response->setStatus(StatusBuilder::buildStatus());
140 response->setNameID(NameIDBuilder::buildNameID());
142 assertEquals(expectedChildElementsDOM, response);