2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 #include <saml/saml2/core/Assertions.h>
23 #include <saml/util/SAMLConstants.h>
25 using namespace opensaml::saml2;
27 class AuthnStatement20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
28 DateTime* expectedAuthnInstant;
29 XMLCh* expectedSessionIndex;
30 DateTime* expectedSessionNotOnOrAfter;
34 expectedAuthnInstant = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
35 expectedAuthnInstant->parseDateTime();
36 expectedSessionIndex = (XMLString::transcode("abc123"));
37 expectedSessionNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
38 expectedSessionNotOnOrAfter->parseDateTime();
40 singleElementFile = data_path + "saml2/core/impl/AuthnStatement.xml";
41 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AuthnStatementOptionalAttributes.xml";
42 childElementsFile = data_path + "saml2/core/impl/AuthnStatementChildElements.xml";
43 SAMLObjectBaseTestCase::setUp();
47 delete expectedAuthnInstant;
48 XMLString::release(&expectedSessionIndex);
49 delete expectedSessionNotOnOrAfter;
50 SAMLObjectBaseTestCase::tearDown();
53 void testSingleElementUnmarshall() {
54 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
55 AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
56 TS_ASSERT(statement!=nullptr);
58 TSM_ASSERT_EQUALS("AuthnInstant attribute", expectedAuthnInstant->getEpoch(), statement->getAuthnInstant()->getEpoch());
59 TS_ASSERT(statement->getSessionIndex()==nullptr);
60 TS_ASSERT(statement->getSessionNotOnOrAfter()==nullptr);
62 TS_ASSERT(statement->getSubjectLocality()==nullptr);
63 TS_ASSERT(statement->getAuthnContext()==nullptr);
66 void testSingleElementOptionalAttributesUnmarshall() {
67 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
68 AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
69 TS_ASSERT(statement!=nullptr);
71 TSM_ASSERT_EQUALS("AuthnInstant attribute", expectedAuthnInstant->getEpoch(), statement->getAuthnInstant()->getEpoch());
72 assertEquals("SessionIndex attribute", expectedSessionIndex, statement->getSessionIndex());
73 TSM_ASSERT_EQUALS("SessionNotOnOrAfter attribute", expectedSessionNotOnOrAfter->getEpoch(), statement->getSessionNotOnOrAfter()->getEpoch());
75 TS_ASSERT(statement->getSubjectLocality()==nullptr);
76 TS_ASSERT(statement->getAuthnContext()==nullptr);
80 void testChildElementsUnmarshall() {
81 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
82 AuthnStatement* statement= dynamic_cast<AuthnStatement*>(xo.get());
83 TS_ASSERT(statement!=nullptr);
85 TS_ASSERT(statement->getAuthnInstant()==nullptr);
86 TS_ASSERT(statement->getSessionIndex()==nullptr);
87 TS_ASSERT(statement->getSessionNotOnOrAfter()==nullptr);
89 TS_ASSERT(statement->getSubjectLocality()!=nullptr);
90 TS_ASSERT(statement->getAuthnContext()!=nullptr);
94 void testSingleElementMarshall() {
95 AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
96 statement->setAuthnInstant(expectedAuthnInstant);
97 assertEquals(expectedDOM, statement);
100 void testSingleElementOptionalAttributesMarshall() {
101 AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
102 statement->setAuthnInstant(expectedAuthnInstant);
103 statement->setSessionIndex(expectedSessionIndex);
104 statement->setSessionNotOnOrAfter(expectedSessionNotOnOrAfter);
105 assertEquals(expectedOptionalAttributesDOM, statement);
108 void testChildElementsMarshall() {
109 AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
110 statement->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
111 statement->setAuthnContext(AuthnContextBuilder::buildAuthnContext());
112 assertEquals(expectedChildElementsDOM, statement);