Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / AuthnStatement20Test.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include "internal.h"
22 #include <saml/saml2/core/Assertions.h>
23 #include <saml/util/SAMLConstants.h>
24
25 using namespace opensaml::saml2;
26
27 class AuthnStatement20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
28     DateTime* expectedAuthnInstant;
29     XMLCh* expectedSessionIndex;
30     DateTime* expectedSessionNotOnOrAfter;
31
32 public:
33     void setUp() {
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();
39
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();
44     }
45     
46     void tearDown() {
47         delete expectedAuthnInstant;
48         XMLString::release(&expectedSessionIndex);
49         delete expectedSessionNotOnOrAfter;
50         SAMLObjectBaseTestCase::tearDown();
51     }
52
53     void testSingleElementUnmarshall() {
54         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
55         AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
56         TS_ASSERT(statement!=nullptr);
57
58         TSM_ASSERT_EQUALS("AuthnInstant attribute", expectedAuthnInstant->getEpoch(), statement->getAuthnInstant()->getEpoch());
59         TS_ASSERT(statement->getSessionIndex()==nullptr);
60         TS_ASSERT(statement->getSessionNotOnOrAfter()==nullptr);
61
62         TS_ASSERT(statement->getSubjectLocality()==nullptr);
63         TS_ASSERT(statement->getAuthnContext()==nullptr);
64     }
65
66     void testSingleElementOptionalAttributesUnmarshall() {
67         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
68         AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
69         TS_ASSERT(statement!=nullptr);
70
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());
74
75         TS_ASSERT(statement->getSubjectLocality()==nullptr);
76         TS_ASSERT(statement->getAuthnContext()==nullptr);
77
78     }
79
80     void testChildElementsUnmarshall() {
81         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
82         AuthnStatement* statement= dynamic_cast<AuthnStatement*>(xo.get());
83         TS_ASSERT(statement!=nullptr);
84
85         TS_ASSERT(statement->getAuthnInstant()==nullptr);
86         TS_ASSERT(statement->getSessionIndex()==nullptr);
87         TS_ASSERT(statement->getSessionNotOnOrAfter()==nullptr);
88
89         TS_ASSERT(statement->getSubjectLocality()!=nullptr);
90         TS_ASSERT(statement->getAuthnContext()!=nullptr);
91
92     }
93
94     void testSingleElementMarshall() {
95         AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
96         statement->setAuthnInstant(expectedAuthnInstant);
97         assertEquals(expectedDOM, statement);
98     }
99
100     void testSingleElementOptionalAttributesMarshall() {
101         AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
102         statement->setAuthnInstant(expectedAuthnInstant);
103         statement->setSessionIndex(expectedSessionIndex);
104         statement->setSessionNotOnOrAfter(expectedSessionNotOnOrAfter);
105         assertEquals(expectedOptionalAttributesDOM, statement);
106     }
107
108     void testChildElementsMarshall() {
109         AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
110         statement->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
111         statement->setAuthnContext(AuthnContextBuilder::buildAuthnContext());
112         assertEquals(expectedChildElementsDOM, statement);
113     }
114
115 };