Convert from NULL macro to nullptr, remove unused zlib code.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / AuthzDecisionQuery20Test.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 AuthzDecisionQuery20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25     XMLCh* expectedID; 
26     XMLCh* expectedVersion; 
27     XMLCh* expectedConsent; 
28     XMLCh* expectedDestination; 
29     DateTime* expectedIssueInstant; 
30     XMLCh* expectedResource; 
31
32 public:
33     void setUp() {
34         expectedID = XMLString::transcode("abc123");; 
35         expectedVersion = XMLString::transcode("2.0"); 
36         expectedConsent = XMLString::transcode("urn:string:consent"); 
37         expectedDestination = XMLString::transcode("http://idp.example.org/endpoint"); 
38         expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
39         expectedIssueInstant->parseDateTime();
40         expectedResource = XMLString::transcode("urn:string:resource");
41
42         singleElementFile = data_path + "saml2/core/impl/AuthzDecisionQuery.xml";
43         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AuthzDecisionQueryOptionalAttributes.xml";
44         childElementsFile  = data_path + "saml2/core/impl/AuthzDecisionQueryChildElements.xml";    
45         SAMLObjectBaseTestCase::setUp();
46     }
47     
48     void tearDown() {
49         XMLString::release(&expectedID);
50         XMLString::release(&expectedVersion);
51         XMLString::release(&expectedConsent);
52         XMLString::release(&expectedDestination);
53         XMLString::release(&expectedResource);
54         delete expectedIssueInstant;
55         SAMLObjectBaseTestCase::tearDown();
56     }
57
58     void testSingleElementUnmarshall() {
59         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
60         AuthzDecisionQuery* query = dynamic_cast<AuthzDecisionQuery*>(xo.get());
61         TS_ASSERT(query!=nullptr);
62         assertEquals("ID attribute", expectedID, query->getID());
63         assertEquals("Version attribute", expectedVersion, query->getVersion());
64         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), query->getIssueInstant()->getEpoch());
65         assertEquals("Resource attribute", expectedResource, query->getResource());
66
67         TS_ASSERT(query->getIssuer()==nullptr);
68         TS_ASSERT(query->getSignature()==nullptr);
69         TS_ASSERT(query->getExtensions()==nullptr);
70         TS_ASSERT(query->getSubject()==nullptr);
71         TSM_ASSERT_EQUALS("# of Action child elements", 0, query->getActions().size());
72         TS_ASSERT(query->getEvidence()==nullptr);
73     }
74
75     void testSingleElementOptionalAttributesUnmarshall() {
76         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
77         AuthzDecisionQuery* query = dynamic_cast<AuthzDecisionQuery*>(xo.get());
78         TS_ASSERT(query!=nullptr);
79         assertEquals("Consent attribute", expectedConsent, query->getConsent());
80         assertEquals("Destination attribute", expectedDestination, query->getDestination());
81
82         TS_ASSERT(query->getIssuer()==nullptr);
83         TS_ASSERT(query->getSignature()==nullptr);
84         TS_ASSERT(query->getExtensions()==nullptr);
85         TS_ASSERT(query->getSubject()==nullptr);
86         TSM_ASSERT_EQUALS("# of Action child elements", 0, query->getActions().size());
87         TS_ASSERT(query->getEvidence()==nullptr);
88     }
89
90     void testChildElementsUnmarshall() {
91         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
92         AuthzDecisionQuery* query= dynamic_cast<AuthzDecisionQuery*>(xo.get());
93         TS_ASSERT(query!=nullptr);
94         TS_ASSERT(query->getIssuer()!=nullptr);
95         TS_ASSERT(query->getSignature()==nullptr);
96         TS_ASSERT(query->getExtensions()==nullptr);
97         TS_ASSERT(query->getSubject()!=nullptr);
98         TSM_ASSERT_EQUALS("# of Action child elements", 2, query->getActions().size());
99         TS_ASSERT(query->getEvidence()!=nullptr);
100     }
101
102     void testSingleElementMarshall() {
103         AuthzDecisionQuery* query=AuthzDecisionQueryBuilder::buildAuthzDecisionQuery();
104         query->setID(expectedID);
105         query->setIssueInstant(expectedIssueInstant);
106         //query->setVersion(expectedVersion);
107         query->setResource(expectedResource);
108         assertEquals(expectedDOM, query);
109     }
110
111     void testSingleElementOptionalAttributesMarshall() {
112         AuthzDecisionQuery* query=AuthzDecisionQueryBuilder::buildAuthzDecisionQuery();
113         query->setID(expectedID);
114         query->setIssueInstant(expectedIssueInstant);
115         //query->setVersion(expectedVersion);
116         query->setConsent(expectedConsent);
117         query->setDestination(expectedDestination);
118         query->setResource(expectedResource);
119         assertEquals(expectedOptionalAttributesDOM, query);
120     }
121
122     void testChildElementsMarshall() {
123         AuthzDecisionQuery* query=AuthzDecisionQueryBuilder::buildAuthzDecisionQuery();
124         query->setID(expectedID);
125         query->setIssueInstant(expectedIssueInstant);
126         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
127         Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
128         query->addNamespace(*ns);
129         query->setIssuer(IssuerBuilder::buildIssuer());
130         query->setSubject(SubjectBuilder::buildSubject());
131         query->getActions().push_back(ActionBuilder::buildAction());
132         query->getActions().push_back(ActionBuilder::buildAction());
133         query->setEvidence(EvidenceBuilder::buildEvidence());
134         assertEquals(expectedChildElementsDOM, query);
135         delete ns;
136     }
137
138 };