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