Github user StephanEwen commented on a diff in the pull request: https://github.com/apache/flink/pull/3486#discussion_r105910791 --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java --- @@ -125,4 +129,99 @@ public void testCreateSSLServerContextMisconfiguration() { } } + /** + * Tests if SSL Server Context creation fails with bad SSL configuration + */ + @Test + public void testCreateSSLServerContextWithMultiProtocols() { + + Configuration serverConfig = new Configuration(); + serverConfig.setBoolean(ConfigConstants.SECURITY_SSL_ENABLED, true); + serverConfig.setString(ConfigConstants.SECURITY_SSL_KEYSTORE, "src/test/resources/local127.keystore"); + serverConfig.setString(ConfigConstants.SECURITY_SSL_KEYSTORE_PASSWORD, "password"); + serverConfig.setString(ConfigConstants.SECURITY_SSL_KEY_PASSWORD, "password"); + serverConfig.setString(ConfigConstants.SECURITY_SSL_PROTOCOL, "TLSv1,TLSv1.2"); + + try { + SSLContext serverContext = SSLUtils.createSSLServerContext(serverConfig); + Assert.fail("SSL server context created even with multiple protocols set "); + } catch (Exception e) { + // Exception here is valid + } + } + + /** + * 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(ConfigConstants.SECURITY_SSL_ENABLED, true); + serverConfig.setString(ConfigConstants.SECURITY_SSL_KEYSTORE, "src/test/resources/local127.keystore"); + serverConfig.setString(ConfigConstants.SECURITY_SSL_KEYSTORE_PASSWORD, "password"); + serverConfig.setString(ConfigConstants.SECURITY_SSL_KEY_PASSWORD, "password"); + serverConfig.setString(ConfigConstants.SECURITY_SSL_PROTOCOL, "TLSv1.1"); + serverConfig.setString(ConfigConstants.SECURITY_SSL_ALGORITHMS, "TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256"); + + int port = new Random().nextInt(65535); + SSLContext serverContext = SSLUtils.createSSLServerContext(serverConfig); + ServerSocket socket = null; + try { + socket = serverContext.getServerSocketFactory().createServerSocket(port); + + String[] protocols = ((SSLServerSocket) socket).getEnabledProtocols(); + String[] algorithms = ((SSLServerSocket) socket).getEnabledCipherSuites(); + Assert.assertTrue(protocols.length > 1); + Assert.assertTrue(algorithms.length > 2); + + SSLUtils.setSSLVerAndCipherSuites(socket, serverConfig); + protocols = ((SSLServerSocket) socket).getEnabledProtocols(); + algorithms = ((SSLServerSocket) socket).getEnabledCipherSuites(); + Assert.assertTrue(protocols.length == 1); --- End diff -- Using `assertEquals` often helps in failing tests, because it prints expected and actual values. `assertTrue` gives no good error message (other than that the condition was violated).
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---