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 NameIDMappingRequest20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
26 XMLCh* expectedVersion;
27 DateTime* expectedIssueInstant;
28 XMLCh* expectedConsent;
29 XMLCh* expectedDestination;
33 expectedID = XMLString::transcode("abc123");;
34 expectedVersion = XMLString::transcode("2.0");
35 expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
36 expectedIssueInstant->parseDateTime();
37 expectedConsent = XMLString::transcode("urn:string:consent");
38 expectedDestination = XMLString::transcode("http://idp.example.org/endpoint");
40 singleElementFile = data_path + "saml2/core/impl/NameIDMappingRequest.xml";
41 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/NameIDMappingRequestOptionalAttributes.xml";
42 childElementsFile = data_path + "saml2/core/impl/NameIDMappingRequestChildElements.xml";
43 SAMLObjectBaseTestCase::setUp();
47 XMLString::release(&expectedID);
48 XMLString::release(&expectedVersion);
49 XMLString::release(&expectedConsent);
50 XMLString::release(&expectedDestination);
51 delete expectedIssueInstant;
52 SAMLObjectBaseTestCase::tearDown();
55 void testSingleElementUnmarshall() {
56 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
57 NameIDMappingRequest* request = dynamic_cast<NameIDMappingRequest*>(xo.get());
58 TS_ASSERT(request!=NULL);
59 assertEquals("ID attribute", expectedID, request->getID());
60 assertEquals("Version attribute", expectedVersion, request->getVersion());
61 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), request->getIssueInstant()->getEpoch());
63 TS_ASSERT(request->getIssuer()==NULL);
64 TS_ASSERT(request->getSignature()==NULL);
65 TS_ASSERT(request->getExtensions()==NULL);
66 TS_ASSERT(request->getBaseID()==NULL);
67 TS_ASSERT(request->getNameID()==NULL);
68 TS_ASSERT(request->getEncryptedID()==NULL);
69 TS_ASSERT(request->getNameIDPolicy()==NULL);
72 void testSingleElementOptionalAttributesUnmarshall() {
73 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
74 NameIDMappingRequest* request = dynamic_cast<NameIDMappingRequest*>(xo.get());
75 TS_ASSERT(request!=NULL);
77 assertEquals("Consent attribute", expectedConsent, request->getConsent());
78 assertEquals("Destination attribute", expectedDestination, request->getDestination());
80 TS_ASSERT(request->getIssuer()==NULL);
81 TS_ASSERT(request->getSignature()==NULL);
82 TS_ASSERT(request->getExtensions()==NULL);
83 TS_ASSERT(request->getBaseID()==NULL);
84 TS_ASSERT(request->getNameID()==NULL);
85 TS_ASSERT(request->getEncryptedID()==NULL);
86 TS_ASSERT(request->getNameIDPolicy()==NULL);
89 void testChildElementsUnmarshall() {
90 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
91 NameIDMappingRequest* request= dynamic_cast<NameIDMappingRequest*>(xo.get());
92 TS_ASSERT(request!=NULL);
93 TS_ASSERT(request->getIssuer()!=NULL);
94 TS_ASSERT(request->getSignature()==NULL);
95 TS_ASSERT(request->getExtensions()==NULL);
96 TS_ASSERT(request->getBaseID()==NULL);
97 TS_ASSERT(request->getNameID()!=NULL);
98 TS_ASSERT(request->getEncryptedID()==NULL);
99 TS_ASSERT(request->getNameIDPolicy()!=NULL);
102 void testSingleElementMarshall() {
103 NameIDMappingRequest* request=NameIDMappingRequestBuilder::buildNameIDMappingRequest();
104 request->setID(expectedID);
105 request->setIssueInstant(expectedIssueInstant);
106 //request->setVersion(expectedVersion);
107 assertEquals(expectedDOM, request);
110 void testSingleElementOptionalAttributesMarshall() {
111 NameIDMappingRequest* request=NameIDMappingRequestBuilder::buildNameIDMappingRequest();
112 request->setID(expectedID);
113 request->setIssueInstant(expectedIssueInstant);
114 //request->setVersion(expectedVersion);
115 request->setConsent(expectedConsent);
116 request->setDestination(expectedDestination);
117 assertEquals(expectedOptionalAttributesDOM, request);
120 void testChildElementsMarshall() {
121 NameIDMappingRequest* request=NameIDMappingRequestBuilder::buildNameIDMappingRequest();
122 request->setID(expectedID);
123 request->setIssueInstant(expectedIssueInstant);
124 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
125 Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);
126 request->addNamespace(*ns);
127 request->setIssuer(IssuerBuilder::buildIssuer());
128 request->setNameID(NameIDBuilder::buildNameID());
129 request->setNameIDPolicy(NameIDPolicyBuilder::buildNameIDPolicy());
130 assertEquals(expectedChildElementsDOM, request);