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