|
25 | 25 | import java.util.Set; |
26 | 26 |
|
27 | 27 | import com.google.common.collect.ImmutableList; |
| 28 | +import org.apache.hadoop.hdfs.DistributedFileSystem; |
28 | 29 |
|
29 | 30 | import org.apache.hadoop.conf.Configuration; |
30 | 31 | import org.apache.hadoop.fs.FileStatus; |
|
35 | 36 | import org.apache.hadoop.hdfs.DFSConfigKeys; |
36 | 37 | import org.apache.hadoop.hdfs.HdfsConfiguration; |
37 | 38 | import org.apache.hadoop.hdfs.MiniDFSCluster; |
| 39 | +import org.apache.hadoop.hdfs.DFSTestUtil; |
38 | 40 | import org.apache.hadoop.security.AccessControlException; |
39 | 41 | import org.apache.hadoop.security.UserGroupInformation; |
40 | 42 | import org.junit.After; |
@@ -87,7 +89,8 @@ public void checkPermissionWithContext( |
87 | 89 | AuthorizationContext authzContext) throws AccessControlException { |
88 | 90 | if (authzContext.getAncestorIndex() > 1 |
89 | 91 | && authzContext.getInodes()[1].getLocalName().equals("user") |
90 | | - && authzContext.getInodes()[2].getLocalName().equals("acl")) { |
| 92 | + && authzContext.getInodes()[2].getLocalName().equals("acl") |
| 93 | + || runPermissionCheck) { |
91 | 94 | this.ace.checkPermissionWithContext(authzContext); |
92 | 95 | } |
93 | 96 | CALLED.add("checkPermission|" + authzContext.getAncestorAccess() |
@@ -485,4 +488,65 @@ public Void run() throws Exception { |
485 | 488 | } |
486 | 489 | }); |
487 | 490 | } |
| 491 | + |
| 492 | + @Test |
| 493 | + // See HDFS-16132 where an issue was reported after HDFS-15372. The sequence |
| 494 | + // of operations here causes that change to break and the test fails with: |
| 495 | + // org.apache.hadoop.ipc.RemoteException(java.lang.AssertionError): |
| 496 | + // Absolute path required, but got 'foo' |
| 497 | + // at org.apache.hadoop.hdfs.server.namenode.INode.checkAbsolutePath |
| 498 | + // (INode.java:838) |
| 499 | + // at org.apache.hadoop.hdfs.server.namenode.INode.getPathComponents |
| 500 | + // (INode.java:813) |
| 501 | + // After reverting HDFS-15372 the test passes, so including this test in the |
| 502 | + // revert for future reference. |
| 503 | + public void testAttrProviderWorksCorrectlyOnRenamedSnapshotPaths() |
| 504 | + throws Exception { |
| 505 | + runPermissionCheck = true; |
| 506 | + FileSystem fs = FileSystem.get(miniDFS.getConfiguration(0)); |
| 507 | + DistributedFileSystem hdfs = miniDFS.getFileSystem(); |
| 508 | + final Path parent = new Path("/user"); |
| 509 | + hdfs.mkdirs(parent); |
| 510 | + fs.setPermission(parent, new FsPermission(HDFS_PERMISSION)); |
| 511 | + final Path sub1 = new Path(parent, "sub1"); |
| 512 | + final Path sub1foo = new Path(sub1, "foo"); |
| 513 | + hdfs.mkdirs(sub1); |
| 514 | + hdfs.mkdirs(sub1foo); |
| 515 | + Path f = new Path(sub1foo, "file0"); |
| 516 | + DFSTestUtil.createFile(hdfs, f, 0, (short) 1, 0); |
| 517 | + hdfs.allowSnapshot(parent); |
| 518 | + hdfs.createSnapshot(parent, "s0"); |
| 519 | + |
| 520 | + f = new Path(sub1foo, "file1"); |
| 521 | + DFSTestUtil.createFile(hdfs, f, 0, (short) 1, 0); |
| 522 | + f = new Path(sub1foo, "file2"); |
| 523 | + DFSTestUtil.createFile(hdfs, f, 0, (short) 1, 0); |
| 524 | + |
| 525 | + final Path sub2 = new Path(parent, "sub2"); |
| 526 | + hdfs.mkdirs(sub2); |
| 527 | + final Path sub2foo = new Path(sub2, "foo"); |
| 528 | + // mv /parent/sub1/foo to /parent/sub2/foo |
| 529 | + hdfs.rename(sub1foo, sub2foo); |
| 530 | + |
| 531 | + hdfs.createSnapshot(parent, "s1"); |
| 532 | + hdfs.createSnapshot(parent, "s2"); |
| 533 | + |
| 534 | + final Path sub3 = new Path(parent, "sub3"); |
| 535 | + hdfs.mkdirs(sub3); |
| 536 | + // mv /parent/sub2/foo to /parent/sub3/foo |
| 537 | + hdfs.rename(sub2foo, sub3); |
| 538 | + |
| 539 | + hdfs.delete(sub3, true); |
| 540 | + UserGroupInformation ugi = |
| 541 | + UserGroupInformation.createUserForTesting("u1", new String[] {"g1"}); |
| 542 | + ugi.doAs(new PrivilegedExceptionAction<Void>() { |
| 543 | + @Override |
| 544 | + public Void run() throws Exception { |
| 545 | + FileSystem fs = FileSystem.get(miniDFS.getConfiguration(0)); |
| 546 | + ((DistributedFileSystem)fs).getSnapshotDiffReport(parent, "s1", "s2"); |
| 547 | + CALLED.clear(); |
| 548 | + return null; |
| 549 | + } |
| 550 | + }); |
| 551 | + } |
488 | 552 | } |
0 commit comments