Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / LogoutResponse20Test.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/Protocols.h>
23 #include <saml/util/SAMLConstants.h>
24
25 using namespace opensaml::saml2p;
26 using namespace opensaml::saml2;
27
28 class LogoutResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
29     XMLCh* expectedID; 
30     XMLCh* expectedInResponseTo; 
31     XMLCh* expectedVersion; 
32     XMLCh* expectedConsent; 
33     XMLCh* expectedDestination; 
34     DateTime* expectedIssueInstant; 
35
36 public:
37     void setUp() {
38         expectedID = XMLString::transcode("def456"); 
39         expectedInResponseTo = XMLString::transcode("abc123"); 
40         expectedVersion = XMLString::transcode("2.0"); 
41         expectedConsent = XMLString::transcode("urn:string:consent"); 
42         expectedDestination = XMLString::transcode("http://sp.example.org/endpoint"); 
43         expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
44         expectedIssueInstant->parseDateTime();
45
46         singleElementFile = data_path + "saml2/core/impl/LogoutResponse.xml";
47         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/LogoutResponseOptionalAttributes.xml";
48         childElementsFile  = data_path + "saml2/core/impl/LogoutResponseChildElements.xml";    
49         SAMLObjectBaseTestCase::setUp();
50     }
51     
52     void tearDown() {
53         XMLString::release(&expectedID);
54         XMLString::release(&expectedInResponseTo);
55         XMLString::release(&expectedVersion);
56         XMLString::release(&expectedConsent);
57         XMLString::release(&expectedDestination);
58         delete expectedIssueInstant;
59         SAMLObjectBaseTestCase::tearDown();
60     }
61
62     void testSingleElementUnmarshall() {
63         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
64         LogoutResponse* response = dynamic_cast<LogoutResponse*>(xo.get());
65         TS_ASSERT(response!=nullptr);
66
67         assertEquals("ID attribute", expectedID, response->getID());
68         assertEquals("Version attribute", expectedVersion, response->getVersion());
69         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch());
70
71         TS_ASSERT(response->getIssuer()==nullptr);
72         TS_ASSERT(response->getSignature()==nullptr);
73         TS_ASSERT(response->getExtensions()==nullptr);
74         TS_ASSERT(response->getStatus()==nullptr);
75     }
76
77     void testSingleElementOptionalAttributesUnmarshall() {
78         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
79         LogoutResponse* response = dynamic_cast<LogoutResponse*>(xo.get());
80         TS_ASSERT(response!=nullptr);
81
82         assertEquals("Consent attribute", expectedConsent, response->getConsent());
83         assertEquals("Destination attribute", expectedDestination, response->getDestination());
84         assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
85
86         TS_ASSERT(response->getIssuer()==nullptr);
87         TS_ASSERT(response->getSignature()==nullptr);
88         TS_ASSERT(response->getExtensions()==nullptr);
89         TS_ASSERT(response->getStatus()==nullptr);
90     }
91
92     void testChildElementsUnmarshall() {
93         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
94         LogoutResponse* response= dynamic_cast<LogoutResponse*>(xo.get());
95         TS_ASSERT(response!=nullptr);
96
97         TS_ASSERT(response->getIssuer()!=nullptr);
98         TS_ASSERT(response->getSignature()==nullptr);
99         TS_ASSERT(response->getExtensions()==nullptr);
100         TS_ASSERT(response->getStatus()!=nullptr);
101     }
102
103     void testSingleElementMarshall() {
104         LogoutResponse* response = LogoutResponseBuilder::buildLogoutResponse();
105         TS_ASSERT(response!=nullptr);
106
107         response->setID(expectedID);
108         response->setIssueInstant(expectedIssueInstant);
109         //response->setVersion(expectedVersion);
110         assertEquals(expectedDOM, response);
111     }
112
113     void testSingleElementOptionalAttributesMarshall() {
114         LogoutResponse* response = LogoutResponseBuilder::buildLogoutResponse();
115         TS_ASSERT(response!=nullptr);
116
117         response->setID(expectedID);
118         response->setInResponseTo(expectedInResponseTo);
119         response->setIssueInstant(expectedIssueInstant);
120         //response->setVersion(expectedVersion);
121         response->setConsent(expectedConsent);
122         response->setDestination(expectedDestination);
123         response->setInResponseTo(expectedInResponseTo);
124         assertEquals(expectedOptionalAttributesDOM, response);
125     }
126
127     void testChildElementsMarshall() {
128         LogoutResponse* response = LogoutResponseBuilder::buildLogoutResponse();
129         TS_ASSERT(response!=nullptr);
130
131         response->setID(expectedID);
132         response->setIssueInstant(expectedIssueInstant);
133         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
134         Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
135         response->addNamespace(*ns);
136         response->setIssuer(IssuerBuilder::buildIssuer());
137         response->setStatus(StatusBuilder::buildStatus());
138
139         assertEquals(expectedChildElementsDOM, response);
140         delete ns;
141     }
142
143 };