1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.net.ssl;
15
16 import java.security.KeyStore;
17
18 import org.junit.jupiter.api.Test;
19
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21
22
23
24
25
26
27 public class KeyStoreFactoryBeanTest {
28
29 private KeyStoreFactoryBean factoryBean = new KeyStoreFactoryBean();
30
31 @Test
32 public void testDefaults() throws Exception {
33 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
34 assertNotNull(factoryBean.createKeyStore());
35 }
36
37 @Test
38 public void testExplicitProvider() throws Exception {
39 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
40 KeyStore keyStore = factoryBean.createKeyStore();
41 factoryBean.setProvider(keyStore.getProvider().getName());
42 assertNotNull(factoryBean.createKeyStore());
43 }
44
45 @Test
46 public void testExplicitType() throws Exception {
47 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
48 factoryBean.setType(SSL.DEFAULT_KEYSTORE_TYPE);
49 assertNotNull(factoryBean.createKeyStore());
50 }
51
52 @Test
53 public void testPKCS12Type() throws Exception {
54 factoryBean.setLocation(SSLTestConstants.KEYSTORE_PKCS12_RESOURCE);
55 factoryBean.setType(SSLTestConstants.PKCS12_TYPE);
56 assertNotNull(factoryBean.createKeyStore());
57 }
58
59 @Test
60 public void testExplicitPassphrase() throws Exception {
61 factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE);
62 factoryBean.setPassword(SSL.DEFAULT_KEYSTORE_PASSWORD);
63 assertNotNull(factoryBean.createKeyStore());
64 }
65
66 }