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