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.
17 #include "XMLObjectBaseTestCase.h"
20 #include <xmltooling/signature/KeyInfo.h>
21 #include <xmltooling/validation/ValidatorSuite.h>
23 using namespace xmlsignature;
25 class KeyInfoTest : public CxxTest::TestSuite {
30 XMLObjectBuilder::registerDefaultBuilder(new AnyElementBuilder());
34 XMLObjectBuilder::deregisterDefaultBuilder();
38 string path=data_path + "KeyInfo1.xml";
39 ifstream fs(path.c_str());
40 DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);
43 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
46 auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
47 TS_ASSERT(kiObject.get()!=NULL);
48 TSM_ASSERT_EQUALS("Number of child elements was not expected value",
49 3, kiObject->getOrderedChildren().size());
50 TSM_ASSERT_EQUALS("Number of child elements was not expected value",
51 1, kiObject->getKeyValues().size());
52 TSM_ASSERT_EQUALS("Number of child elements was not expected value",
53 1, kiObject->getX509Datas().front()->getX509Certificates().size());
55 auto_ptr_XMLCh expected("Public Key for CN=xmldap.org, OU=Domain Control Validated, O=xmldap.org");
56 TSM_ASSERT("KeyName was not expected value", XMLString::equals(expected.get(), kiObject->getKeyNames().front()->getName()));
58 SchemaValidators.validate(kiObject.get());
62 string path=data_path + "KeyInfo2.xml";
63 ifstream fs(path.c_str());
64 DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);
67 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
70 auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
71 TS_ASSERT(kiObject.get()!=NULL);
72 TSM_ASSERT_EQUALS("Number of child elements was not expected value",
73 2, kiObject->getOrderedChildren().size());
74 TSM_ASSERT_EQUALS("Number of child elements was not expected value",
75 1, kiObject->getRetrievalMethods().size());
76 TSM_ASSERT_EQUALS("Number of child elements was not expected value",
77 2, kiObject->getSPKIDatas().front()->getSPKISexps().size());
79 SchemaValidators.validate(kiObject.get());
83 string path=data_path + "KeyInfo3.xml";
84 ifstream fs(path.c_str());
85 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
88 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
91 auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
92 TS_ASSERT(kiObject.get()!=NULL);
93 TS_ASSERT_THROWS(SchemaValidators.validate(kiObject.get()),ValidationException);