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 XMLCh* expectedIssueInstant;
\r
30 expectedID=XMLString::transcode("ident");
\r
31 expectedMinorVersion=1;
\r
32 expectedIssueInstant=XMLString::transcode("1970-01-02T01:01:02.100Z");
\r
33 expectedIssuer=XMLString::transcode("issuer");
\r
34 singleElementFile = data_path + "saml1/core/impl/singleAssertion.xml";
\r
35 singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionAttributes.xml";
\r
36 childElementsFile = data_path + "saml1/core/impl/AssertionWithChildren.xml";
\r
37 SAMLObjectBaseTestCase::setUp();
\r
41 XMLString::release(&expectedID);
\r
42 XMLString::release(&expectedIssueInstant);
\r
43 XMLString::release(&expectedIssuer);
\r
44 SAMLObjectBaseTestCase::tearDown();
\r
47 void testSingleElementUnmarshall() {
\r
48 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
\r
49 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
\r
50 TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);
\r
51 TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));
\r
52 TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));
\r
54 TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);
\r
55 TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);
\r
57 TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
\r
58 TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
\r
59 TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
\r
60 TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
\r
61 TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
\r
64 void testSingleElementOptionalAttributesUnmarshall() {
\r
65 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
\r
66 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
\r
68 TSM_ASSERT_SAME_DATA("Issuer attribute", expectedIssuer, assertion.getIssuer(), XMLString::stringLen(expectedIssuer));
\r
69 TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));
\r
70 TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));
\r
71 TSM_ASSERT_EQUALS("Issuer expectedMinorVersion", expectedMinorVersion, assertion.getMinorVersion());
\r
73 TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);
\r
74 TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);
\r
76 TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
\r
77 TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
\r
78 TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
\r
79 TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
\r
80 TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
\r
83 void testChildElementsUnmarshall() {
\r
84 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
\r
85 Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
\r
87 TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);
\r
88 TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));
\r
89 TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));
\r
91 TSM_ASSERT("Conditions element null", assertion.getConditions()!=NULL);
\r
92 TSM_ASSERT("Advice element null", assertion.getAdvice()!=NULL);
\r
94 TSM_ASSERT_EQUALS("AuthenticationStatements element count", 2, assertion.getAuthenticationStatements().size());
\r
95 TSM_ASSERT_EQUALS("AttributeStatements element count", 3, assertion.getAttributeStatements().size());
\r
96 TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 3, assertion.getAuthorizationDecisionStatements().size());
\r
99 void testSingleElementMarshall() {
\r
100 Assertion* assertion=AssertionBuilder::buildAssertion();
\r
101 assertion->setAssertionID(expectedID);
\r
102 assertion->setIssueInstant(expectedIssueInstant);
\r
103 assertEquals(expectedDOM, assertion);
\r
106 void testSingleElementOptionalAttributesMarshall() {
\r
107 Assertion* assertion=AssertionBuilder::buildAssertion();
\r
108 assertion->setIssueInstant(expectedIssueInstant);
\r
109 assertion->setAssertionID(expectedID);
\r
110 assertion->setIssuer(expectedIssuer);
\r
111 assertEquals(expectedOptionalAttributesDOM, assertion);
\r
114 void testChildElementsMarshall() {
\r
115 Assertion* assertion=AssertionBuilder::buildAssertion();
\r
116 assertion->setIssueInstant(expectedIssueInstant);
\r
117 assertion->setAssertionID(expectedID);
\r
118 assertion->setConditions(ConditionsBuilder::buildConditions());
\r
119 assertion->setAdvice(AdviceBuilder::buildAdvice());
\r
120 assertion->getAuthenticationStatements().push_back(
\r
121 AuthenticationStatementBuilder::buildAuthenticationStatement()
\r
123 assertion->getAuthorizationDecisionStatements().push_back(
\r
124 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
\r
126 assertion->getAttributeStatements().push_back(
\r
127 AttributeStatementBuilder::buildAttributeStatement()
\r
129 assertion->getAuthenticationStatements().push_back(
\r
130 AuthenticationStatementBuilder::buildAuthenticationStatement()
\r
132 assertion->getAuthorizationDecisionStatements().push_back(
\r
133 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
\r
135 assertion->getAttributeStatements().push_back(
\r
136 AttributeStatementBuilder::buildAttributeStatement()
\r
138 assertion->getAuthorizationDecisionStatements().push_back(
\r
139 AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
\r
141 assertion->getAttributeStatements().push_back(
\r
142 AttributeStatementBuilder::buildAttributeStatement()
\r
144 assertEquals(expectedChildElementsDOM, assertion);
\r