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/security/X509Credential.h>
21 #include <xmltooling/security/KeyInfoResolver.h>
22 #include <xmltooling/signature/KeyInfo.h>
24 using namespace xmlsignature;
26 class InlineKeyResolverTest : public CxxTest::TestSuite {
27 KeyInfoResolver* m_resolver;
29 InlineKeyResolverTest() : m_resolver(NULL) {}
32 string config = data_path + "InlineKeyResolver.xml";
33 ifstream in(config.c_str());
34 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
35 XercesJanitor<DOMDocument> janitor(doc);
36 m_resolver=XMLToolingConfig::getConfig().KeyInfoResolverManager.newPlugin(INLINE_KEYINFO_RESOLVER,doc->getDocumentElement());
45 string path=data_path + "KeyInfo1.xml";
46 ifstream fs(path.c_str());
47 DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);
49 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
51 auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
52 TS_ASSERT(kiObject.get()!=NULL);
54 auto_ptr<X509Credential> cred(dynamic_cast<X509Credential*>(m_resolver->resolve(kiObject.get())));
55 TSM_ASSERT("Unable to resolve KeyInfo into Credential.", cred.get()!=NULL);
57 TSM_ASSERT("Unable to resolve public key.", cred->getPublicKey()!=NULL);
58 TSM_ASSERT_EQUALS("Unexpected key type.", cred->getPublicKey()->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);
59 TSM_ASSERT_EQUALS("Wrong certificate count.", cred->getEntityCertificateChain().size(), 1);
60 TSM_ASSERT("Unable to resolve CRL.", cred->getCRL()!=NULL);