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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <saml/saml2/core/Protocols.h>
23 #include <saml/util/SAMLConstants.h>
25 using namespace opensaml::saml2p;
26 using namespace opensaml::saml2;
28 class RequestedAuthnContext20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
29 XMLCh* expectedComparison;
33 expectedComparison = XMLString::transcode("exact");
35 singleElementFile = data_path + "saml2/core/impl/RequestedAuthnContext.xml";
36 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/RequestedAuthnContextOptionalAttributes.xml";
37 childElementsFile = data_path + "saml2/core/impl/RequestedAuthnContextChildElements.xml";
38 SAMLObjectBaseTestCase::setUp();
42 XMLString::release(&expectedComparison);
43 SAMLObjectBaseTestCase::tearDown();
46 void testSingleElementUnmarshall() {
47 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
48 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
49 TS_ASSERT(rac !=nullptr);
50 TS_ASSERT(rac->getComparison()==nullptr);
52 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
53 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
56 void testSingleElementOptionalAttributesUnmarshall() {
57 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
58 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
59 TS_ASSERT(rac!=nullptr);
60 assertEquals("Comparison attribute", expectedComparison, rac->getComparison());
62 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
63 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
66 void testChildElementsUnmarshall() {
67 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
68 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
69 TS_ASSERT(rac !=nullptr);
70 TS_ASSERT(rac->getComparison()==nullptr);
72 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 3, rac->getAuthnContextClassRefs().size());
73 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
76 void testSingleElementMarshall() {
77 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
78 assertEquals(expectedDOM, rac);
81 void testSingleElementOptionalAttributesMarshall() {
82 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
83 rac->setComparison(expectedComparison);
84 assertEquals(expectedOptionalAttributesDOM, rac);
87 void testChildElementsMarshall() {
88 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
89 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
90 Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
91 rac->addNamespace(*ns);
92 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
93 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
94 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
95 assertEquals(expectedChildElementsDOM, rac);