soumyakanti3578 commented on code in PR #6851:
URL: https://github.com/apache/hive/pull/6851#discussion_r4594157834
##########
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");
+
+ SymlinkTextInputFormat inputFormat = new SymlinkTextInputFormat();
+ FileInputFormat.setInputPaths(job, symlinkDir);
+
+ assertRejected(assertThrows(IOException.class, () ->
inputFormat.getSplits(job, 2)).getCause());
+ }
+
+ @Test
+ public void testReworkKeepsTargetNextToSymlinkFile() throws IOException {
Review Comment:
It tested that a target in the same directory as the symlink file was
allowed automatically. That implicit root is gone (see
https://github.com/apache/hive/pull/6851#discussion_r4348015115), so I will
remove the test.
--
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]