Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / NameIDMappingResponse20Test.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 NameIDMappingResponse20Test : 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/NameIDMappingResponse.xml";
47         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/NameIDMappingResponseOptionalAttributes.xml";
48         childElementsFile  = data_path + "saml2/core/impl/NameIDMappingResponseChildElements.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         NameIDMappingResponse* response = dynamic_cast<NameIDMappingResponse*>(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         TS_ASSERT(response->getNameID()==nullptr);
76         TS_ASSERT(response->getEncryptedID()==nullptr);
77     }
78
79     void testSingleElementOptionalAttributesUnmarshall() {
80         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
81         NameIDMappingResponse* response = dynamic_cast<NameIDMappingResponse*>(xo.get());
82         TS_ASSERT(response!=nullptr);
83
84         assertEquals("Consent attribute", expectedConsent, response->getConsent());
85         assertEquals("Destination attribute", expectedDestination, response->getDestination());
86         assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
87
88         TS_ASSERT(response->getIssuer()==nullptr);
89         TS_ASSERT(response->getSignature()==nullptr);
90         TS_ASSERT(response->getExtensions()==nullptr);
91         TS_ASSERT(response->getStatus()==nullptr);
92         TS_ASSERT(response->getNameID()==nullptr);
93         TS_ASSERT(response->getEncryptedID()==nullptr);
94     }
95
96     void testChildElementsUnmarshall() {
97         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
98         NameIDMappingResponse* response= dynamic_cast<NameIDMappingResponse*>(xo.get());
99         TS_ASSERT(response!=nullptr);
100
101         TS_ASSERT(response->getIssuer()!=nullptr);
102         TS_ASSERT(response->getSignature()==nullptr);
103         TS_ASSERT(response->getExtensions()==nullptr);
104         TS_ASSERT(response->getStatus()!=nullptr);
105         TS_ASSERT(response->getNameID()!=nullptr);
106         TS_ASSERT(response->getEncryptedID()==nullptr);
107     }
108
109     void testSingleElementMarshall() {
110         NameIDMappingResponse* response = NameIDMappingResponseBuilder::buildNameIDMappingResponse();
111         TS_ASSERT(response!=nullptr);
112
113         response->setID(expectedID);
114         response->setIssueInstant(expectedIssueInstant);
115         //response->setVersion(expectedVersion);
116         assertEquals(expectedDOM, response);
117     }
118
119     void testSingleElementOptionalAttributesMarshall() {
120         NameIDMappingResponse* response = NameIDMappingResponseBuilder::buildNameIDMappingResponse();
121         TS_ASSERT(response!=nullptr);
122
123         response->setID(expectedID);
124         response->setInResponseTo(expectedInResponseTo);
125         response->setIssueInstant(expectedIssueInstant);
126         //response->setVersion(expectedVersion);
127         response->setConsent(expectedConsent);
128         response->setDestination(expectedDestination);
129         response->setInResponseTo(expectedInResponseTo);
130         assertEquals(expectedOptionalAttributesDOM, response);
131     }
132
133     void testChildElementsMarshall() {
134         NameIDMappingResponse* response = NameIDMappingResponseBuilder::buildNameIDMappingResponse();
135         TS_ASSERT(response!=nullptr);
136
137         response->setID(expectedID);
138         response->setIssueInstant(expectedIssueInstant);
139         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
140         Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
141         response->addNamespace(*ns);
142         response->setIssuer(IssuerBuilder::buildIssuer());
143         response->setStatus(StatusBuilder::buildStatus());
144         response->setNameID(NameIDBuilder::buildNameID());
145
146         assertEquals(expectedChildElementsDOM, response);
147         delete ns;
148     }
149
150 };