soumyakanti3578 commented on code in PR #6851:
URL: https://github.com/apache/hive/pull/6851#discussion_r4594096944


##########
ql/src/test/org/apache/hadoop/hive/ql/io/TestSymlinkTextInputFormat.java:
##########
@@ -364,4 +372,185 @@ private void writeSymlinkFile(Path symlinkFile, 
Path...paths)
     }
     writer.close();
   }
+
+  @Test
+  public void testTargetOutsideOfAllowedPaths() throws IOException {
+    writeTextFile(new Path(dataDir1, "file1"), "dir1_file1_line1\n");
+    writeSymlinkFile(new Path(symlinkDir, "symlink_file"), new Path(dataDir1, 
"file1"));
+
+    SymlinkTextInputFormat inputFormat = new SymlinkTextInputFormat();
+    FileInputFormat.setInputPaths(job, symlinkDir);
+
+    assertRejected(
+        assertThrows(IOException.class, () -> inputFormat.getSplits(job, 
2)).getCause()
+    );
+    assertRejected(
+        assertThrows(IOException.class, () -> 
inputFormat.getContentSummary(symlinkDir, job)).getCause()
+    );
+  }
+
+  @Test
+  public void testTargetEscapingAllowedPath() throws IOException {
+    writeTextFile(new Path(dataDir2, "file2"), "dir2_file2_line1\n");
+    writeTextFile(new Path(symlinkDir, "symlink_file"), dataDir1 + 
"/../datadir2/file2\n");
+    job.set(ConfVars.HIVE_SYMLINK_ALLOWED_TARGET_PATHS.varname, 
dataDir1.toString());
+
+    SymlinkTextInputFormat inputFormat = new SymlinkTextInputFormat();
+    FileInputFormat.setInputPaths(job, symlinkDir);
+
+    assertRejected(assertThrows(IOException.class, () -> 
inputFormat.getSplits(job, 2)).getCause());
+  }
+
+  /** Rejected before any FileSystem is created for the unknown scheme. */
+  @Test
+  public void testTargetOnForeignFileSystem() throws IOException {
+    writeTextFile(new Path(symlinkDir, "symlink_file"), 
"unknownfs://custom:1234/abc\n");

Review Comment:
   If a filesystem lookup happened first, an unknown scheme would fail with "No 
FileSystem for scheme". The test expects "is outside of the allowed locations", 
so the check must run first.
   
   I will rename the test, the java doc, and add a comment in the body to 
explain it better.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to