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 RequestedAuthnContext20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25 XMLCh* expectedComparison;
29 expectedComparison = XMLString::transcode("exact");
31 singleElementFile = data_path + "saml2/core/impl/RequestedAuthnContext.xml";
32 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/RequestedAuthnContextOptionalAttributes.xml";
33 childElementsFile = data_path + "saml2/core/impl/RequestedAuthnContextChildElements.xml";
34 SAMLObjectBaseTestCase::setUp();
38 XMLString::release(&expectedComparison);
39 SAMLObjectBaseTestCase::tearDown();
42 void testSingleElementUnmarshall() {
43 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
44 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
45 TS_ASSERT(rac !=NULL);
46 TS_ASSERT(rac->getComparison()==NULL);
48 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
49 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
52 void testSingleElementOptionalAttributesUnmarshall() {
53 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
54 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
56 assertEquals("Comparison attribute", expectedComparison, rac->getComparison());
58 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
59 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
62 void testChildElementsUnmarshall() {
63 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
64 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
65 TS_ASSERT(rac !=NULL);
66 TS_ASSERT(rac->getComparison()==NULL);
68 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 3, rac->getAuthnContextClassRefs().size());
69 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
72 void testSingleElementMarshall() {
73 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
74 assertEquals(expectedDOM, rac);
77 void testSingleElementOptionalAttributesMarshall() {
78 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
79 rac->setComparison(expectedComparison);
80 assertEquals(expectedOptionalAttributesDOM, rac);
83 void testChildElementsMarshall() {
84 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
85 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
86 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
87 rac->addNamespace(*ns);
88 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
89 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
90 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
91 assertEquals(expectedChildElementsDOM, rac);