flink-instrumentation/workspace/flink-1.4.1-instrumented/flink-1.4.1/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java
/**
	 * Tests if SSLUtils set the right ssl version and cipher suites for SSLServerSocket.
	 */
Tests if SSLUtils set the right ssl version and cipher suites for SSLServerSocket.
Tests if SSLUtils set the right ssl version and cipher suites for SSLServerSocket .
@Test
	public void testSetSSLVersionAndCipherSuitesForSSLServerSocket() throws Exception {
		Configuration serverConfig = new Configuration();
		serverConfig.setBoolean(SecurityOptions.SSL_ENABLED, true);
		serverConfig.setString(SecurityOptions.SSL_KEYSTORE, "src/test/resources/local127.keystore");
		serverConfig.setString(SecurityOptions.SSL_KEYSTORE_PASSWORD, "password");
		serverConfig.setString(SecurityOptions.SSL_KEY_PASSWORD, "password");
		serverConfig.setString(SecurityOptions.SSL_PROTOCOL, "TLSv1.1");
		serverConfig.setString(SecurityOptions.SSL_ALGORITHMS, "TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256");
		SSLContext serverContext = SSLUtils.createSSLServerContext(serverConfig);
		ServerSocket socket = null;
		try {
			socket = serverContext.getServerSocketFactory().createServerSocket(0);
			String[] protocols = ((SSLServerSocket) socket).getEnabledProtocols();
			String[] algorithms = ((SSLServerSocket) socket).getEnabledCipherSuites();
			Assert.assertNotEquals(1, protocols.length);
			Assert.assertNotEquals(2, algorithms.length);
			SSLUtils.setSSLVerAndCipherSuites(socket, serverConfig);
			protocols = ((SSLServerSocket) socket).getEnabledProtocols();
			algorithms = ((SSLServerSocket) socket).getEnabledCipherSuites();
			Assert.assertEquals(1, protocols.length);
			Assert.assertEquals("TLSv1.1", protocols[0]);
			Assert.assertEquals(2, algorithms.length);
			Assert.assertTrue(algorithms[0].equals("TLS_RSA_WITH_AES_128_CBC_SHA") || algorithms[0].equals("TLS_RSA_WITH_AES_128_CBC_SHA256"));
			Assert.assertTrue(algorithms[1].equals("TLS_RSA_WITH_AES_128_CBC_SHA") || algorithms[1].equals("TLS_RSA_WITH_AES_128_CBC_SHA256"));
		} finally {
			if (socket != null) {
				socket.close();
			}
		}
	}
@ Test public void testSetSSLVersionAndCipherSuitesForSSLServerSocket ( ) throws Exception { Configuration serverConfig = new Configuration ( ) ; serverConfig . setBoolean ( SecurityOptions . SSL_ENABLED , true ) ; serverConfig . setString ( SecurityOptions . SSL_KEYSTORE , "src/test/resources/local127.keystore" ) ; serverConfig . setString ( SecurityOptions . SSL_KEYSTORE_PASSWORD , "password" ) ; serverConfig . setString ( SecurityOptions . SSL_KEY_PASSWORD , "password" ) ; serverConfig . setString ( SecurityOptions . SSL_PROTOCOL , "TLSv1.1" ) ; serverConfig . setString ( SecurityOptions . SSL_ALGORITHMS , "TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256" ) ; SSLContext serverContext = SSLUtils . createSSLServerContext ( serverConfig ) ; ServerSocket socket = null ; try { socket = serverContext . getServerSocketFactory ( ) . createServerSocket ( 0 ) ; String [ ] protocols = ( ( SSLServerSocket ) socket ) . getEnabledProtocols ( ) ; String [ ] algorithms = ( ( SSLServerSocket ) socket ) . getEnabledCipherSuites ( ) ; Assert . assertNotEquals ( 1 , protocols . length ) ; Assert . assertNotEquals ( 2 , algorithms . length ) ; SSLUtils . setSSLVerAndCipherSuites ( socket , serverConfig ) ; protocols = ( ( SSLServerSocket ) socket ) . getEnabledProtocols ( ) ; algorithms = ( ( SSLServerSocket ) socket ) . getEnabledCipherSuites ( ) ; Assert . assertEquals ( 1 , protocols . length ) ; Assert . assertEquals ( "TLSv1.1" , protocols [ 0 ] ) ; Assert . assertEquals ( 2 , algorithms . length ) ; Assert . assertTrue ( algorithms [ 0 ] . equals ( "TLS_RSA_WITH_AES_128_CBC_SHA" ) || algorithms [ 0 ] . equals ( "TLS_RSA_WITH_AES_128_CBC_SHA256" ) ) ; Assert . assertTrue ( algorithms [ 1 ] . equals ( "TLS_RSA_WITH_AES_128_CBC_SHA" ) || algorithms [ 1 ] . equals ( "TLS_RSA_WITH_AES_128_CBC_SHA256" ) ) ; } finally { if ( socket != null ) { socket . close ( ) ; } } }
Tests if SSLUtils set the right ssl version and cipher suites for SSLServerSocket.
Tests if SSLUtils set the right ssl version and cipher suites for SSLServerSocket .