Multi-line svn commit, see body.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / StatusResponse20Test.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include "internal.h"\r
18 #include <saml/saml2/core/Protocols.h>\r
19 #include <saml/util/SAMLConstants.h>\r
20 \r
21 using namespace opensaml::saml2p;\r
22 using namespace opensaml::saml2;\r
23 \r
24 /*\r
25    This tests building an element of type StatusResponseType with a non-SAML element name and namespace\r
26  */\r
27 \r
28 class StatusResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
29     XMLCh* expectedID; \r
30     XMLCh* expectedInResponseTo; \r
31     XMLCh* expectedVersion; \r
32     XMLCh* expectedConsent; \r
33     XMLCh* expectedDestination; \r
34     DateTime* expectedIssueInstant; \r
35 \r
36     //TODO possibly move these up to SAMLObjectBaseTestCase, for use in optional helper methods below\r
37     XMLCh* elementName;\r
38     XMLCh* elementNS;\r
39     XMLCh* elementPrefix;\r
40     const XMLCh* typeName;\r
41     const XMLCh* typeNS;\r
42     const XMLCh* typePrefix;\r
43 \r
44 public:\r
45     void setUp() {\r
46         expectedID = XMLString::transcode("def456"); \r
47         expectedInResponseTo = XMLString::transcode("abc123"); \r
48         expectedVersion = XMLString::transcode("2.0"); \r
49         expectedConsent = XMLString::transcode("urn:string:consent"); \r
50         expectedDestination = XMLString::transcode("http://sp.example.org/endpoint"); \r
51         expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));\r
52 \r
53         elementName = XMLString::transcode("Foo");;\r
54         elementNS = XMLString::transcode("http://www.example.org/test");\r
55         elementPrefix = XMLString::transcode("test");;\r
56         typeName = StatusResponse::TYPE_NAME;\r
57         typeNS = SAMLConstants::SAML20P_NS;\r
58         typePrefix = SAMLConstants::SAML20P_PREFIX;\r
59 \r
60         singleElementFile = data_path + "saml2/core/impl/StatusResponse.xml";\r
61         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/StatusResponseOptionalAttributes.xml";\r
62         childElementsFile  = data_path + "saml2/core/impl/StatusResponseChildElements.xml";    \r
63         SAMLObjectBaseTestCase::setUp();\r
64     }\r
65     \r
66     void tearDown() {\r
67         XMLString::release(&expectedID);\r
68         XMLString::release(&expectedInResponseTo);\r
69         XMLString::release(&expectedVersion);\r
70         XMLString::release(&expectedConsent);\r
71         XMLString::release(&expectedDestination);\r
72         XMLString::release(&elementName);\r
73         XMLString::release(&elementNS);\r
74         XMLString::release(&elementPrefix);\r
75         delete expectedIssueInstant;\r
76         SAMLObjectBaseTestCase::tearDown();\r
77     }\r
78 \r
79     //TODO possibly move this functionality up to SAMLObjectBaseTestCase, as optional helper method\r
80     void checkNameAndType(XMLObject* xo) {\r
81         assertEquals("Element name", elementName, xo->getElementQName().getLocalPart());\r
82         assertEquals("Element namespace", elementNS, xo->getElementQName().getNamespaceURI());\r
83         assertEquals("Element namespace prefix", elementPrefix, xo->getElementQName().getPrefix());\r
84 \r
85         assertEquals("Schema type name", typeName, xo->getSchemaType()->getLocalPart());\r
86         assertEquals("Schema type namespace", typeNS, xo->getSchemaType()->getNamespaceURI());\r
87         assertEquals("Schema type namespace prefix", typePrefix, xo->getSchemaType()->getPrefix());\r
88     }\r
89 \r
90     //TODO possibly move this functionality up to SAMLObjectBaseTestCase, as optional helper method\r
91     XMLObject * buildObject() {\r
92         const XMLObjectBuilder* builder = XMLObjectBuilder::getBuilder(QName(typeNS,typeName));\r
93         QName type(typeNS,typeName,typePrefix);\r
94         return builder->buildObject(elementNS, elementName, elementPrefix, &type);\r
95     }\r
96 \r
97     void testSingleElementUnmarshall() {\r
98         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
99         StatusResponse* response = dynamic_cast<StatusResponse*>(xo.get());\r
100         TS_ASSERT(response!=NULL);\r
101 \r
102         checkNameAndType(response);\r
103 \r
104         assertEquals("ID attribute", expectedID, response->getID());\r
105         assertEquals("Version attribute", expectedVersion, response->getVersion());\r
106         assertEquals("IssueInstant attribute", expectedIssueInstant->getFormattedString(), response->getIssueInstant()->getFormattedString());\r
107 \r
108         TS_ASSERT(response->getIssuer()==NULL);\r
109         TS_ASSERT(response->getSignature()==NULL);\r
110         TS_ASSERT(response->getExtensions()==NULL);\r
111         TS_ASSERT(response->getStatus()==NULL);\r
112     }\r
113 \r
114     void testSingleElementOptionalAttributesUnmarshall() {\r
115         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
116         StatusResponse* response = dynamic_cast<StatusResponse*>(xo.get());\r
117         TS_ASSERT(response!=NULL);\r
118 \r
119         checkNameAndType(response);\r
120 \r
121         assertEquals("Consent attribute", expectedConsent, response->getConsent());\r
122         assertEquals("Destination attribute", expectedDestination, response->getDestination());\r
123         assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());\r
124 \r
125         TS_ASSERT(response->getIssuer()==NULL);\r
126         TS_ASSERT(response->getSignature()==NULL);\r
127         TS_ASSERT(response->getExtensions()==NULL);\r
128         TS_ASSERT(response->getStatus()==NULL);\r
129     }\r
130 \r
131     void testChildElementsUnmarshall() {\r
132         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
133         StatusResponse* response= dynamic_cast<StatusResponse*>(xo.get());\r
134         TS_ASSERT(response!=NULL);\r
135 \r
136         checkNameAndType(response);\r
137 \r
138         TS_ASSERT(response->getIssuer()!=NULL);\r
139         TS_ASSERT(response->getSignature()==NULL);\r
140         TS_ASSERT(response->getExtensions()==NULL);\r
141         TS_ASSERT(response->getStatus()!=NULL);\r
142     }\r
143 \r
144     void testSingleElementMarshall() {\r
145         StatusResponse* response = dynamic_cast<StatusResponse*>(buildObject());\r
146         TS_ASSERT(response!=NULL);\r
147         checkNameAndType(response);\r
148 \r
149         response->setID(expectedID);\r
150         response->setIssueInstant(expectedIssueInstant);\r
151         //response->setVersion(expectedVersion);\r
152         assertEquals(expectedDOM, response);\r
153     }\r
154 \r
155     void testSingleElementOptionalAttributesMarshall() {\r
156         StatusResponse* response = dynamic_cast<StatusResponse*>(buildObject());\r
157         TS_ASSERT(response!=NULL);\r
158         checkNameAndType(response);\r
159 \r
160         response->setID(expectedID);\r
161         response->setInResponseTo(expectedInResponseTo);\r
162         response->setIssueInstant(expectedIssueInstant);\r
163         //response->setVersion(expectedVersion);\r
164         response->setConsent(expectedConsent);\r
165         response->setDestination(expectedDestination);\r
166         response->setInResponseTo(expectedInResponseTo);\r
167         assertEquals(expectedOptionalAttributesDOM, response);\r
168     }\r
169 \r
170     void testChildElementsMarshall() {\r
171         StatusResponse* response = dynamic_cast<StatusResponse*>(buildObject());\r
172         TS_ASSERT(response!=NULL);\r
173         checkNameAndType(response);\r
174 \r
175         response->setID(expectedID);\r
176         response->setIssueInstant(expectedIssueInstant);\r
177         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file\r
178         Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);\r
179         response->addNamespace(*ns);\r
180         response->setIssuer(IssuerBuilder::buildIssuer());\r
181         response->setStatus(StatusBuilder::buildStatus());\r
182         assertEquals(expectedChildElementsDOM, response);\r
183         delete ns;\r
184     }\r
185 \r
186 };\r