2 * Copyright 2001-2007 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 AttributeQuery20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
26 XMLCh* expectedVersion;
27 XMLCh* expectedConsent;
28 XMLCh* expectedDestination;
29 DateTime* expectedIssueInstant;
33 expectedID = XMLString::transcode("abc123");;
34 expectedVersion = XMLString::transcode("2.0");
35 expectedConsent = XMLString::transcode("urn:string:consent");
36 expectedDestination = XMLString::transcode("http://idp.example.org/endpoint");
37 expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
38 expectedIssueInstant->parseDateTime();
40 singleElementFile = data_path + "saml2/core/impl/AttributeQuery.xml";
41 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AttributeQueryOptionalAttributes.xml";
42 childElementsFile = data_path + "saml2/core/impl/AttributeQueryChildElements.xml";
43 SAMLObjectBaseTestCase::setUp();
47 XMLString::release(&expectedID);
48 XMLString::release(&expectedVersion);
49 XMLString::release(&expectedConsent);
50 XMLString::release(&expectedDestination);
51 delete expectedIssueInstant;
52 SAMLObjectBaseTestCase::tearDown();
55 void testSingleElementUnmarshall() {
56 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
57 AttributeQuery* query = dynamic_cast<AttributeQuery*>(xo.get());
58 TS_ASSERT(query!=NULL);
59 assertEquals("ID attribute", expectedID, query->getID());
60 assertEquals("Version attribute", expectedVersion, query->getVersion());
61 TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), query->getIssueInstant()->getEpoch());
63 TS_ASSERT(query->getIssuer()==NULL);
64 TS_ASSERT(query->getSignature()==NULL);
65 TS_ASSERT(query->getExtensions()==NULL);
66 TS_ASSERT(query->getSubject()==NULL);
69 void testSingleElementOptionalAttributesUnmarshall() {
70 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
71 AttributeQuery* query = dynamic_cast<AttributeQuery*>(xo.get());
72 TS_ASSERT(query!=NULL);
73 assertEquals("Consent attribute", expectedConsent, query->getConsent());
74 assertEquals("Destination attribute", expectedDestination, query->getDestination());
76 TS_ASSERT(query->getIssuer()==NULL);
77 TS_ASSERT(query->getSignature()==NULL);
78 TS_ASSERT(query->getExtensions()==NULL);
79 TS_ASSERT(query->getSubject()==NULL);
82 void testChildElementsUnmarshall() {
83 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
84 AttributeQuery* query= dynamic_cast<AttributeQuery*>(xo.get());
85 TS_ASSERT(query!=NULL);
86 TS_ASSERT(query->getIssuer()!=NULL);
87 TS_ASSERT(query->getSignature()==NULL);
88 TS_ASSERT(query->getExtensions()==NULL);
89 TS_ASSERT(query->getSubject()!=NULL);
90 TSM_ASSERT_EQUALS("# of Attribute child elements", 4, query->getAttributes().size());
93 void testSingleElementMarshall() {
94 AttributeQuery* query=AttributeQueryBuilder::buildAttributeQuery();
95 query->setID(expectedID);
96 query->setIssueInstant(expectedIssueInstant);
97 //query->setVersion(expectedVersion);
98 assertEquals(expectedDOM, query);
101 void testSingleElementOptionalAttributesMarshall() {
102 AttributeQuery* query=AttributeQueryBuilder::buildAttributeQuery();
103 query->setID(expectedID);
104 query->setIssueInstant(expectedIssueInstant);
105 //query->setVersion(expectedVersion);
106 query->setConsent(expectedConsent);
107 query->setDestination(expectedDestination);
108 assertEquals(expectedOptionalAttributesDOM, query);
111 void testChildElementsMarshall() {
112 AttributeQuery* query=AttributeQueryBuilder::buildAttributeQuery();
113 query->setID(expectedID);
114 query->setIssueInstant(expectedIssueInstant);
115 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
116 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
117 query->addNamespace(*ns);
118 query->setIssuer(IssuerBuilder::buildIssuer());
119 query->setSubject(SubjectBuilder::buildSubject());
120 query->getAttributes().push_back(AttributeBuilder::buildAttribute());
121 query->getAttributes().push_back(AttributeBuilder::buildAttribute());
122 query->getAttributes().push_back(AttributeBuilder::buildAttribute());
123 query->getAttributes().push_back(AttributeBuilder::buildAttribute());
124 assertEquals(expectedChildElementsDOM, query);