Adjust cxxtest path in build rules.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / FilesystemCredentialResolverTest.h
1 /*
2  *  Copyright 2001-2010 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 <xmltooling/security/CredentialResolver.h>
20 #include <xmltooling/security/X509Credential.h>
21
22 #include <fstream>
23
24 class FilesystemCredentialResolverTest : public CxxTest::TestSuite {
25 public:
26     void setUp() {
27     }
28     
29     void tearDown() {
30     }
31
32     void testFilesystemProvider() {
33         string config = data_path + "FilesystemCredentialResolver.xml";
34         ifstream in(config.c_str());
35         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
36         XercesJanitor<DOMDocument> janitor(doc);
37
38         auto_ptr<CredentialResolver> credResolver(
39             XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(
40                 FILESYSTEM_CREDENTIAL_RESOLVER,doc->getDocumentElement()
41                 )
42             );
43
44         Locker locker(credResolver.get());
45         const X509Credential* cred=dynamic_cast<const X509Credential*>(credResolver->resolve());
46         TSM_ASSERT("Retrieved credential was null", cred!=nullptr);
47         TSM_ASSERT("Retrieved key was null", cred->getPrivateKey()!=nullptr);
48         TSM_ASSERT_EQUALS("Unexpected number of certificates", 1, cred->getEntityCertificateChain().size());
49         TSM_ASSERT_EQUALS("Custom key name not found", 1, cred->getKeyNames().count("Sample Key"));
50     }
51 };