2 * Copyright 2001-2006 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <saml/saml2/core/Protocols.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
24 class AuthzDecisionQuery20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
26 XMLCh* expectedVersion;
27 XMLCh* expectedConsent;
28 XMLCh* expectedDestination;
29 DateTime* expectedIssueInstant;
30 XMLCh* expectedResource;
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");
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();
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();
58 void testSingleElementUnmarshall() {
59 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
60 AuthzDecisionQuery* query = dynamic_cast<AuthzDecisionQuery*>(xo.get());
61 TS_ASSERT(query!=NULL);
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());
67 TS_ASSERT(query->getIssuer()==NULL);
68 TS_ASSERT(query->getSignature()==NULL);
69 TS_ASSERT(query->getExtensions()==NULL);
70 TS_ASSERT(query->getSubject()==NULL);
71 TSM_ASSERT_EQUALS("# of Action child elements", 0, query->getActions().size());
72 TS_ASSERT(query->getEvidence()==NULL);
75 void testSingleElementOptionalAttributesUnmarshall() {
76 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
77 AuthzDecisionQuery* query = dynamic_cast<AuthzDecisionQuery*>(xo.get());
78 TS_ASSERT(query!=NULL);
79 assertEquals("Consent attribute", expectedConsent, query->getConsent());
80 assertEquals("Destination attribute", expectedDestination, query->getDestination());
82 TS_ASSERT(query->getIssuer()==NULL);
83 TS_ASSERT(query->getSignature()==NULL);
84 TS_ASSERT(query->getExtensions()==NULL);
85 TS_ASSERT(query->getSubject()==NULL);
86 TSM_ASSERT_EQUALS("# of Action child elements", 0, query->getActions().size());
87 TS_ASSERT(query->getEvidence()==NULL);
90 void testChildElementsUnmarshall() {
91 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
92 AuthzDecisionQuery* query= dynamic_cast<AuthzDecisionQuery*>(xo.get());
93 TS_ASSERT(query!=NULL);
94 TS_ASSERT(query->getIssuer()!=NULL);
95 TS_ASSERT(query->getSignature()==NULL);
96 TS_ASSERT(query->getExtensions()==NULL);
97 TS_ASSERT(query->getSubject()!=NULL);
98 TSM_ASSERT_EQUALS("# of Action child elements", 2, query->getActions().size());
99 TS_ASSERT(query->getEvidence()!=NULL);
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);
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);
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(opensaml::SAMLConstants::SAML20_NS, opensaml::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);