2 * Copyright 2001-2010 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>
20 #include <xmltooling/signature/KeyInfo.h>
22 using namespace opensaml::saml2;
23 using xmlsignature::KeyInfoBuilder;
25 //TODO need testing for ElementProxy and wildcard attributes/elements
27 class KeyInfoConfirmationDataType20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
28 DateTime* expectedNotBefore;
29 DateTime* expectedNotOnOrAfter;
30 XMLCh* expectedRecipient;
31 XMLCh* expectedInResponseTo;
32 XMLCh* expectedAddress;
36 expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
37 expectedNotBefore->parseDateTime();
38 expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
39 expectedNotOnOrAfter->parseDateTime();
40 expectedRecipient = (XMLString::transcode("recipient"));
41 expectedInResponseTo = (XMLString::transcode("inresponse"));
42 expectedAddress = (XMLString::transcode("address"));
44 singleElementFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataType.xml";
45 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeOptionalAttributes.xml";
46 childElementsFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeChildElements.xml";
47 SAMLObjectBaseTestCase::setUp();
51 delete expectedNotBefore;
52 delete expectedNotOnOrAfter;
53 XMLString::release(&expectedRecipient);
54 XMLString::release(&expectedInResponseTo);
55 XMLString::release(&expectedAddress);
56 SAMLObjectBaseTestCase::tearDown();
59 void testSingleElementUnmarshall() {
60 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
61 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
62 TS_ASSERT(scd!=nullptr);
64 TS_ASSERT(scd->getNotBefore()==nullptr);
65 TS_ASSERT(scd->getNotOnOrAfter()==nullptr);
66 TS_ASSERT(scd->getRecipient()==nullptr);
67 TS_ASSERT(scd->getInResponseTo()==nullptr);
68 TS_ASSERT(scd->getAddress()==nullptr);
69 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
72 void testSingleElementOptionalAttributesUnmarshall() {
73 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
74 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
75 TS_ASSERT(scd!=nullptr);
77 TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), scd->getNotBefore()->getEpoch());
78 TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), scd->getNotOnOrAfter()->getEpoch());
79 assertEquals("Recipient attribute", expectedRecipient, scd->getRecipient());
80 assertEquals("InResponseTo attribute", expectedInResponseTo, scd->getInResponseTo());
81 assertEquals("Address attribute", expectedAddress, scd->getAddress());
82 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
84 //TODO need to test with some wildcard attributes
87 void testChildElementsUnmarshall() {
88 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
89 KeyInfoConfirmationDataType* scd= dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
90 TS_ASSERT(scd!=nullptr);
92 TS_ASSERT(scd->getNotBefore()==nullptr);
93 TS_ASSERT(scd->getNotOnOrAfter()==nullptr);
94 TS_ASSERT(scd->getRecipient()==nullptr);
95 TS_ASSERT(scd->getInResponseTo()==nullptr);
96 TS_ASSERT(scd->getAddress()==nullptr);
97 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 1, scd->getKeyInfos().size());
99 //TODO need to test with some wildcard child elements
102 void testSingleElementMarshall() {
103 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
104 assertEquals(expectedDOM, scd);
107 void testSingleElementOptionalAttributesMarshall() {
108 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
109 scd->setNotBefore(expectedNotBefore);
110 scd->setNotOnOrAfter(expectedNotOnOrAfter);
111 scd->setRecipient(expectedRecipient);
112 scd->setInResponseTo(expectedInResponseTo);
113 scd->setAddress(expectedAddress);
114 //TODO need to test with some wilcard attributes
115 assertEquals(expectedOptionalAttributesDOM, scd);
118 void testChildElementsMarshall() {
119 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
120 scd->getKeyInfos().push_back(KeyInfoBuilder::buildKeyInfo());
121 //TODO need to test with some wilcard child elements
122 assertEquals(expectedChildElementsDOM, scd);