Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / RequestedAuthnContext20Test.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include "internal.h"
22 #include <saml/saml2/core/Protocols.h>
23 #include <saml/util/SAMLConstants.h>
24
25 using namespace opensaml::saml2p;
26 using namespace opensaml::saml2;
27
28 class RequestedAuthnContext20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
29     XMLCh* expectedComparison; 
30
31 public:
32     void setUp() {
33         expectedComparison = XMLString::transcode("exact"); 
34
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();
39     }
40     
41     void tearDown() {
42         XMLString::release(&expectedComparison);
43         SAMLObjectBaseTestCase::tearDown();
44     }
45
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);
51
52         TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
53         TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
54     }
55
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());
61
62         TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
63         TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
64     }
65
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);
71
72         TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 3, rac->getAuthnContextClassRefs().size());
73         TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
74     }
75
76     void testSingleElementMarshall() {
77         RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
78         assertEquals(expectedDOM, rac);
79     }
80
81     void testSingleElementOptionalAttributesMarshall() {
82         RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
83         rac->setComparison(expectedComparison);
84         assertEquals(expectedOptionalAttributesDOM, rac);
85     }
86
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);
96         delete ns;
97     }
98
99 };