Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / KeyInfoConfirmationDataType20Test.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include "internal.h"
22 #include <saml/saml2/core/Assertions.h>
23 #include <saml/util/SAMLConstants.h>
24 #include <xmltooling/signature/KeyInfo.h>
25
26 using namespace opensaml::saml2;
27 using xmlsignature::KeyInfoBuilder;
28
29 //TODO need testing for ElementProxy and wildcard attributes/elements
30
31 class KeyInfoConfirmationDataType20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
32     DateTime* expectedNotBefore;
33     DateTime* expectedNotOnOrAfter;
34     XMLCh* expectedRecipient;
35     XMLCh* expectedInResponseTo;
36     XMLCh* expectedAddress;
37
38 public:
39     void setUp() {
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"));
47
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();
52     }
53     
54     void tearDown() {
55         delete expectedNotBefore;
56         delete expectedNotOnOrAfter;
57         XMLString::release(&expectedRecipient);
58         XMLString::release(&expectedInResponseTo);
59         XMLString::release(&expectedAddress);
60         SAMLObjectBaseTestCase::tearDown();
61     }
62
63     void testSingleElementUnmarshall() {
64         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
65         KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
66         TS_ASSERT(scd!=nullptr);
67
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());
74     }
75
76     void testSingleElementOptionalAttributesUnmarshall() {
77         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
78         KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
79         TS_ASSERT(scd!=nullptr);
80
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());
87
88         //TODO need to test with some wildcard attributes
89     }
90
91     void testChildElementsUnmarshall() {
92         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
93         KeyInfoConfirmationDataType* scd= dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
94         TS_ASSERT(scd!=nullptr);
95
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());
102
103         //TODO need to test with some wildcard child elements
104     }
105
106     void testSingleElementMarshall() {
107         KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
108         assertEquals(expectedDOM, scd);
109     }
110
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);
120     }
121
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);
127     }
128
129 };