View Javadoc

1   /*
2    * $Id: TlsConfigurationTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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(""); // guaranteed to not exist
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