e01b9f915586f1bb8028a7a12e61fbaed0b7dee5
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / ArtifactResponse20Test.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 class ArtifactResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
25     XMLCh* expectedID; \r
26     XMLCh* expectedInResponseTo; \r
27     XMLCh* expectedVersion; \r
28     XMLCh* expectedConsent; \r
29     XMLCh* expectedDestination; \r
30     DateTime* expectedIssueInstant; \r
31 \r
32     // The payload will be an AuthnRequest in this test.\r
33     // AuthnRequest marshaller autogenerates ID, Version and IssueInstant if they are NULL,\r
34     // so have to agree on something to put in the control XML\r
35     XMLCh* authnRequestID;\r
36 \r
37 public:\r
38     void setUp() {\r
39         expectedID = XMLString::transcode("def456"); \r
40         expectedInResponseTo = XMLString::transcode("abc123"); \r
41         expectedVersion = XMLString::transcode("2.0"); \r
42         expectedConsent = XMLString::transcode("urn:string:consent"); \r
43         expectedDestination = XMLString::transcode("http://sp.example.org/endpoint"); \r
44         expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));\r
45 \r
46         authnRequestID = XMLString::transcode("test1"); \r
47 \r
48         singleElementFile = data_path + "saml2/core/impl/ArtifactResponse.xml";\r
49         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ArtifactResponseOptionalAttributes.xml";\r
50         childElementsFile  = data_path + "saml2/core/impl/ArtifactResponseChildElements.xml";    \r
51         SAMLObjectBaseTestCase::setUp();\r
52     }\r
53     \r
54     void tearDown() {\r
55         XMLString::release(&expectedID);\r
56         XMLString::release(&expectedInResponseTo);\r
57         XMLString::release(&expectedVersion);\r
58         XMLString::release(&expectedConsent);\r
59         XMLString::release(&expectedDestination);\r
60         XMLString::release(&authnRequestID);\r
61         delete expectedIssueInstant;\r
62         SAMLObjectBaseTestCase::tearDown();\r
63     }\r
64 \r
65     void testSingleElementUnmarshall() {\r
66         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
67         ArtifactResponse* response = dynamic_cast<ArtifactResponse*>(xo.get());\r
68         TS_ASSERT(response!=NULL);\r
69 \r
70         assertEquals("ID attribute", expectedID, response->getID());\r
71         assertEquals("Version attribute", expectedVersion, response->getVersion());\r
72         assertEquals("IssueInstant attribute", expectedIssueInstant->getFormattedString(), response->getIssueInstant()->getFormattedString());\r
73 \r
74         TS_ASSERT(response->getIssuer()==NULL);\r
75         TS_ASSERT(response->getSignature()==NULL);\r
76         TS_ASSERT(response->getExtensions()==NULL);\r
77         TS_ASSERT(response->getStatus()==NULL);\r
78         TS_ASSERT(response->getPayload()==NULL);\r
79     }\r
80 \r
81     void testSingleElementOptionalAttributesUnmarshall() {\r
82         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
83         ArtifactResponse* response = dynamic_cast<ArtifactResponse*>(xo.get());\r
84         TS_ASSERT(response!=NULL);\r
85 \r
86         assertEquals("Consent attribute", expectedConsent, response->getConsent());\r
87         assertEquals("Destination attribute", expectedDestination, response->getDestination());\r
88         assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());\r
89 \r
90         TS_ASSERT(response->getIssuer()==NULL);\r
91         TS_ASSERT(response->getSignature()==NULL);\r
92         TS_ASSERT(response->getExtensions()==NULL);\r
93         TS_ASSERT(response->getStatus()==NULL);\r
94         TS_ASSERT(response->getPayload()==NULL);\r
95     }\r
96 \r
97     void testChildElementsUnmarshall() {\r
98         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
99         ArtifactResponse* response= dynamic_cast<ArtifactResponse*>(xo.get());\r
100         TS_ASSERT(response!=NULL);\r
101 \r
102         TS_ASSERT(response->getIssuer()!=NULL);\r
103         TS_ASSERT(response->getSignature()==NULL);\r
104         TS_ASSERT(response->getExtensions()==NULL);\r
105         TS_ASSERT(response->getStatus()!=NULL);\r
106         TS_ASSERT(response->getPayload()!=NULL);\r
107     }\r
108 \r
109     void testSingleElementMarshall() {\r
110         ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();\r
111         TS_ASSERT(response!=NULL);\r
112 \r
113         response->setID(expectedID);\r
114         response->setIssueInstant(expectedIssueInstant);\r
115         //response->setVersion(expectedVersion);\r
116         assertEquals(expectedDOM, response);\r
117     }\r
118 \r
119     void testSingleElementOptionalAttributesMarshall() {\r
120         ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();\r
121         TS_ASSERT(response!=NULL);\r
122 \r
123         response->setID(expectedID);\r
124         response->setInResponseTo(expectedInResponseTo);\r
125         response->setIssueInstant(expectedIssueInstant);\r
126         //response->setVersion(expectedVersion);\r
127         response->setConsent(expectedConsent);\r
128         response->setDestination(expectedDestination);\r
129         response->setInResponseTo(expectedInResponseTo);\r
130         assertEquals(expectedOptionalAttributesDOM, response);\r
131     }\r
132 \r
133     void testChildElementsMarshall() {\r
134         ArtifactResponse* response = ArtifactResponseBuilder::buildArtifactResponse();\r
135         TS_ASSERT(response!=NULL);\r
136 \r
137         response->setID(expectedID);\r
138         response->setIssueInstant(expectedIssueInstant);\r
139         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file\r
140         Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);\r
141         response->addNamespace(*ns);\r
142         response->setIssuer(IssuerBuilder::buildIssuer());\r
143         response->setStatus(StatusBuilder::buildStatus());\r
144 \r
145         AuthnRequest* authnRequest = AuthnRequestBuilder::buildAuthnRequest();\r
146         authnRequest->setIssueInstant(expectedIssueInstant);\r
147         authnRequest->setID(authnRequestID);\r
148         response->setPayload(authnRequest);\r
149 \r
150         assertEquals(expectedChildElementsDOM, response);\r
151         delete ns;\r
152     }\r
153 \r
154 };\r