use of org.apache.hadoop.fs.permission.AclStatus in project hadoop by apache.
the class FSAclBaseTest method testDefaultAclNewDirWithMode.
@Test
public void testDefaultAclNewDirWithMode() throws Exception {
FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short) 0755));
List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(DEFAULT, USER, "foo", ALL));
fs.setAcl(path, aclSpec);
Path dirPath = new Path(path, "dir1");
fs.mkdirs(dirPath, new FsPermission((short) 0740));
AclStatus s = fs.getAclStatus(dirPath);
AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
assertArrayEquals(new AclEntry[] { aclEntry(ACCESS, USER, "foo", ALL), aclEntry(ACCESS, GROUP, READ_EXECUTE), aclEntry(DEFAULT, USER, ALL), aclEntry(DEFAULT, USER, "foo", ALL), aclEntry(DEFAULT, GROUP, READ_EXECUTE), aclEntry(DEFAULT, MASK, ALL), aclEntry(DEFAULT, OTHER, READ_EXECUTE) }, returned);
assertPermission(dirPath, (short) 010740);
assertAclFeature(dirPath, true);
}
use of org.apache.hadoop.fs.permission.AclStatus in project hadoop by apache.
the class TestACLFeatures method getAclStatusAsExpected.
@Test
public void getAclStatusAsExpected() throws URISyntaxException, IOException {
getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getGetAclStatusJSONResponse()));
AclStatus aclStatus = getMockAdlFileSystem().getAclStatus(new Path("/test1/test2"));
Assert.assertEquals(aclStatus.getGroup(), "supergroup");
Assert.assertEquals(aclStatus.getOwner(), "hadoop");
Assert.assertEquals((Short) aclStatus.getPermission().toShort(), Short.valueOf("775", 8));
for (AclEntry entry : aclStatus.getEntries()) {
if (!(entry.toString().equalsIgnoreCase("user:carla:rw-") || entry.toString().equalsIgnoreCase("group::r-x"))) {
Assert.fail("Unexpected entry : " + entry.toString());
}
}
}
use of org.apache.hadoop.fs.permission.AclStatus in project hive by apache.
the class TestHdfsUtils method testSetFullFileStatusFailInheritAclsRecursive.
/**
* Tests that {@link HdfsUtils#setFullFileStatus(Configuration, HdfsUtils.HadoopFileStatus, FileSystem, Path, boolean)}
* does not thrown an exception when setting ACLs and with recursion.
*/
@Test
public void testSetFullFileStatusFailInheritAclsRecursive() throws Exception {
Configuration conf = new Configuration();
conf.set("dfs.namenode.acls.enabled", "true");
Path fakeTarget = new Path("fakePath");
HdfsUtils.HadoopFileStatus mockHadoopFileStatus = mock(HdfsUtils.HadoopFileStatus.class);
FileStatus mockSourceStatus = mock(FileStatus.class);
FsShell mockFsShell = mock(FsShell.class);
AclStatus mockAclStatus = mock(AclStatus.class);
when(mockSourceStatus.getPermission()).thenReturn(new FsPermission((short) 777));
when(mockAclStatus.toString()).thenReturn("");
when(mockHadoopFileStatus.getFileStatus()).thenReturn(mockSourceStatus);
when(mockHadoopFileStatus.getAclEntries()).thenReturn(new ArrayList<AclEntry>());
when(mockHadoopFileStatus.getAclStatus()).thenReturn(mockAclStatus);
doThrow(RuntimeException.class).when(mockFsShell).run(any(String[].class));
HdfsUtils.setFullFileStatus(conf, mockHadoopFileStatus, "", mock(FileSystem.class), fakeTarget, true, mockFsShell);
verify(mockFsShell).run(new String[] { "-setfacl", "-R", "--set", any(String.class), fakeTarget.toString() });
}
use of org.apache.hadoop.fs.permission.AclStatus in project hive by apache.
the class TestHadoopFileStatus method testHadoopFileStatusAclEntries.
/*
* HdfsUtils.setFullFileStatus(..) is called from multiple parallel threads. If AclEntries
* is modifiable the method will not be thread safe and could cause random concurrency issues
* This test case checks if the aclEntries returned from HadoopFileStatus is thread-safe or not
*/
@Test(expected = UnsupportedOperationException.class)
public void testHadoopFileStatusAclEntries() throws IOException {
FileSystem mockDfs = Mockito.mock(DistributedFileSystem.class);
Path mockPath = Mockito.mock(Path.class);
List<AclEntry> aclEntries = Lists.newArrayList();
aclEntries.add(newAclEntry(AclEntryScope.ACCESS, AclEntryType.USER, FsAction.ALL));
aclEntries.add(newAclEntry(AclEntryScope.ACCESS, AclEntryType.GROUP, FsAction.READ_EXECUTE));
aclEntries.add(newAclEntry(AclEntryScope.ACCESS, AclEntryType.OTHER, FsAction.NONE));
AclStatus aclStatus = new AclStatus.Builder().owner("dummyOwner").group("dummyGroup").stickyBit(true).addEntries(aclEntries).build();
FileStatus mockFileStatus = Mockito.mock(FileStatus.class);
Mockito.when(mockDfs.getAclStatus(mockPath)).thenReturn(aclStatus);
Mockito.when(mockDfs.getFileStatus(mockPath)).thenReturn(mockFileStatus);
sourceStatus = new HadoopFileStatus(hiveConf, mockDfs, mockPath);
Assert.assertNotNull(sourceStatus.getAclEntries());
Assert.assertTrue(sourceStatus.getAclEntries().size() == 3);
Iterables.removeIf(sourceStatus.getAclEntries(), new Predicate<AclEntry>() {
@Override
public boolean apply(AclEntry input) {
if (input.getName() == null) {
return true;
}
return false;
}
});
}
use of org.apache.hadoop.fs.permission.AclStatus in project hive by apache.
the class TestHdfsUtils method testSetFullFileStatusFailInheritAcls.
/**
* Tests that {@link HdfsUtils#setFullFileStatus(Configuration, HdfsUtils.HadoopFileStatus, FileSystem, Path, boolean)}
* does not thrown an exception when setting ACLs and without recursion.
*/
@Test
public void testSetFullFileStatusFailInheritAcls() throws IOException {
Configuration conf = new Configuration();
conf.set("dfs.namenode.acls.enabled", "true");
HdfsUtils.HadoopFileStatus mockHadoopFileStatus = mock(HdfsUtils.HadoopFileStatus.class);
FileStatus mockSourceStatus = mock(FileStatus.class);
AclStatus mockAclStatus = mock(AclStatus.class);
FileSystem mockFs = mock(FileSystem.class);
when(mockSourceStatus.getPermission()).thenReturn(new FsPermission((short) 777));
when(mockAclStatus.toString()).thenReturn("");
when(mockHadoopFileStatus.getFileStatus()).thenReturn(mockSourceStatus);
when(mockHadoopFileStatus.getAclEntries()).thenReturn(new ArrayList<AclEntry>());
when(mockHadoopFileStatus.getAclStatus()).thenReturn(mockAclStatus);
doThrow(RuntimeException.class).when(mockFs).setAcl(any(Path.class), any(List.class));
HdfsUtils.setFullFileStatus(conf, mockHadoopFileStatus, mockFs, new Path("fakePath"), false);
verify(mockFs).setAcl(any(Path.class), any(List.class));
}
Aggregations