gaborgsomogyi commented on code in PR #30199:
URL: https://github.com/apache/flink/pull/30199#discussion_r4772722053


##########
flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java:
##########
@@ -246,6 +252,101 @@ void testRESTServerSSLBadKeystoreType(String sslProvider) 
{
                 .isInstanceOf(KeyStoreException.class);
     }
 
+    // ------------------- REST server mutual authentication 
---------------------
+
+    /**
+     * Tests that REST mutual authentication without a truststore fails 
instead of being skipped.
+     */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTServerSSLMutualAuthWithoutTrustStore(String sslProvider) {
+        Configuration serverConfig = 
createRestSslConfigWithKeyStore(sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+
+        assertThatThrownBy(() -> 
SSLUtils.createRestServerSSLEngineFactory(serverConfig))
+                .isInstanceOf(IllegalConfigurationException.class)
+                .hasMessage(
+                        "Mutual authentication is enabled for the REST 
endpoints "
+                                + "(security.ssl.rest.authentication-enabled), 
but no truststore is "
+                                + "configured to verify the client 
certificates. The config option "
+                                + "security.ssl.rest.truststore or 
security.ssl.truststore is missing.");
+    }
+
+    /** Tests that a REST server with mutual authentication requires a client 
certificate. */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTServerSSLMutualAuthEnforcesClientCertificate(String 
sslProvider) throws Exception {
+        Configuration serverConfig = 
createRestSslConfigWithKeyAndTrustStores(sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+
+        assertRESTMutualAuthEnforced(serverConfig, sslProvider);
+    }
+
+    /** Tests that the generic truststore options are accepted for REST mutual 
authentication. */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTServerSSLMutualAuthWithGenericTrustStore(String sslProvider) 
throws Exception {
+        Configuration serverConfig = 
createRestSslConfigWithKeyStore(sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+        serverConfig.set(SecurityOptions.SSL_TRUSTSTORE, TRUST_STORE_PATH);
+        serverConfig.set(SecurityOptions.SSL_TRUSTSTORE_PASSWORD, 
TRUST_STORE_PASSWORD);
+
+        assertRESTMutualAuthEnforced(serverConfig, sslProvider);
+    }
+
+    /**
+     * Tests that only the REST server needs a truststore for mutual 
authentication: a REST client
+     * without one is created and verifies the server against the default 
truststore of the JDK.
+     */
+    @ParameterizedTest
+    @MethodSource("parameters")
+    void testRESTClientSSLMutualAuthWithoutTrustStore(String sslProvider) 
throws Exception {
+        Configuration serverConfig =
+                
withTlsCiphers(createRestSslConfigWithKeyAndTrustStores(sslProvider), 
sslProvider);
+        serverConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+        Configuration clientConfig = 
createRestSslConfigWithKeyStore(sslProvider);
+        clientConfig.set(SecurityOptions.SSL_REST_AUTHENTICATION_ENABLED, 
true);
+
+        SSLHandlerFactory server = 
SSLUtils.createRestServerSSLEngineFactory(serverConfig);
+        SSLHandlerFactory client = 
SSLUtils.createRestClientSSLEngineFactory(clientConfig);
+
+        // the default truststore of the JDK does not contain the self-signed 
test certificate
+        assertThatThrownBy(() -> negotiate(server, client))

Review Comment:
   Changed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to