snuyanzin commented on code in PR #30192:
URL: https://github.com/apache/flink/pull/30192#discussion_r4733632140


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/LogAndProfilingFileNamePathParameterTest.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.messages;
+
+import org.junit.jupiter.api.Named;
+import org.junit.jupiter.params.Parameter;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Tests for {@link LogFileNamePathParameter} and {@link 
ProfilingFileNamePathParameter}. The REST
+ * handlers strip any path from the file name, so the path parameter just 
needs to verify that the
+ * name represents a valid filename in a directory.
+ */
+@ParameterizedClass(name = "{0}")
+@MethodSource("parameters")
+class LogAndProfilingFileNamePathParameterTest {
+
+    private static Stream<Named<MessagePathParameter<String>>> parameters() {
+        return Stream.of(
+                Named.of("LogFileNamePathParameter", new 
LogFileNamePathParameter()),
+                Named.of("ProfilingFileNamePathParameter", new 
ProfilingFileNamePathParameter()));
+    }
+
+    @Parameter private MessagePathParameter<String> parameter;
+
+    @ParameterizedTest(name = "fileName={0}")
+    @ValueSource(strings = {"test.log", "dir/test.log", "../test.log", 
"dir/../../test.log"})
+    void testFileNameIsAccepted(final String fileName) throws Exception {
+        assertThat(parameter.convertFromString(fileName)).isEqualTo(fileName);
+    }
+
+    @ParameterizedTest(name = "fileName={0}")
+    @ValueSource(strings = {"", ".", "..", "/", "dir/..", "dir/.", "../.."})
+    void testFileNameThatDoesNotNameAFileIsRejected(final String fileName) {
+        assertThatThrownBy(() -> parameter.convertFromString(fileName))
+                .isInstanceOf(ConversionException.class);

Review Comment:
   we should assert msg content as well



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