2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <saml/saml1/core/Assertions.h>
20 using namespace opensaml::saml1;
22 class AssertionTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
23 int expectedMinorVersion;
24 XMLCh* expectedIssuer;
25 DateTime* expectedIssueInstant;
30 expectedID=XMLString::transcode("ident");
31 expectedMinorVersion=1;
32 expectedIssueInstant=new DateTime(XMLString::transcode("1970-01-02T01:01:02.100Z"));
33 expectedIssueInstant->parseDateTime();
34 expectedIssuer=XMLString::transcode("issuer");
35 singleElementFile = data_path + "saml1/core/impl/singleAssertion.xml";
36 singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionAttributes.xml";
37 childElementsFile = data_path + "saml1/core/impl/AssertionWithChildren.xml";
38 SAMLObjectBaseTestCase::setUp();
42 XMLString::release(&expectedID);
43 XMLString::release(&expectedIssuer);
44 delete expectedIssueInstant;
45 SAMLObjectBaseTestCase::tearDown();
48 void testSingleElementUnmarshall() {
49 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
50 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
51 TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);
52 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
53 assertEquals("ID attribute", expectedID, assertion.getAssertionID());
55 TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);
56 TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);
58 TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
59 TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
60 TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
61 TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
62 TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
65 void testSingleElementOptionalAttributesUnmarshall() {
66 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
67 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
69 assertEquals("Issuer attribute", expectedIssuer, assertion.getIssuer());
70 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
71 assertEquals("ID attribute", expectedID, assertion.getAssertionID());
72 TSM_ASSERT_EQUALS("Issuer expectedMinorVersion", expectedMinorVersion, assertion.getMinorVersion().second);
74 TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);
75 TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);
77 TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
78 TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
79 TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
80 TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
81 TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
84 void testChildElementsUnmarshall() {
85 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
86 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
88 TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);
89 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
90 assertEquals("ID attribute", expectedID, assertion.getAssertionID());
92 TSM_ASSERT("Conditions element null", assertion.getConditions()!=NULL);
93 TSM_ASSERT("Advice element null", assertion.getAdvice()!=NULL);
95 TSM_ASSERT_EQUALS("AuthenticationStatements element count", 2, assertion.getAuthenticationStatements().size());
96 TSM_ASSERT_EQUALS("AttributeStatements element count", 3, assertion.getAttributeStatements().size());
97 TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 3, assertion.getAuthorizationDecisionStatements().size());
100 void testSingleElementMarshall() {
101 Assertion* assertion=AssertionBuilder::buildAssertion();
102 assertion->setAssertionID(expectedID);
103 assertion->setIssueInstant(expectedIssueInstant);
104 assertEquals(expectedDOM, assertion);
107 void testSingleElementOptionalAttributesMarshall() {
108 Assertion* assertion=AssertionBuilder::buildAssertion();
109 assertion->setIssueInstant(expectedIssueInstant);
110 assertion->setAssertionID(expectedID);
111 assertion->setIssuer(expectedIssuer);
112 assertEquals(expectedOptionalAttributesDOM, assertion);
115 void testChildElementsMarshall() {
116 Assertion* assertion=AssertionBuilder::buildAssertion();
117 assertion->setIssueInstant(expectedIssueInstant);
118 assertion->setAssertionID(expectedID);
119 assertion->setConditions(ConditionsBuilder::buildConditions());
120 assertion->setAdvice(AdviceBuilder::buildAdvice());
121 assertion->getAuthenticationStatements().push_back(
122 AuthenticationStatementBuilder::buildAuthenticationStatement()
124 assertion->getAuthorizationDecisionStatements().push_back(
125 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
127 assertion->getAttributeStatements().push_back(
128 AttributeStatementBuilder::buildAttributeStatement()
130 assertion->getAuthenticationStatements().push_back(
131 AuthenticationStatementBuilder::buildAuthenticationStatement()
133 assertion->getAuthorizationDecisionStatements().push_back(
134 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
136 assertion->getAttributeStatements().push_back(
137 AttributeStatementBuilder::buildAttributeStatement()
139 assertion->getAuthorizationDecisionStatements().push_back(
140 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
142 assertion->getAttributeStatements().push_back(
143 AttributeStatementBuilder::buildAttributeStatement()
145 assertEquals(expectedChildElementsDOM, assertion);