2 * Copyright 2001-2006 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/saml2/core/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2;
23 class AuthnStatement20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
24 DateTime* expectedAuthnInstant;
25 XMLCh* expectedSessionIndex;
26 DateTime* expectedSessionNotOnOrAfter;
30 expectedAuthnInstant = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
31 expectedAuthnInstant->parseDateTime();
32 expectedSessionIndex = (XMLString::transcode("abc123"));
33 expectedSessionNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
34 expectedSessionNotOnOrAfter->parseDateTime();
36 singleElementFile = data_path + "saml2/core/impl/AuthnStatement.xml";
37 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AuthnStatementOptionalAttributes.xml";
38 childElementsFile = data_path + "saml2/core/impl/AuthnStatementChildElements.xml";
39 SAMLObjectBaseTestCase::setUp();
43 delete expectedAuthnInstant;
44 XMLString::release(&expectedSessionIndex);
45 delete expectedSessionNotOnOrAfter;
46 SAMLObjectBaseTestCase::tearDown();
49 void testSingleElementUnmarshall() {
50 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
51 AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
52 TS_ASSERT(statement!=NULL);
54 TSM_ASSERT_EQUALS("AuthnInstant attribute", expectedAuthnInstant->getEpoch(), statement->getAuthnInstant()->getEpoch());
55 TS_ASSERT(statement->getSessionIndex()==NULL);
56 TS_ASSERT(statement->getSessionNotOnOrAfter()==NULL);
58 TS_ASSERT(statement->getSubjectLocality()==NULL);
59 TS_ASSERT(statement->getAuthnContext()==NULL);
62 void testSingleElementOptionalAttributesUnmarshall() {
63 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
64 AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
65 TS_ASSERT(statement!=NULL);
67 TSM_ASSERT_EQUALS("AuthnInstant attribute", expectedAuthnInstant->getEpoch(), statement->getAuthnInstant()->getEpoch());
68 assertEquals("SessionIndex attribute", expectedSessionIndex, statement->getSessionIndex());
69 TSM_ASSERT_EQUALS("SessionNotOnOrAfter attribute", expectedSessionNotOnOrAfter->getEpoch(), statement->getSessionNotOnOrAfter()->getEpoch());
71 TS_ASSERT(statement->getSubjectLocality()==NULL);
72 TS_ASSERT(statement->getAuthnContext()==NULL);
76 void testChildElementsUnmarshall() {
77 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
78 AuthnStatement* statement= dynamic_cast<AuthnStatement*>(xo.get());
79 TS_ASSERT(statement!=NULL);
81 TS_ASSERT(statement->getAuthnInstant()==NULL);
82 TS_ASSERT(statement->getSessionIndex()==NULL);
83 TS_ASSERT(statement->getSessionNotOnOrAfter()==NULL);
85 TS_ASSERT(statement->getSubjectLocality()!=NULL);
86 TS_ASSERT(statement->getAuthnContext()!=NULL);
90 void testSingleElementMarshall() {
91 AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
92 statement->setAuthnInstant(expectedAuthnInstant);
93 assertEquals(expectedDOM, statement);
96 void testSingleElementOptionalAttributesMarshall() {
97 AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
98 statement->setAuthnInstant(expectedAuthnInstant);
99 statement->setSessionIndex(expectedSessionIndex);
100 statement->setSessionNotOnOrAfter(expectedSessionNotOnOrAfter);
101 assertEquals(expectedOptionalAttributesDOM, statement);
104 void testChildElementsMarshall() {
105 AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
106 statement->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
107 statement->setAuthnContext(AuthnContextBuilder::buildAuthnContext());
108 assertEquals(expectedChildElementsDOM, statement);