Home | History | Annotate | Download | only in ssl
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      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 package libcore.javax.net.ssl;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 
     21 import java.util.Arrays;
     22 import javax.net.ssl.SSLServerSocket;
     23 import javax.net.ssl.SSLServerSocketFactory;
     24 import org.junit.Test;
     25 import org.junit.runner.RunWith;
     26 import org.junit.runners.JUnit4;
     27 
     28 @RunWith(JUnit4.class)
     29 public class SSLServerSocketTest extends AbstractSSLTest {
     30 
     31     @Test
     32     public void testDefaultConfiguration() throws Exception {
     33         SSLConfigurationAsserts.assertSSLServerSocketDefaultConfiguration(
     34                 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket());
     35     }
     36 
     37     @Test
     38     public void testSetEnabledCipherSuitesAffectsGetter() throws Exception {
     39         SSLServerSocket socket =
     40                 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket();
     41         String[] cipherSuites = new String[] {socket.getSupportedCipherSuites()[0]};
     42         socket.setEnabledCipherSuites(cipherSuites);
     43         assertEquals(Arrays.asList(cipherSuites), Arrays.asList(socket.getEnabledCipherSuites()));
     44     }
     45 
     46     @Test
     47     public void testSetEnabledCipherSuitesStoresCopy() throws Exception {
     48         SSLServerSocket socket =
     49                 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket();
     50         String[] array = new String[] {socket.getEnabledCipherSuites()[0]};
     51         String originalFirstElement = array[0];
     52         socket.setEnabledCipherSuites(array);
     53         array[0] = "Modified after having been set";
     54         assertEquals(originalFirstElement, socket.getEnabledCipherSuites()[0]);
     55     }
     56 
     57     @Test
     58     public void testSetEnabledProtocolsAffectsGetter() throws Exception {
     59         SSLServerSocket socket =
     60                 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket();
     61         String[] protocols = new String[] {socket.getSupportedProtocols()[0]};
     62         socket.setEnabledProtocols(protocols);
     63         assertEquals(Arrays.asList(protocols), Arrays.asList(socket.getEnabledProtocols()));
     64     }
     65 
     66     @Test
     67     public void testSetEnabledProtocolsStoresCopy() throws Exception {
     68         SSLServerSocket socket =
     69                 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket();
     70         String[] array = new String[] {socket.getEnabledProtocols()[0]};
     71         String originalFirstElement = array[0];
     72         socket.setEnabledProtocols(array);
     73         array[0] = "Modified after having been set";
     74         assertEquals(originalFirstElement, socket.getEnabledProtocols()[0]);
     75     }
     76 }
     77