Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AssertionTest.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/saml1/core/Assertions.h>
23
24 using namespace opensaml::saml1;
25
26 class AssertionTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27     int expectedMinorVersion;
28     XMLCh* expectedIssuer;
29     DateTime* expectedIssueInstant;
30     XMLCh* expectedID;
31
32 public:
33     void setUp() {
34         expectedID=XMLString::transcode("ident");
35         expectedMinorVersion=1;
36         expectedIssueInstant=new DateTime(XMLString::transcode("1970-01-02T01:01:02.100Z"));
37         expectedIssueInstant->parseDateTime();
38         expectedIssuer=XMLString::transcode("issuer");
39         singleElementFile = data_path + "saml1/core/impl/singleAssertion.xml";
40         singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionAttributes.xml";
41         childElementsFile  = data_path + "saml1/core/impl/AssertionWithChildren.xml";    
42         SAMLObjectBaseTestCase::setUp();
43     }
44     
45     void tearDown() {
46         XMLString::release(&expectedID);
47         XMLString::release(&expectedIssuer);
48         delete expectedIssueInstant;
49         SAMLObjectBaseTestCase::tearDown();
50     }
51
52     void testSingleElementUnmarshall() {
53         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
54         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
55         TSM_ASSERT("Issuer attribute", assertion.getIssuer()==nullptr);
56         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
57         assertEquals("ID attribute", expectedID, assertion.getAssertionID());
58
59         TSM_ASSERT("Conditions element", assertion.getConditions()==nullptr);
60         TSM_ASSERT("Advice element", assertion.getAdvice()==nullptr);
61
62         TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
63         TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
64         TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
65         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
66         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
67     }
68
69     void testSingleElementOptionalAttributesUnmarshall() {
70         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
71         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
72
73         assertEquals("Issuer attribute", expectedIssuer, assertion.getIssuer());
74         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
75         assertEquals("ID attribute", expectedID, assertion.getAssertionID());
76         TSM_ASSERT_EQUALS("Issuer expectedMinorVersion", expectedMinorVersion, assertion.getMinorVersion().second);
77
78         TSM_ASSERT("Conditions element", assertion.getConditions()==nullptr);
79         TSM_ASSERT("Advice element", assertion.getAdvice()==nullptr);
80
81         TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
82         TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
83         TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
84         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
85         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
86     }
87
88     void testChildElementsUnmarshall() {
89         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
90         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
91
92         TSM_ASSERT("Issuer attribute", assertion.getIssuer()==nullptr);
93         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
94         assertEquals("ID attribute", expectedID, assertion.getAssertionID());
95
96         TSM_ASSERT("Conditions element null", assertion.getConditions()!=nullptr);
97         TSM_ASSERT("Advice element null", assertion.getAdvice()!=nullptr);
98
99         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 2, assertion.getAuthenticationStatements().size());
100         TSM_ASSERT_EQUALS("AttributeStatements element count", 3, assertion.getAttributeStatements().size());
101         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 3, assertion.getAuthorizationDecisionStatements().size());
102     }
103
104     void testSingleElementMarshall() {
105         Assertion* assertion=AssertionBuilder::buildAssertion();
106         assertion->setAssertionID(expectedID);
107         assertion->setIssueInstant(expectedIssueInstant);
108         assertEquals(expectedDOM, assertion);
109     }
110
111     void testSingleElementOptionalAttributesMarshall() {
112         Assertion* assertion=AssertionBuilder::buildAssertion();
113         assertion->setIssueInstant(expectedIssueInstant);
114         assertion->setAssertionID(expectedID);
115         assertion->setIssuer(expectedIssuer);
116         assertEquals(expectedOptionalAttributesDOM, assertion);
117     }
118
119     void testChildElementsMarshall() {
120         Assertion* assertion=AssertionBuilder::buildAssertion();
121         assertion->setIssueInstant(expectedIssueInstant);
122         assertion->setAssertionID(expectedID);
123         assertion->setConditions(ConditionsBuilder::buildConditions());
124         assertion->setAdvice(AdviceBuilder::buildAdvice());
125         assertion->getAuthenticationStatements().push_back(
126             AuthenticationStatementBuilder::buildAuthenticationStatement()
127             );
128         assertion->getAuthorizationDecisionStatements().push_back(
129             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
130             );
131         assertion->getAttributeStatements().push_back(
132             AttributeStatementBuilder::buildAttributeStatement()
133             );
134         assertion->getAuthenticationStatements().push_back(
135             AuthenticationStatementBuilder::buildAuthenticationStatement()
136             );
137         assertion->getAuthorizationDecisionStatements().push_back(
138             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
139             );
140         assertion->getAttributeStatements().push_back(
141             AttributeStatementBuilder::buildAttributeStatement()
142             );
143         assertion->getAuthorizationDecisionStatements().push_back(
144             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
145             );
146         assertion->getAttributeStatements().push_back(
147             AttributeStatementBuilder::buildAttributeStatement()
148             );
149         assertEquals(expectedChildElementsDOM, assertion);
150     }
151
152 };