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 AuthnQuery20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
26 XMLCh* expectedVersion;
27 XMLCh* expectedConsent;
28 XMLCh* expectedDestination;
29 DateTime* expectedIssueInstant;
30 XMLCh* expectedSessionIndex;
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 expectedSessionIndex = XMLString::transcode("session12345");
42 singleElementFile = data_path + "saml2/core/impl/AuthnQuery.xml";
43 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AuthnQueryOptionalAttributes.xml";
44 childElementsFile = data_path + "saml2/core/impl/AuthnQueryChildElements.xml";
45 SAMLObjectBaseTestCase::setUp();
49 XMLString::release(&expectedID);
50 XMLString::release(&expectedVersion);
51 XMLString::release(&expectedConsent);
52 XMLString::release(&expectedDestination);
53 XMLString::release(&expectedSessionIndex);
54 delete expectedIssueInstant;
55 SAMLObjectBaseTestCase::tearDown();
58 void testSingleElementUnmarshall() {
59 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
60 AuthnQuery* query = dynamic_cast<AuthnQuery*>(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());
66 TS_ASSERT(query->getIssuer()==NULL);
67 TS_ASSERT(query->getSignature()==NULL);
68 TS_ASSERT(query->getExtensions()==NULL);
69 TS_ASSERT(query->getSubject()==NULL);
70 TS_ASSERT(query->getRequestedAuthnContext()==NULL);
73 void testSingleElementOptionalAttributesUnmarshall() {
74 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
75 AuthnQuery* query = dynamic_cast<AuthnQuery*>(xo.get());
76 TS_ASSERT(query!=NULL);
77 assertEquals("Consent attribute", expectedConsent, query->getConsent());
78 assertEquals("Destination attribute", expectedDestination, query->getDestination());
79 assertEquals("SessionIndex attribute", expectedSessionIndex, query->getSessionIndex());
81 TS_ASSERT(query->getIssuer()==NULL);
82 TS_ASSERT(query->getSignature()==NULL);
83 TS_ASSERT(query->getExtensions()==NULL);
84 TS_ASSERT(query->getSubject()==NULL);
85 TS_ASSERT(query->getRequestedAuthnContext()==NULL);
88 void testChildElementsUnmarshall() {
89 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
90 AuthnQuery* query= dynamic_cast<AuthnQuery*>(xo.get());
91 TS_ASSERT(query!=NULL);
92 TS_ASSERT(query->getIssuer()!=NULL);
93 TS_ASSERT(query->getSignature()==NULL);
94 TS_ASSERT(query->getExtensions()==NULL);
95 TS_ASSERT(query->getSubject()!=NULL);
96 TS_ASSERT(query->getRequestedAuthnContext()!=NULL);
99 void testSingleElementMarshall() {
100 AuthnQuery* query=AuthnQueryBuilder::buildAuthnQuery();
101 query->setID(expectedID);
102 query->setIssueInstant(expectedIssueInstant);
103 //query->setVersion(expectedVersion);
104 assertEquals(expectedDOM, query);
107 void testSingleElementOptionalAttributesMarshall() {
108 AuthnQuery* query=AuthnQueryBuilder::buildAuthnQuery();
109 query->setID(expectedID);
110 query->setIssueInstant(expectedIssueInstant);
111 //query->setVersion(expectedVersion);
112 query->setConsent(expectedConsent);
113 query->setDestination(expectedDestination);
114 query->setSessionIndex(expectedSessionIndex);
115 assertEquals(expectedOptionalAttributesDOM, query);
118 void testChildElementsMarshall() {
119 AuthnQuery* query=AuthnQueryBuilder::buildAuthnQuery();
120 query->setID(expectedID);
121 query->setIssueInstant(expectedIssueInstant);
122 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
123 Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);
124 query->addNamespace(*ns);
125 query->setIssuer(IssuerBuilder::buildIssuer());
126 query->setSubject(SubjectBuilder::buildSubject());
127 query->setRequestedAuthnContext(RequestedAuthnContextBuilder::buildRequestedAuthnContext());
128 assertEquals(expectedChildElementsDOM, query);