Search in sources :

Example 61 with Mode

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());
}
Also used : FileInfo(alluxio.wire.FileInfo) Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 62 with Mode

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())));
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 63 with Mode

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));
}
Also used : FileInfo(alluxio.wire.FileInfo) Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 64 with Mode

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));
}
Also used : FileInfo(alluxio.wire.FileInfo) Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 65 with Mode

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));
}
Also used : Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

Mode (alluxio.security.authorization.Mode)78 Test (org.junit.Test)47 AlluxioURI (alluxio.AlluxioURI)43 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)15 UnderFileSystem (alluxio.underfs.UnderFileSystem)14 Random (java.util.Random)14 IOException (java.io.IOException)11 UfsMode (alluxio.underfs.UfsMode)9 URIStatus (alluxio.client.file.URIStatus)8 FileInfo (alluxio.wire.FileInfo)8 ArrayList (java.util.ArrayList)8 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)7 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 WriteType (alluxio.client.WriteType)5 AlluxioException (alluxio.exception.AlluxioException)5 LockedInodePath (alluxio.master.file.meta.LockedInodePath)5 AclEntry (alluxio.security.authorization.AclEntry)5 AuthenticatedClientUserResource (alluxio.AuthenticatedClientUserResource)4 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)4