Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / Assertion20Test.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
25 using namespace opensaml::saml2;
26
27 class Assertion20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
28     const XMLCh* expectedVersion;
29     XMLCh* expectedID;
30     DateTime* expectedIssueInstant;
31
32 public:
33     void setUp() {
34         expectedVersion = samlconstants::SAML20_VERSION;
35         expectedID = XMLString::transcode("abc123");
36         expectedIssueInstant = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
37         expectedIssueInstant->parseDateTime();
38
39
40         singleElementFile = data_path + "saml2/core/impl/Assertion.xml";
41         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AssertionOptionalAttributes.xml";
42         childElementsFile  = data_path + "saml2/core/impl/AssertionChildElements.xml";
43         SAMLObjectBaseTestCase::setUp();
44     }
45
46     void tearDown() {
47         delete expectedIssueInstant;
48         XMLString::release(&expectedID);
49         SAMLObjectBaseTestCase::tearDown();
50     }
51
52     void testSingleElementUnmarshall() {
53         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
54         Assertion* assertion = dynamic_cast<Assertion*>(xo.get());
55         TS_ASSERT(assertion!=nullptr);
56
57         assertEquals("ID attribute", expectedID, assertion->getID());
58         assertEquals("Version attribute", expectedVersion, assertion->getVersion());
59         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion->getIssueInstant()->getEpoch());
60
61         TS_ASSERT(assertion->getIssuer()==nullptr);
62         TS_ASSERT(assertion->getSignature()==nullptr);
63         TS_ASSERT(assertion->getSubject()==nullptr);
64         TS_ASSERT(assertion->getConditions()==nullptr);
65         TS_ASSERT(assertion->getAdvice()==nullptr);
66
67         TSM_ASSERT_EQUALS("# of Statement child elements", 0, assertion->getStatements().size());
68         TSM_ASSERT_EQUALS("# of AuthnStatement child elements", 0, assertion->getAuthnStatements().size());
69         TSM_ASSERT_EQUALS("# of AttributeStatement child elements", 0, assertion->getAttributeStatements().size());
70         TSM_ASSERT_EQUALS("# of AuthzDecisionStatement child elements", 0, assertion->getAuthzDecisionStatements().size());
71     }
72
73     void testChildElementsUnmarshall() {
74         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
75         Assertion* assertion= dynamic_cast<Assertion*>(xo.get());
76         TS_ASSERT(assertion!=nullptr);
77
78         assertEquals("ID attribute", expectedID, assertion->getID());
79         assertEquals("Version attribute", expectedVersion, assertion->getVersion());
80         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion->getIssueInstant()->getEpoch());
81
82         TS_ASSERT(assertion->getIssuer()!=nullptr);
83         TS_ASSERT(assertion->getSignature()==nullptr);
84         TS_ASSERT(assertion->getSubject()!=nullptr);
85         TS_ASSERT(assertion->getConditions()!=nullptr);
86         TS_ASSERT(assertion->getAdvice()!=nullptr);
87
88         TSM_ASSERT_EQUALS("# of Statement child elements", 1, assertion->getStatements().size());
89         TSM_ASSERT_EQUALS("# of AuthnStatement child elements", 1, assertion->getAuthnStatements().size());
90         TSM_ASSERT_EQUALS("# of AttributeStatement child elements", 3, assertion->getAttributeStatements().size());
91         TSM_ASSERT_EQUALS("# of AuthzDecisionStatement child elements", 2, assertion->getAuthzDecisionStatements().size());
92     }
93
94     void testSingleElementMarshall() {
95         Assertion* assertion=AssertionBuilder::buildAssertion();
96         assertion->setID(expectedID);
97         assertion->setIssueInstant(expectedIssueInstant);
98         assertEquals(expectedDOM, assertion);
99     }
100
101     void testChildElementsMarshall() {
102         xmltooling::QName qext("http://www.opensaml.org/", "Foo", "ext");
103
104         Assertion* assertion=AssertionBuilder::buildAssertion();
105         assertion->setID(expectedID);
106         assertion->setIssueInstant(expectedIssueInstant);
107         assertion->setIssuer(IssuerBuilder::buildIssuer());
108         assertion->setSubject(SubjectBuilder::buildSubject());
109         assertion->setConditions(ConditionsBuilder::buildConditions());
110         assertion->setAdvice(AdviceBuilder::buildAdvice());
111
112         //Test storing children as their direct type
113         assertion->getAuthnStatements().push_back(AuthnStatementBuilder::buildAuthnStatement());
114         assertion->getAttributeStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
115         assertion->getAttributeStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
116         assertion->getAuthzDecisionStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
117         assertion->getAuthzDecisionStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
118         assertion->getAttributeStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
119         assertion->getStatements().push_back(StatementBuilder::buildStatement(qext));
120         assertEquals(expectedChildElementsDOM, assertion);
121
122         // Note: assertEquals() above has already 'delete'-ed the XMLObject* it was passed
123         assertion=nullptr;
124         assertion=AssertionBuilder::buildAssertion();
125         assertion->setID(expectedID);
126         assertion->setIssueInstant(expectedIssueInstant);
127         assertion->setIssuer(IssuerBuilder::buildIssuer());
128         assertion->setSubject(SubjectBuilder::buildSubject());
129         assertion->setConditions(ConditionsBuilder::buildConditions());
130         assertion->setAdvice(AdviceBuilder::buildAdvice());
131
132         //Test storing children as a Statement (each is a derived type of StatementAbstractType)
133         assertion->getStatements().push_back(AuthnStatementBuilder::buildAuthnStatement());
134         assertion->getStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
135         assertion->getStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
136         assertion->getStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
137         assertion->getStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
138         assertion->getStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
139         assertion->getStatements().push_back(StatementBuilder::buildStatement(qext));
140         assertEquals(expectedChildElementsDOM, assertion);
141     }
142
143 };