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 <xmltooling/encryption/Encryption.h>
20 #include <xmltooling/util/XMLConstants.h>
22 using namespace opensaml;
23 using namespace opensaml::saml2p;
24 using namespace xmlencryption;
26 class NewEncryptedID20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
30 singleElementFile = data_path + "saml2/core/impl/NewEncryptedID.xml";
31 childElementsFile = data_path + "saml2/core/impl/NewEncryptedIDChildElements.xml";
32 SAMLObjectBaseTestCase::setUp();
36 SAMLObjectBaseTestCase::tearDown();
39 void testSingleElementUnmarshall() {
40 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
41 NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());
42 TS_ASSERT(encID!=NULL);
43 TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()==NULL);
44 TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 0, encID->getEncryptedKeys().size());
47 void testChildElementsUnmarshall() {
48 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
49 NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());
50 TS_ASSERT(encID!=NULL);
51 TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()!=NULL);
52 TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 2, encID->getEncryptedKeys().size());
55 void testSingleElementMarshall() {
56 NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();
57 assertEquals(expectedDOM, encID);
60 void testChildElementsMarshall() {
61 NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();
62 // Do this just so don't have to redeclare the xenc namespace prefix on every child element in the control XML file
63 Namespace* ns = new Namespace(xmlconstants::XMLENC_NS, xmlconstants::XMLENC_PREFIX);
64 encID->addNamespace(*ns);
65 encID->setEncryptedData(EncryptedDataBuilder::buildEncryptedData());
66 encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());
67 encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());
68 assertEquals(expectedChildElementsDOM, encID);