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/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2;
22 using namespace xmlsignature;
24 //TODO need testing for ElementProxy and wildcard attributes/elements
26 class KeyInfoConfirmationDataType20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27 DateTime* expectedNotBefore;
28 DateTime* expectedNotOnOrAfter;
29 XMLCh* expectedRecipient;
30 XMLCh* expectedInResponseTo;
31 XMLCh* expectedAddress;
35 expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
36 expectedNotBefore->parseDateTime();
37 expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
38 expectedNotOnOrAfter->parseDateTime();
39 expectedRecipient = (XMLString::transcode("recipient"));
40 expectedInResponseTo = (XMLString::transcode("inresponse"));
41 expectedAddress = (XMLString::transcode("address"));
43 singleElementFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataType.xml";
44 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeOptionalAttributes.xml";
45 childElementsFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeChildElements.xml";
46 SAMLObjectBaseTestCase::setUp();
50 delete expectedNotBefore;
51 delete expectedNotOnOrAfter;
52 XMLString::release(&expectedRecipient);
53 XMLString::release(&expectedInResponseTo);
54 XMLString::release(&expectedAddress);
55 SAMLObjectBaseTestCase::tearDown();
58 void testSingleElementUnmarshall() {
59 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
60 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
63 TS_ASSERT(scd->getNotBefore()==NULL);
64 TS_ASSERT(scd->getNotOnOrAfter()==NULL);
65 TS_ASSERT(scd->getRecipient()==NULL);
66 TS_ASSERT(scd->getInResponseTo()==NULL);
67 TS_ASSERT(scd->getAddress()==NULL);
68 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
71 void testSingleElementOptionalAttributesUnmarshall() {
72 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
73 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
76 TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), scd->getNotBefore()->getEpoch());
77 TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), scd->getNotOnOrAfter()->getEpoch());
78 assertEquals("Recipient attribute", expectedRecipient, scd->getRecipient());
79 assertEquals("InResponseTo attribute", expectedInResponseTo, scd->getInResponseTo());
80 assertEquals("Address attribute", expectedAddress, scd->getAddress());
81 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
83 //TODO need to test with some wildcard attributes
86 void testChildElementsUnmarshall() {
87 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
88 KeyInfoConfirmationDataType* scd= dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
91 TS_ASSERT(scd->getNotBefore()==NULL);
92 TS_ASSERT(scd->getNotOnOrAfter()==NULL);
93 TS_ASSERT(scd->getRecipient()==NULL);
94 TS_ASSERT(scd->getInResponseTo()==NULL);
95 TS_ASSERT(scd->getAddress()==NULL);
96 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 1, scd->getKeyInfos().size());
98 //TODO need to test with some wildcard child elements
101 void testSingleElementMarshall() {
102 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
103 assertEquals(expectedDOM, scd);
106 void testSingleElementOptionalAttributesMarshall() {
107 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
108 scd->setNotBefore(expectedNotBefore);
109 scd->setNotOnOrAfter(expectedNotOnOrAfter);
110 scd->setRecipient(expectedRecipient);
111 scd->setInResponseTo(expectedInResponseTo);
112 scd->setAddress(expectedAddress);
113 //TODO need to test with some wilcard attributes
114 assertEquals(expectedOptionalAttributesDOM, scd);
117 void testChildElementsMarshall() {
118 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
119 scd->getKeyInfos().push_back(KeyInfoBuilder::buildKeyInfo());
120 //TODO need to test with some wilcard child elements
121 assertEquals(expectedChildElementsDOM, scd);