2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 #include <saml/saml2/core/Assertions.h>
23 #include <saml/util/SAMLConstants.h>
24 #include <xmltooling/signature/KeyInfo.h>
26 using namespace opensaml::saml2;
27 using xmlsignature::KeyInfoBuilder;
29 //TODO need testing for ElementProxy and wildcard attributes/elements
31 class KeyInfoConfirmationDataType20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
32 DateTime* expectedNotBefore;
33 DateTime* expectedNotOnOrAfter;
34 XMLCh* expectedRecipient;
35 XMLCh* expectedInResponseTo;
36 XMLCh* expectedAddress;
40 expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
41 expectedNotBefore->parseDateTime();
42 expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
43 expectedNotOnOrAfter->parseDateTime();
44 expectedRecipient = (XMLString::transcode("recipient"));
45 expectedInResponseTo = (XMLString::transcode("inresponse"));
46 expectedAddress = (XMLString::transcode("address"));
48 singleElementFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataType.xml";
49 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeOptionalAttributes.xml";
50 childElementsFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeChildElements.xml";
51 SAMLObjectBaseTestCase::setUp();
55 delete expectedNotBefore;
56 delete expectedNotOnOrAfter;
57 XMLString::release(&expectedRecipient);
58 XMLString::release(&expectedInResponseTo);
59 XMLString::release(&expectedAddress);
60 SAMLObjectBaseTestCase::tearDown();
63 void testSingleElementUnmarshall() {
64 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
65 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
66 TS_ASSERT(scd!=nullptr);
68 TS_ASSERT(scd->getNotBefore()==nullptr);
69 TS_ASSERT(scd->getNotOnOrAfter()==nullptr);
70 TS_ASSERT(scd->getRecipient()==nullptr);
71 TS_ASSERT(scd->getInResponseTo()==nullptr);
72 TS_ASSERT(scd->getAddress()==nullptr);
73 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
76 void testSingleElementOptionalAttributesUnmarshall() {
77 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
78 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
79 TS_ASSERT(scd!=nullptr);
81 TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), scd->getNotBefore()->getEpoch());
82 TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), scd->getNotOnOrAfter()->getEpoch());
83 assertEquals("Recipient attribute", expectedRecipient, scd->getRecipient());
84 assertEquals("InResponseTo attribute", expectedInResponseTo, scd->getInResponseTo());
85 assertEquals("Address attribute", expectedAddress, scd->getAddress());
86 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
88 //TODO need to test with some wildcard attributes
91 void testChildElementsUnmarshall() {
92 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
93 KeyInfoConfirmationDataType* scd= dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
94 TS_ASSERT(scd!=nullptr);
96 TS_ASSERT(scd->getNotBefore()==nullptr);
97 TS_ASSERT(scd->getNotOnOrAfter()==nullptr);
98 TS_ASSERT(scd->getRecipient()==nullptr);
99 TS_ASSERT(scd->getInResponseTo()==nullptr);
100 TS_ASSERT(scd->getAddress()==nullptr);
101 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 1, scd->getKeyInfos().size());
103 //TODO need to test with some wildcard child elements
106 void testSingleElementMarshall() {
107 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
108 assertEquals(expectedDOM, scd);
111 void testSingleElementOptionalAttributesMarshall() {
112 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
113 scd->setNotBefore(expectedNotBefore);
114 scd->setNotOnOrAfter(expectedNotOnOrAfter);
115 scd->setRecipient(expectedRecipient);
116 scd->setInResponseTo(expectedInResponseTo);
117 scd->setAddress(expectedAddress);
118 //TODO need to test with some wilcard attributes
119 assertEquals(expectedOptionalAttributesDOM, scd);
122 void testChildElementsMarshall() {
123 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
124 scd->getKeyInfos().push_back(KeyInfoBuilder::buildKeyInfo());
125 //TODO need to test with some wilcard child elements
126 assertEquals(expectedChildElementsDOM, scd);