1
2
3
4
5
6
7
8
9
10
11 package org.mule.api;
12
13 import org.mule.api.security.tls.TlsConfiguration;
14 import org.mule.tck.AbstractMuleTestCase;
15
16 import javax.net.ssl.SSLSocketFactory;
17
18 public class TlsConfigurationTestCase extends AbstractMuleTestCase
19 {
20
21 public void testEmptyConfiguration() throws Exception
22 {
23 TlsConfiguration configuration = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
24 try
25 {
26 configuration.initialise(false, TlsConfiguration.JSSE_NAMESPACE);
27 fail("no key password");
28 }
29 catch (IllegalArgumentException e)
30 {
31 assertNotNull("expected", e);
32 }
33 configuration.setKeyPassword("mulepassword");
34 try
35 {
36 configuration.initialise(false, TlsConfiguration.JSSE_NAMESPACE);
37 fail("no store password");
38 }
39 catch (IllegalArgumentException e)
40 {
41 assertNotNull("expected", e);
42 }
43 configuration.setKeyStorePassword("mulepassword");
44 configuration.setKeyStore("");
45 try
46 {
47 configuration.initialise(false, TlsConfiguration.JSSE_NAMESPACE);
48 fail("no keystore");
49 }
50 catch (Exception e)
51 {
52 assertNotNull("expected", e);
53 }
54 }
55
56 public void testSimpleSocket() throws Exception
57 {
58 TlsConfiguration configuration = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
59 configuration.setKeyPassword("mulepassword");
60 configuration.setKeyStorePassword("mulepassword");
61 configuration.setKeyStore("clientKeystore");
62 configuration.initialise(false, TlsConfiguration.JSSE_NAMESPACE);
63 SSLSocketFactory socketFactory = configuration.getSocketFactory();
64 assertTrue("socket is useless", socketFactory.getSupportedCipherSuites().length > 0);
65 }
66
67 }
68
69