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 17package libcore.javax.net.ssl; 18 19import javax.net.ssl.SSLServerSocket; 20import javax.net.ssl.SSLServerSocketFactory; 21import junit.framework.TestCase; 22import java.util.Arrays; 23 24public class SSLServerSocketTest extends TestCase { 25 26 public void testDefaultConfiguration() throws Exception { 27 SSLConfigurationAsserts.assertSSLServerSocketDefaultConfiguration( 28 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket()); 29 } 30 31 public void testSetEnabledCipherSuitesAffectsGetter() throws Exception { 32 SSLServerSocket socket = 33 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(); 34 String[] cipherSuites = new String[] {socket.getSupportedCipherSuites()[0]}; 35 socket.setEnabledCipherSuites(cipherSuites); 36 assertEquals(Arrays.asList(cipherSuites), Arrays.asList(socket.getEnabledCipherSuites())); 37 } 38 39 public void testSetEnabledCipherSuitesStoresCopy() throws Exception { 40 SSLServerSocket socket = 41 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(); 42 String[] array = new String[] {socket.getEnabledCipherSuites()[0]}; 43 String originalFirstElement = array[0]; 44 socket.setEnabledCipherSuites(array); 45 array[0] = "Modified after having been set"; 46 assertEquals(originalFirstElement, socket.getEnabledCipherSuites()[0]); 47 } 48 49 public void testSetEnabledProtocolsAffectsGetter() throws Exception { 50 SSLServerSocket socket = 51 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(); 52 String[] protocols = new String[] {socket.getSupportedProtocols()[0]}; 53 socket.setEnabledProtocols(protocols); 54 assertEquals(Arrays.asList(protocols), Arrays.asList(socket.getEnabledProtocols())); 55 } 56 57 public void testSetEnabledProtocolsStoresCopy() throws Exception { 58 SSLServerSocket socket = 59 (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(); 60 String[] array = new String[] {socket.getEnabledProtocols()[0]}; 61 String originalFirstElement = array[0]; 62 socket.setEnabledProtocols(array); 63 array[0] = "Modified after having been set"; 64 assertEquals(originalFirstElement, socket.getEnabledProtocols()[0]); 65 } 66} 67