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 ManageNameIDRequest20Test : 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/ManageNameIDRequest.xml";
41 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ManageNameIDRequestOptionalAttributes.xml";
42 childElementsFile = data_path + "saml2/core/impl/ManageNameIDRequestChildElements.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 ManageNameIDRequest* request = dynamic_cast<ManageNameIDRequest*>(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->getNameID()==NULL);
67 TS_ASSERT(request->getEncryptedID()==NULL);
68 TS_ASSERT(request->getNewID()==NULL);
69 TS_ASSERT(request->getNewEncryptedID()==NULL);
70 TS_ASSERT(request->getTerminate()==NULL);
73 void testSingleElementOptionalAttributesUnmarshall() {
74 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
75 ManageNameIDRequest* request = dynamic_cast<ManageNameIDRequest*>(xo.get());
76 TS_ASSERT(request!=NULL);
78 assertEquals("Consent attribute", expectedConsent, request->getConsent());
79 assertEquals("Destination attribute", expectedDestination, request->getDestination());
81 TS_ASSERT(request->getIssuer()==NULL);
82 TS_ASSERT(request->getSignature()==NULL);
83 TS_ASSERT(request->getExtensions()==NULL);
84 TS_ASSERT(request->getNameID()==NULL);
85 TS_ASSERT(request->getEncryptedID()==NULL);
86 TS_ASSERT(request->getNewID()==NULL);
87 TS_ASSERT(request->getNewEncryptedID()==NULL);
88 TS_ASSERT(request->getTerminate()==NULL);
91 void testChildElementsUnmarshall() {
92 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
93 ManageNameIDRequest* request= dynamic_cast<ManageNameIDRequest*>(xo.get());
94 TS_ASSERT(request!=NULL);
95 TS_ASSERT(request->getIssuer()!=NULL);
96 TS_ASSERT(request->getSignature()==NULL);
97 TS_ASSERT(request->getExtensions()==NULL);
98 TS_ASSERT(request->getNameID()!=NULL);
99 TS_ASSERT(request->getEncryptedID()==NULL);
100 TS_ASSERT(request->getNewID()!=NULL);
101 TS_ASSERT(request->getNewEncryptedID()==NULL);
102 TS_ASSERT(request->getTerminate()==NULL);
105 void testSingleElementMarshall() {
106 ManageNameIDRequest* request=ManageNameIDRequestBuilder::buildManageNameIDRequest();
107 request->setID(expectedID);
108 request->setIssueInstant(expectedIssueInstant);
109 //request->setVersion(expectedVersion);
110 assertEquals(expectedDOM, request);
113 void testSingleElementOptionalAttributesMarshall() {
114 ManageNameIDRequest* request=ManageNameIDRequestBuilder::buildManageNameIDRequest();
115 request->setID(expectedID);
116 request->setIssueInstant(expectedIssueInstant);
117 //request->setVersion(expectedVersion);
118 request->setConsent(expectedConsent);
119 request->setDestination(expectedDestination);
120 assertEquals(expectedOptionalAttributesDOM, request);
123 void testChildElementsMarshall() {
124 ManageNameIDRequest* request=ManageNameIDRequestBuilder::buildManageNameIDRequest();
125 request->setID(expectedID);
126 request->setIssueInstant(expectedIssueInstant);
127 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
128 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
129 request->addNamespace(*ns);
130 request->setIssuer(IssuerBuilder::buildIssuer());
131 request->setNameID(NameIDBuilder::buildNameID());
132 request->setNewID(NewIDBuilder::buildNewID());
133 assertEquals(expectedChildElementsDOM, request);