Search in sources :

Example 41 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class FileSystemMasterTest method deleteDirRecursiveWithInsufficientPermissions.

@Test
public void deleteDirRecursiveWithInsufficientPermissions() throws Exception {
    // userA has permissions to delete directory but not one of the nested files
    createFileWithSingleBlock(NESTED_FILE_URI);
    createFileWithSingleBlock(NESTED_FILE2_URI);
    mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
    mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0700).toProto())));
    mFileSystemMaster.setAttribute(NESTED_FILE2_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
    try (AuthenticatedClientUserResource userA = new AuthenticatedClientUserResource("userA", ServerConfiguration.global())) {
        mFileSystemMaster.delete(NESTED_URI, DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
        fail("Deleting a directory w/ insufficient permission on child should fail");
    } catch (AccessControlException e) {
        String expectedChildMessage = ExceptionMessage.PERMISSION_DENIED.getMessage("user=userA, access=-w-, path=" + NESTED_FILE_URI + ": failed at file");
        assertTrue(e.getMessage().startsWith(ExceptionMessage.DELETE_FAILED_DIR_CHILDREN.getMessage(NESTED_URI, expectedChildMessage)));
    }
    assertNotEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_URI));
    assertNotEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_FILE_URI));
    assertNotEquals(IdUtils.INVALID_FILE_ID, mFileSystemMaster.getFileId(NESTED_FILE2_URI));
}
Also used : AuthenticatedClientUserResource(alluxio.AuthenticatedClientUserResource) Mode(alluxio.security.authorization.Mode) AccessControlException(alluxio.exception.AccessControlException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 42 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method deleteFile.

@Test
public void deleteFile() throws IOException, AlluxioException {
    AlluxioURI fileUri = new AlluxioURI(FILE_PATH);
    try {
        mFileSystem.delete(fileUri);
        Assert.fail("deleteFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(fileUri, MOUNT_PATH)));
    }
    Assert.assertTrue(mFileSystem.exists(fileUri));
    Assert.assertNotNull(mFileSystem.getStatus(fileUri));
    fileUri = new AlluxioURI(SUB_FILE_PATH);
    try {
        mFileSystem.delete(fileUri);
        Assert.fail("deleteFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(fileUri, MOUNT_PATH)));
    }
    Assert.assertTrue(mFileSystem.exists(fileUri));
    Assert.assertNotNull(mFileSystem.getStatus(fileUri));
}
Also used : AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 43 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method chgrp.

@Test
public void chgrp() throws IOException, AlluxioException {
    AlluxioURI uri = new AlluxioURI(FILE_PATH + "_chgrp");
    try {
        mFileSystem.setAttribute(uri, SetAttributePOptions.newBuilder().setGroup("foo").build());
        Assert.fail("chgrp should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 44 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method createDirectory.

@Test
public void createDirectory() throws IOException, AlluxioException {
    AlluxioURI uri = new AlluxioURI(PathUtils.concatPath(MOUNT_PATH, "create"));
    try {
        mFileSystem.createDirectory(uri);
        Assert.fail("createDirectory should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
    uri = new AlluxioURI(PathUtils.concatPath(SUB_DIR_PATH, "create"));
    try {
        mFileSystem.createDirectory(uri);
        Assert.fail("createDirectory should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 45 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method createFile.

@Test
public void createFile() throws IOException, AlluxioException {
    CreateFilePOptions writeBoth = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).build();
    AlluxioURI uri = new AlluxioURI(FILE_PATH + "_create");
    try {
        mFileSystem.createFile(uri, writeBoth).close();
        Assert.fail("createFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
    uri = new AlluxioURI(SUB_FILE_PATH + "_create");
    try {
        mFileSystem.createFile(uri, writeBoth).close();
        Assert.fail("createFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

AccessControlException (alluxio.exception.AccessControlException)64 AlluxioURI (alluxio.AlluxioURI)29 LockedInodePath (alluxio.master.file.meta.LockedInodePath)21 Test (org.junit.Test)21 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)16 LockingScheme (alluxio.master.file.meta.LockingScheme)15 InvalidPathException (alluxio.exception.InvalidPathException)12 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Inode (alluxio.master.file.meta.Inode)9 MountTable (alluxio.master.file.meta.MountTable)7 FileInfo (alluxio.wire.FileInfo)7 AlluxioException (alluxio.exception.AlluxioException)4 LockedInodePathList (alluxio.master.file.meta.LockedInodePathList)4 Mode (alluxio.security.authorization.Mode)4 UnderFileSystem (alluxio.underfs.UnderFileSystem)4 FileBlockInfo (alluxio.wire.FileBlockInfo)4 DescendantType (alluxio.file.options.DescendantType)3 FileSystemMasterCommonPOptions (alluxio.grpc.FileSystemMasterCommonPOptions)3