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