Migrate to xmlsec 1.3 release, shrink a few headers.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / InlineKeyResolverTest.h
1 /*\r
2  *  Copyright 2001-2005 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include "XMLObjectBaseTestCase.h"\r
18 \r
19 #include <fstream>\r
20 #include <xmltooling/signature/KeyInfo.h>\r
21 #include <xmltooling/signature/KeyResolver.h>\r
22 \r
23 using namespace xmlsignature;\r
24 \r
25 class InlineKeyResolverTest : public CxxTest::TestSuite {\r
26     KeyResolver* m_resolver;\r
27 public:\r
28     InlineKeyResolverTest() : m_resolver(NULL) {}\r
29 \r
30     void setUp() {\r
31         string config = data_path + "InlineKeyResolver.xml";\r
32         ifstream in(config.c_str());\r
33         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
34         XercesJanitor<DOMDocument> janitor(doc);\r
35         m_resolver=XMLToolingConfig::getConfig().KeyResolverManager.newPlugin(INLINE_KEY_RESOLVER,doc->getDocumentElement());\r
36     }\r
37 \r
38     void tearDown() {\r
39         delete m_resolver;\r
40         m_resolver=NULL;\r
41     }\r
42 \r
43     void testResolver() {\r
44         string path=data_path + "KeyInfo1.xml";\r
45         ifstream fs(path.c_str());\r
46         DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);\r
47         TS_ASSERT(doc!=NULL);\r
48         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
49         TS_ASSERT(b!=NULL);\r
50         auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));\r
51         TS_ASSERT(kiObject.get()!=NULL);\r
52 \r
53         auto_ptr<XSECCryptoKey> key(m_resolver->resolveKey(kiObject.get()));\r
54         TSM_ASSERT("Unable to resolve public key.", key.get()!=NULL);\r
55         TSM_ASSERT_EQUALS("Unexpected key type.", key->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);\r
56 \r
57         auto_ptr<XSECCryptoX509CRL> crl(m_resolver->resolveCRL(kiObject.get()));\r
58         TSM_ASSERT("Unable to resolve CRL.", crl.get()!=NULL);\r
59 \r
60         KeyResolver::ResolvedCertificates certs;\r
61         TSM_ASSERT_EQUALS("Wrong certificate count.", m_resolver->resolveCertificates(kiObject.get(), certs), 1);\r
62     }\r
63 };\r