use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method loadMetadataInNestedDirectories.
/**
* Tests listing a directory in a nested directory load the UFS status of Inodes on the path.
*/
@Test
public void loadMetadataInNestedDirectories() throws Exception {
String ufs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String targetPath = Paths.get(ufs, "d1", "d2", "d3").toString();
FileUtils.createDir(targetPath);
FileUtils.changeLocalFilePermission(targetPath, new Mode((short) 0755).toString());
String parentPath = Paths.get(ufs, "d1").toString();
FileUtils.changeLocalFilePermission(parentPath, new Mode((short) 0700).toString());
AlluxioURI path = new AlluxioURI(Paths.get("/d1", "d2", "d3").toString());
mFsMaster.listStatus(path, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.ONCE)));
long fileId = mFsMaster.getFileId(new AlluxioURI("/d1"));
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals("d1", fileInfo.getName());
Assert.assertTrue(fileInfo.isFolder());
Assert.assertTrue(fileInfo.isPersisted());
Assert.assertEquals(0700, (short) fileInfo.getMode());
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method setModeNoOwner.
@Test
public void setModeNoOwner() throws Exception {
AlluxioURI root = new AlluxioURI("/");
mFsMaster.setAttribute(root, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
AlluxioURI alluxioFile = new AlluxioURI("/in_alluxio");
try (AutoCloseable closeable = new AuthenticatedUserRule("foo", ServerConfiguration.global()).toResource()) {
FileInfo file = mFsMaster.createFile(alluxioFile, CreateFileContext.defaults());
long opTimeMs = TEST_TIME_MS;
mFsMaster.completeFile(alluxioFile, CompleteFileContext.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(0)).setOperationTimeMs(opTimeMs));
mFsMaster.setAttribute(alluxioFile, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
Assert.assertEquals(0777, mFsMaster.getFileInfo(file.getFileId()).getMode());
}
mThrown.expect(AccessControlException.class);
try (AutoCloseable closeable = new AuthenticatedUserRule("bar", ServerConfiguration.global()).toResource()) {
mFsMaster.setAttribute(alluxioFile, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0677).toProto())));
}
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method createNestedDirectories.
/**
* Tests creating nested directories.
*/
@Test
public void createNestedDirectories() throws Exception {
String ufs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String parentPath = Paths.get(ufs, "d1").toString();
FileUtils.createDir(parentPath);
FileUtils.changeLocalFilePermission(parentPath, new Mode((short) 0755).toString());
AlluxioURI path = new AlluxioURI(Paths.get("/d1", "d2", "d3", "d4").toString());
String ufsPath = Paths.get(ufs, "d1", "d2", "d3", "d4").toString();
mFsMaster.createDirectory(path, CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true).setMode(new Mode((short) 0700).toProto())).setWriteType(WriteType.CACHE_THROUGH));
long fileId = mFsMaster.getFileId(path);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals("d4", fileInfo.getName());
Assert.assertTrue(fileInfo.isFolder());
Assert.assertTrue(fileInfo.isPersisted());
Assert.assertEquals(0700, (short) fileInfo.getMode());
Assert.assertTrue(FileUtils.exists(ufsPath));
Assert.assertEquals(0700, FileUtils.getLocalFileMode(ufsPath));
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method loadParentDirectoryTimestamps.
/**
* Tests loading ufs last modified time for parent directories.
*/
@Test
public void loadParentDirectoryTimestamps() throws Exception {
String parentName = "d1";
String childName = "d2";
String ufs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String parentUfsPath = Paths.get(ufs, parentName).toString();
FileUtils.createDir(parentUfsPath);
File file = new File(parentUfsPath);
long actualTime = file.lastModified();
Thread.sleep(100);
AlluxioURI parentPath = new AlluxioURI("/" + parentName);
AlluxioURI path = new AlluxioURI("/" + Paths.get(parentName, childName));
mFsMaster.createDirectory(path, CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true).setMode(new Mode((short) 0700).toProto())).setWriteType(WriteType.CACHE_THROUGH));
long fileId = mFsMaster.getFileId(path);
// calls getFileInfo on child to load metadata of parent
mFsMaster.getFileInfo(fileId);
long parentId = mFsMaster.getFileId(parentPath);
FileInfo parentInfo = mFsMaster.getFileInfo(parentId);
long alluxioTime = parentInfo.getLastModificationTimeMs();
Assert.assertEquals(parentName, parentInfo.getName());
Assert.assertTrue(parentInfo.isFolder());
Assert.assertTrue(parentInfo.isPersisted());
Assert.assertEquals(actualTime, alluxioTime);
Assert.assertTrue(FileUtils.exists(parentUfsPath));
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method createDirectoryInNestedDirectoriesWithoutExecutePermission.
/**
* Tests creating a directory in a nested directory without execute permission.
*/
@Test(expected = IOException.class)
public void createDirectoryInNestedDirectoriesWithoutExecutePermission() throws Exception {
// Assume the user is not root. This test doesn't work as root because root *is* allowed to
// create subdirectories even without execute permission on the parent directory.
assumeFalse(ShellUtils.execCommand("id", "-u").trim().equals("0"));
String ufs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
String parentPath = Paths.get(ufs, "d1").toString();
FileUtils.createDir(parentPath);
FileUtils.changeLocalFilePermission(parentPath, new Mode((short) 0600).toString());
AlluxioURI path = new AlluxioURI(Paths.get("/d1", "d2", "d3", "d4").toString());
// this should fail
mFsMaster.createDirectory(path, CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true).setMode(new Mode((short) 0755).toProto())).setWriteType(WriteType.CACHE_THROUGH));
}
Aggregations