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/saml1/core/Assertions.h>
24 using namespace opensaml::saml1;
26 class AssertionTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27 int expectedMinorVersion;
28 XMLCh* expectedIssuer;
29 DateTime* expectedIssueInstant;
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();
46 XMLString::release(&expectedID);
47 XMLString::release(&expectedIssuer);
48 delete expectedIssueInstant;
49 SAMLObjectBaseTestCase::tearDown();
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());
59 TSM_ASSERT("Conditions element", assertion.getConditions()==nullptr);
60 TSM_ASSERT("Advice element", assertion.getAdvice()==nullptr);
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());
69 void testSingleElementOptionalAttributesUnmarshall() {
70 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
71 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
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);
78 TSM_ASSERT("Conditions element", assertion.getConditions()==nullptr);
79 TSM_ASSERT("Advice element", assertion.getAdvice()==nullptr);
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());
88 void testChildElementsUnmarshall() {
89 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
90 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
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());
96 TSM_ASSERT("Conditions element null", assertion.getConditions()!=nullptr);
97 TSM_ASSERT("Advice element null", assertion.getAdvice()!=nullptr);
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());
104 void testSingleElementMarshall() {
105 Assertion* assertion=AssertionBuilder::buildAssertion();
106 assertion->setAssertionID(expectedID);
107 assertion->setIssueInstant(expectedIssueInstant);
108 assertEquals(expectedDOM, assertion);
111 void testSingleElementOptionalAttributesMarshall() {
112 Assertion* assertion=AssertionBuilder::buildAssertion();
113 assertion->setIssueInstant(expectedIssueInstant);
114 assertion->setAssertionID(expectedID);
115 assertion->setIssuer(expectedIssuer);
116 assertEquals(expectedOptionalAttributesDOM, assertion);
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()
128 assertion->getAuthorizationDecisionStatements().push_back(
129 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
131 assertion->getAttributeStatements().push_back(
132 AttributeStatementBuilder::buildAttributeStatement()
134 assertion->getAuthenticationStatements().push_back(
135 AuthenticationStatementBuilder::buildAuthenticationStatement()
137 assertion->getAuthorizationDecisionStatements().push_back(
138 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
140 assertion->getAttributeStatements().push_back(
141 AttributeStatementBuilder::buildAttributeStatement()
143 assertion->getAuthorizationDecisionStatements().push_back(
144 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
146 assertion->getAttributeStatements().push_back(
147 AttributeStatementBuilder::buildAttributeStatement()
149 assertEquals(expectedChildElementsDOM, assertion);