View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.net.ssl;
15  
16  import java.util.Arrays;
17  
18  import org.junit.jupiter.api.BeforeEach;
19  import org.junit.jupiter.api.Test;
20  
21  import ch.qos.logback.core.ContextBase;
22  import ch.qos.logback.core.net.ssl.mock.MockSSLConfigurable;
23  
24  import static org.junit.jupiter.api.Assertions.assertTrue;
25  
26  /**
27   * Unit tests for {@link SSLParametersConfiguration}.
28   *
29   * @author Carl Harris
30   */
31  public class SSLParametersConfigurationTest {
32  
33      private MockSSLConfigurable configurable = new MockSSLConfigurable();
34  
35      private SSLParametersConfiguration configuration = new SSLParametersConfiguration();
36  
37      @BeforeEach
38      public void setUp() throws Exception {
39          configuration.setContext(new ContextBase());
40      }
41  
42      @Test
43      public void testSetIncludedProtocols() throws Exception {
44          configurable.setSupportedProtocols(new String[] { "A", "B", "C", "D" });
45          configuration.setIncludedProtocols("A,B ,C, D");
46          configuration.configure(configurable);
47          assertTrue(Arrays.equals(new String[] { "A", "B", "C", "D" }, configurable.getEnabledProtocols()));
48      }
49  
50      @Test
51      public void testSetExcludedProtocols() throws Exception {
52          configurable.setSupportedProtocols(new String[] { "A", "B" });
53          configuration.setExcludedProtocols("A");
54          configuration.configure(configurable);
55          assertTrue(Arrays.equals(new String[] { "B" }, configurable.getEnabledProtocols()));
56      }
57  
58      @Test
59      public void testSetIncludedAndExcludedProtocols() throws Exception {
60          configurable.setSupportedProtocols(new String[] { "A", "B", "C" });
61          configuration.setIncludedProtocols("A, B");
62          configuration.setExcludedProtocols("B");
63          configuration.configure(configurable);
64          assertTrue(Arrays.equals(new String[] { "A" }, configurable.getEnabledProtocols()));
65      }
66  
67      @Test
68      public void testSetIncludedCipherSuites() throws Exception {
69          configurable.setSupportedCipherSuites(new String[] { "A", "B", "C", "D" });
70          configuration.setIncludedCipherSuites("A,B ,C, D");
71          configuration.configure(configurable);
72          assertTrue(Arrays.equals(new String[] { "A", "B", "C", "D" }, configurable.getEnabledCipherSuites()));
73      }
74  
75      @Test
76      public void testSetExcludedCipherSuites() throws Exception {
77          configurable.setSupportedCipherSuites(new String[] { "A", "B" });
78          configuration.setExcludedCipherSuites("A");
79          configuration.configure(configurable);
80          assertTrue(Arrays.equals(new String[] { "B" }, configurable.getEnabledCipherSuites()));
81      }
82  
83      @Test
84      public void testSetExcludedAndIncludedCipherSuites() throws Exception {
85          configurable.setSupportedCipherSuites(new String[] { "A", "B", "C" });
86          configuration.setIncludedCipherSuites("A, B");
87          configuration.setExcludedCipherSuites("B");
88          configuration.configure(configurable);
89          assertTrue(Arrays.equals(new String[] { "A" }, configurable.getEnabledCipherSuites()));
90      }
91  
92      @Test
93      public void testSetNeedClientAuth() throws Exception {
94          configuration.setNeedClientAuth(true);
95          configuration.configure(configurable);
96          assertTrue(configurable.isNeedClientAuth());
97      }
98  
99      @Test
100     public void testSetWantClientAuth() throws Exception {
101         configuration.setWantClientAuth(true);
102         configuration.configure(configurable);
103         assertTrue(configurable.isWantClientAuth());
104     }
105 
106     @Test
107     public void testPassDefaultProtocols() throws Exception {
108         final String[] protocols = new String[] { "A" };
109         configurable.setDefaultProtocols(protocols);
110         configuration.configure(configurable);
111         assertTrue(Arrays.equals(protocols, configurable.getEnabledProtocols()));
112     }
113 
114     @Test
115     public void testPassDefaultCipherSuites() throws Exception {
116         final String[] cipherSuites = new String[] { "A" };
117         configurable.setDefaultCipherSuites(cipherSuites);
118         configuration.configure(configurable);
119         assertTrue(Arrays.equals(cipherSuites, configurable.getEnabledCipherSuites()));
120     }
121 
122     @Test
123     public void testPassDefaultNeedClientAuth() throws Exception {
124         configurable.setNeedClientAuth(true);
125         configuration.configure(configurable);
126         assertTrue(configurable.isNeedClientAuth());
127     }
128 
129     @Test
130     public void testPassDefaultWantClientAuth() throws Exception {
131         configurable.setWantClientAuth(true);
132         configuration.configure(configurable);
133         assertTrue(configurable.isWantClientAuth());
134     }
135 
136 }