mateczagany commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2792129777


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestSSLEndpointVerificationITCase.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.util.TestMessageHeaders;
+import org.apache.flink.runtime.rest.util.TestRestHandler;
+import org.apache.flink.runtime.rest.util.TestRestServerEndpoint;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.security.cert.CertificateException;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+
+/**
+ * This test validates that REST SSL endpoint verification works as expected 
and will fail the
+ * request if the endpoint certificate does not match the REST server hostname.
+ */
+public class RestSSLEndpointVerificationITCase {
+
+    private static final File KEY_STORE_FILE =
+            new File(
+                    RestSSLEndpointVerificationITCase.class
+                            .getResource("/local127.keystore")
+                            .getFile());
+    private static final File TRUST_STORE_FILE =
+            new File(
+                    RestSSLEndpointVerificationITCase.class
+                            .getResource("/local127.truststore")
+                            .getFile());
+
+    private static final TestMessageHeaders<
+                    EmptyRequestBody, EmptyResponseBody, 
EmptyMessageParameters>
+            TEST_MESSAGE_HEADERS =
+                    TestMessageHeaders.emptyBuilder()
+                            .setTargetRestEndpointURL("/test-handler")
+                            .build();
+
+    private final Configuration config;
+
+    public RestSSLEndpointVerificationITCase() {
+        config = new Configuration();
+        config.set(RestOptions.BIND_PORT, "0");
+        config.set(RestOptions.ADDRESS, "localhost");
+        config.set(SecurityOptions.SSL_REST_ENABLED, true);
+        config.set(SecurityOptions.SSL_REST_TRUSTSTORE, 
TRUST_STORE_FILE.getAbsolutePath());
+        config.set(SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, "password");
+        config.set(SecurityOptions.SSL_REST_KEYSTORE, 
KEY_STORE_FILE.getAbsolutePath());
+        config.set(SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, "password");
+        config.set(SecurityOptions.SSL_REST_KEY_PASSWORD, "password");
+        config.set(SecurityOptions.SSL_REST_VERIFY_HOSTNAME, true);
+    }
+
+    /**
+     * With hostname verification turned on, this should execute fine as 
"127.0.0.1" is part of the
+     * Subject Alternative Names.
+     */
+    @Test
+    void testConnectSuccess() throws Exception {

Review Comment:
   Thank you, I've added this for both methods.



-- 
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