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