Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / InlineKeyResolverTest.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "XMLObjectBaseTestCase.h"
18
19 #include <fstream>
20 #include <xmltooling/signature/KeyInfo.h>
21 #include <xmltooling/signature/KeyResolver.h>
22
23 using namespace xmlsignature;
24
25 class InlineKeyResolverTest : public CxxTest::TestSuite {
26     KeyResolver* m_resolver;
27 public:
28     InlineKeyResolverTest() : m_resolver(NULL) {}
29
30     void setUp() {
31         string config = data_path + "InlineKeyResolver.xml";
32         ifstream in(config.c_str());
33         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
34         XercesJanitor<DOMDocument> janitor(doc);
35         m_resolver=XMLToolingConfig::getConfig().KeyResolverManager.newPlugin(INLINE_KEY_RESOLVER,doc->getDocumentElement());
36     }
37
38     void tearDown() {
39         delete m_resolver;
40         m_resolver=NULL;
41     }
42
43     void testResolver() {
44         string path=data_path + "KeyInfo1.xml";
45         ifstream fs(path.c_str());
46         DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);
47         TS_ASSERT(doc!=NULL);
48         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
49         TS_ASSERT(b!=NULL);
50         auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
51         TS_ASSERT(kiObject.get()!=NULL);
52
53         auto_ptr<XSECCryptoKey> key(m_resolver->resolveKey(kiObject.get()));
54         TSM_ASSERT("Unable to resolve public key.", key.get()!=NULL);
55         TSM_ASSERT_EQUALS("Unexpected key type.", key->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);
56
57         auto_ptr<XSECCryptoX509CRL> crl(m_resolver->resolveCRL(kiObject.get()));
58         TSM_ASSERT("Unable to resolve CRL.", crl.get()!=NULL);
59
60         KeyResolver::ResolvedCertificates certs;
61         TSM_ASSERT_EQUALS("Wrong certificate count.", m_resolver->resolveCertificates(kiObject.get(), certs), 1);
62     }
63 };