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/saml2/core/Assertions.h>
\r
19 #include <saml/util/SAMLConstants.h>
\r
21 using namespace opensaml::saml2;
\r
23 class Assertion20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
24 const XMLCh* expectedVersion;
\r
26 DateTime* expectedIssueInstant;
\r
30 expectedVersion = SAMLConstants::SAML20_VERSION;
\r
31 expectedID = XMLString::transcode("abc123");
\r
32 expectedIssueInstant = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
\r
33 expectedIssueInstant->parseDateTime();
\r
36 singleElementFile = data_path + "saml2/core/impl/Assertion.xml";
\r
37 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AssertionOptionalAttributes.xml";
\r
38 childElementsFile = data_path + "saml2/core/impl/AssertionChildElements.xml";
\r
39 SAMLObjectBaseTestCase::setUp();
\r
43 delete expectedIssueInstant;
\r
44 XMLString::release(&expectedID);
\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 TS_ASSERT(assertion!=NULL);
\r
53 assertEquals("ID attribute", expectedID, assertion->getID());
\r
54 assertEquals("Version attribute", expectedVersion, assertion->getVersion());
\r
55 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion->getIssueInstant()->getEpoch());
\r
57 TS_ASSERT(assertion->getIssuer()==NULL);
\r
58 TS_ASSERT(assertion->getSignature()==NULL);
\r
59 TS_ASSERT(assertion->getSubject()==NULL);
\r
60 TS_ASSERT(assertion->getConditions()==NULL);
\r
61 TS_ASSERT(assertion->getAdvice()==NULL);
\r
63 TSM_ASSERT_EQUALS("# of Statement child elements", 0, assertion->getStatements().size());
\r
64 TSM_ASSERT_EQUALS("# of AuthnStatement child elements", 0, assertion->getAuthnStatements().size());
\r
65 TSM_ASSERT_EQUALS("# of AttributeStatement child elements", 0, assertion->getAttributeStatements().size());
\r
66 TSM_ASSERT_EQUALS("# of AuthzDecisionStatement child elements", 0, assertion->getAuthzDecisionStatements().size());
\r
69 void testChildElementsUnmarshall() {
\r
70 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
\r
71 Assertion* assertion= dynamic_cast<Assertion*>(xo.get());
\r
72 TS_ASSERT(assertion!=NULL);
\r
74 assertEquals("ID attribute", expectedID, assertion->getID());
\r
75 assertEquals("Version attribute", expectedVersion, assertion->getVersion());
\r
76 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion->getIssueInstant()->getEpoch());
\r
78 TS_ASSERT(assertion->getIssuer()!=NULL);
\r
79 TS_ASSERT(assertion->getSignature()==NULL);
\r
80 TS_ASSERT(assertion->getSubject()!=NULL);
\r
81 TS_ASSERT(assertion->getConditions()!=NULL);
\r
82 TS_ASSERT(assertion->getAdvice()!=NULL);
\r
84 TSM_ASSERT_EQUALS("# of Statement child elements", 0, assertion->getStatements().size());
\r
85 TSM_ASSERT_EQUALS("# of AuthnStatement child elements", 1, assertion->getAuthnStatements().size());
\r
86 TSM_ASSERT_EQUALS("# of AttributeStatement child elements", 3, assertion->getAttributeStatements().size());
\r
87 TSM_ASSERT_EQUALS("# of AuthzDecisionStatement child elements", 2, assertion->getAuthzDecisionStatements().size());
\r
90 void testSingleElementMarshall() {
\r
91 Assertion* assertion=AssertionBuilder::buildAssertion();
\r
92 assertion->setID(expectedID);
\r
93 assertion->setIssueInstant(expectedIssueInstant);
\r
94 assertEquals(expectedDOM, assertion);
\r
97 void testChildElementsMarshall() {
\r
98 Assertion* assertion=AssertionBuilder::buildAssertion();
\r
99 assertion->setID(expectedID);
\r
100 assertion->setIssueInstant(expectedIssueInstant);
\r
101 assertion->setIssuer(IssuerBuilder::buildIssuer());
\r
102 assertion->setSubject(SubjectBuilder::buildSubject());
\r
103 assertion->setConditions(ConditionsBuilder::buildConditions());
\r
104 assertion->setAdvice(AdviceBuilder::buildAdvice());
\r
106 //Test storing children as their direct type
\r
107 assertion->getAuthnStatements().push_back(AuthnStatementBuilder::buildAuthnStatement());
\r
108 assertion->getAttributeStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
\r
109 assertion->getAttributeStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
\r
110 assertion->getAuthzDecisionStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
\r
111 assertion->getAuthzDecisionStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
\r
112 assertion->getAttributeStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
\r
113 assertEquals(expectedChildElementsDOM, assertion);
\r
115 // Note: assertEquals() above has already 'delete'-ed the XMLObject* it was passed
\r
117 assertion=AssertionBuilder::buildAssertion();
\r
118 assertion->setID(expectedID);
\r
119 assertion->setIssueInstant(expectedIssueInstant);
\r
120 assertion->setIssuer(IssuerBuilder::buildIssuer());
\r
121 assertion->setSubject(SubjectBuilder::buildSubject());
\r
122 assertion->setConditions(ConditionsBuilder::buildConditions());
\r
123 assertion->setAdvice(AdviceBuilder::buildAdvice());
\r
125 //Test storing children as a Statement (each is a derived type of StatementAbstractType)
\r
126 assertion->getStatements().push_back(AuthnStatementBuilder::buildAuthnStatement());
\r
127 assertion->getStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
\r
128 assertion->getStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
\r
129 assertion->getStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
\r
130 assertion->getStatements().push_back(AuthzDecisionStatementBuilder::buildAuthzDecisionStatement());
\r
131 assertion->getStatements().push_back(AttributeStatementBuilder::buildAttributeStatement());
\r
132 assertEquals(expectedChildElementsDOM, assertion);
\r