private static void doSnapshotContentsChangeAssertions( Path filePath, Path fileSnapshotPath, Path subdirPath, Path subdirSnapshotPath) throws Exception { AclEntry[] expected = new AclEntry[] {aclEntry(ACCESS, USER, "diana", ALL), aclEntry(ACCESS, GROUP, NONE)}; AclStatus s = hdfs.getAclStatus(filePath); AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010570, filePath); assertFilePermissionDenied(fsAsBruce, BRUCE, filePath); assertFilePermissionGranted(fsAsDiana, DIANA, filePath); s = hdfs.getAclStatus(subdirPath); returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010570, subdirPath); assertDirPermissionDenied(fsAsBruce, BRUCE, subdirPath); assertDirPermissionGranted(fsAsDiana, DIANA, subdirPath); expected = new AclEntry[] { aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE) }; s = hdfs.getAclStatus(fileSnapshotPath); returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010550, fileSnapshotPath); assertFilePermissionGranted(fsAsBruce, BRUCE, fileSnapshotPath); assertFilePermissionDenied(fsAsDiana, DIANA, fileSnapshotPath); s = hdfs.getAclStatus(subdirSnapshotPath); returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010550, subdirSnapshotPath); assertDirPermissionGranted(fsAsBruce, BRUCE, subdirSnapshotPath); assertDirPermissionDenied(fsAsDiana, DIANA, subdirSnapshotPath); }
@Test public void testOriginalAclEnforcedForSnapshotContentsAfterRemoval() throws Exception { Path filePath = new Path(path, "file1"); Path subdirPath = new Path(path, "subdir1"); Path fileSnapshotPath = new Path(snapshotPath, "file1"); Path subdirSnapshotPath = new Path(snapshotPath, "subdir1"); FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short) 0777)); FileSystem.create(hdfs, filePath, FsPermission.createImmutable((short) 0600)).close(); FileSystem.mkdirs(hdfs, subdirPath, FsPermission.createImmutable((short) 0700)); List<AclEntry> aclSpec = Lists.newArrayList( aclEntry(ACCESS, USER, READ_EXECUTE), aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE), aclEntry(ACCESS, OTHER, NONE)); hdfs.setAcl(filePath, aclSpec); hdfs.setAcl(subdirPath, aclSpec); assertFilePermissionGranted(fsAsBruce, BRUCE, filePath); assertFilePermissionDenied(fsAsDiana, DIANA, filePath); assertDirPermissionGranted(fsAsBruce, BRUCE, subdirPath); assertDirPermissionDenied(fsAsDiana, DIANA, subdirPath); SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName); // Both original and snapshot still have same ACL. AclEntry[] expected = new AclEntry[] { aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE) }; AclStatus s = hdfs.getAclStatus(filePath); AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010550, filePath); s = hdfs.getAclStatus(subdirPath); returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010550, subdirPath); s = hdfs.getAclStatus(fileSnapshotPath); returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010550, fileSnapshotPath); assertFilePermissionGranted(fsAsBruce, BRUCE, fileSnapshotPath); assertFilePermissionDenied(fsAsDiana, DIANA, fileSnapshotPath); s = hdfs.getAclStatus(subdirSnapshotPath); returned = s.getEntries().toArray(new AclEntry[0]); assertArrayEquals(expected, returned); assertPermission((short) 010550, subdirSnapshotPath); assertDirPermissionGranted(fsAsBruce, BRUCE, subdirSnapshotPath); assertDirPermissionDenied(fsAsDiana, DIANA, subdirSnapshotPath); hdfs.removeAcl(filePath); hdfs.removeAcl(subdirPath); // Original has changed, but snapshot still has old ACL. doSnapshotContentsRemovalAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath); restart(false); doSnapshotContentsRemovalAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath); restart(true); doSnapshotContentsRemovalAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath); }