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
25 This tests building an element of type StatusResponseType with a non-SAML element name and namespace
\r
28 class StatusResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
30 XMLCh* expectedInResponseTo;
\r
31 XMLCh* expectedVersion;
\r
32 XMLCh* expectedConsent;
\r
33 XMLCh* expectedDestination;
\r
34 DateTime* expectedIssueInstant;
\r
36 //TODO possibly move these up to SAMLObjectBaseTestCase, for use in optional helper methods below
\r
39 XMLCh* elementPrefix;
\r
40 const XMLCh* typeName;
\r
41 const XMLCh* typeNS;
\r
42 const XMLCh* typePrefix;
\r
46 expectedID = XMLString::transcode("def456");
\r
47 expectedInResponseTo = XMLString::transcode("abc123");
\r
48 expectedVersion = XMLString::transcode("2.0");
\r
49 expectedConsent = XMLString::transcode("urn:string:consent");
\r
50 expectedDestination = XMLString::transcode("http://sp.example.org/endpoint");
\r
51 expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
\r
52 expectedIssueInstant->parseDateTime();
\r
54 elementName = XMLString::transcode("Foo");;
\r
55 elementNS = XMLString::transcode("http://www.example.org/test");
\r
56 elementPrefix = XMLString::transcode("test");;
\r
57 typeName = StatusResponse::TYPE_NAME;
\r
58 typeNS = SAMLConstants::SAML20P_NS;
\r
59 typePrefix = SAMLConstants::SAML20P_PREFIX;
\r
61 singleElementFile = data_path + "saml2/core/impl/StatusResponse.xml";
\r
62 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/StatusResponseOptionalAttributes.xml";
\r
63 childElementsFile = data_path + "saml2/core/impl/StatusResponseChildElements.xml";
\r
64 SAMLObjectBaseTestCase::setUp();
\r
68 XMLString::release(&expectedID);
\r
69 XMLString::release(&expectedInResponseTo);
\r
70 XMLString::release(&expectedVersion);
\r
71 XMLString::release(&expectedConsent);
\r
72 XMLString::release(&expectedDestination);
\r
73 XMLString::release(&elementName);
\r
74 XMLString::release(&elementNS);
\r
75 XMLString::release(&elementPrefix);
\r
76 delete expectedIssueInstant;
\r
77 SAMLObjectBaseTestCase::tearDown();
\r
80 //TODO possibly move this functionality up to SAMLObjectBaseTestCase, as optional helper method
\r
81 void checkNameAndType(XMLObject* xo) {
\r
82 assertEquals("Element name", elementName, xo->getElementQName().getLocalPart());
\r
83 assertEquals("Element namespace", elementNS, xo->getElementQName().getNamespaceURI());
\r
84 assertEquals("Element namespace prefix", elementPrefix, xo->getElementQName().getPrefix());
\r
86 assertEquals("Schema type name", typeName, xo->getSchemaType()->getLocalPart());
\r
87 assertEquals("Schema type namespace", typeNS, xo->getSchemaType()->getNamespaceURI());
\r
88 assertEquals("Schema type namespace prefix", typePrefix, xo->getSchemaType()->getPrefix());
\r
91 //TODO possibly move this functionality up to SAMLObjectBaseTestCase, as optional helper method
\r
92 XMLObject * buildObject() {
\r
93 const XMLObjectBuilder* builder = XMLObjectBuilder::getBuilder(QName(typeNS,typeName));
\r
94 QName type(typeNS,typeName,typePrefix);
\r
95 return builder->buildObject(elementNS, elementName, elementPrefix, &type);
\r
98 void testSingleElementUnmarshall() {
\r
99 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
\r
100 StatusResponse* response = dynamic_cast<StatusResponse*>(xo.get());
\r
101 TS_ASSERT(response!=NULL);
\r
103 checkNameAndType(response);
\r
105 assertEquals("ID attribute", expectedID, response->getID());
\r
106 assertEquals("Version attribute", expectedVersion, response->getVersion());
\r
107 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch());
\r
109 TS_ASSERT(response->getIssuer()==NULL);
\r
110 TS_ASSERT(response->getSignature()==NULL);
\r
111 TS_ASSERT(response->getExtensions()==NULL);
\r
112 TS_ASSERT(response->getStatus()==NULL);
\r
115 void testSingleElementOptionalAttributesUnmarshall() {
\r
116 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
\r
117 StatusResponse* response = dynamic_cast<StatusResponse*>(xo.get());
\r
118 TS_ASSERT(response!=NULL);
\r
120 checkNameAndType(response);
\r
122 assertEquals("Consent attribute", expectedConsent, response->getConsent());
\r
123 assertEquals("Destination attribute", expectedDestination, response->getDestination());
\r
124 assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
\r
126 TS_ASSERT(response->getIssuer()==NULL);
\r
127 TS_ASSERT(response->getSignature()==NULL);
\r
128 TS_ASSERT(response->getExtensions()==NULL);
\r
129 TS_ASSERT(response->getStatus()==NULL);
\r
132 void testChildElementsUnmarshall() {
\r
133 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
\r
134 StatusResponse* response= dynamic_cast<StatusResponse*>(xo.get());
\r
135 TS_ASSERT(response!=NULL);
\r
137 checkNameAndType(response);
\r
139 TS_ASSERT(response->getIssuer()!=NULL);
\r
140 TS_ASSERT(response->getSignature()==NULL);
\r
141 TS_ASSERT(response->getExtensions()==NULL);
\r
142 TS_ASSERT(response->getStatus()!=NULL);
\r
145 void testSingleElementMarshall() {
\r
146 StatusResponse* response = dynamic_cast<StatusResponse*>(buildObject());
\r
147 TS_ASSERT(response!=NULL);
\r
148 checkNameAndType(response);
\r
150 response->setID(expectedID);
\r
151 response->setIssueInstant(expectedIssueInstant);
\r
152 //response->setVersion(expectedVersion);
\r
153 assertEquals(expectedDOM, response);
\r
156 void testSingleElementOptionalAttributesMarshall() {
\r
157 StatusResponse* response = dynamic_cast<StatusResponse*>(buildObject());
\r
158 TS_ASSERT(response!=NULL);
\r
159 checkNameAndType(response);
\r
161 response->setID(expectedID);
\r
162 response->setInResponseTo(expectedInResponseTo);
\r
163 response->setIssueInstant(expectedIssueInstant);
\r
164 //response->setVersion(expectedVersion);
\r
165 response->setConsent(expectedConsent);
\r
166 response->setDestination(expectedDestination);
\r
167 response->setInResponseTo(expectedInResponseTo);
\r
168 assertEquals(expectedOptionalAttributesDOM, response);
\r
171 void testChildElementsMarshall() {
\r
172 StatusResponse* response = dynamic_cast<StatusResponse*>(buildObject());
\r
173 TS_ASSERT(response!=NULL);
\r
174 checkNameAndType(response);
\r
176 response->setID(expectedID);
\r
177 response->setIssueInstant(expectedIssueInstant);
\r
178 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
\r
179 Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);
\r
180 response->addNamespace(*ns);
\r
181 response->setIssuer(IssuerBuilder::buildIssuer());
\r
182 response->setStatus(StatusBuilder::buildStatus());
\r
183 assertEquals(expectedChildElementsDOM, response);
\r