Search in sources :

Example 6 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifyRead.

/**
 * This method verifies the read permission.
 * @param user the user
 * @param path the path of the file to read
 * @param isFile whether the path is a file
 * @throws Exception if it fails to verify
 */
private void verifyRead(TestUser user, String path, boolean isFile) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        verifyGetFileId(user, path);
        verifyGetFileInfoOrList(user, path, isFile);
    }
}
Also used : AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable)

Example 7 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class FileSystemMasterTest method listStatusRecursivePermissions.

@Test
public void listStatusRecursivePermissions() throws Exception {
    final int files = 10;
    List<FileInfo> infos;
    List<String> filenames;
    // Test files in root directory.
    for (int i = 0; i < files; i++) {
        createFileWithSingleBlock(ROOT_URI.join("file" + String.format("%05d", i)));
    }
    // Test files in nested directory.
    for (int i = 0; i < files; i++) {
        createFileWithSingleBlock(NESTED_URI.join("file" + String.format("%05d", i)));
    }
    // Test with permissions
    mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0400).toProto()).setRecursive(true)));
    try (Closeable r = new AuthenticatedUserRule("test_user1", ServerConfiguration.global()).toResource()) {
        // Test recursive listStatus
        infos = mFileSystemMaster.listStatus(ROOT_URI, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.ALWAYS).setRecursive(true)));
        // 10 files in each directory, 1 level of directories
        assertEquals(files + 1, infos.size());
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Mode(alluxio.security.authorization.Mode) Closeable(java.io.Closeable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 8 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule 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 9 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class FileSystemMasterIntegrationTest method setModeOwnerNoWritePermission.

@Test
public void setModeOwnerNoWritePermission() throws Exception {
    AlluxioURI root = new AlluxioURI("/");
    mFsMaster.setAttribute(root, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
    try (AutoCloseable closeable = new AuthenticatedUserRule("foo", ServerConfiguration.global()).toResource()) {
        AlluxioURI alluxioFile = new AlluxioURI("/in_alluxio");
        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) 0407).toProto())));
        Assert.assertEquals(0407, mFsMaster.getFileInfo(file.getFileId()).getMode());
        mFsMaster.setAttribute(alluxioFile, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setMode(new Mode((short) 0777).toProto())));
        Assert.assertEquals(0777, mFsMaster.getFileInfo(file.getFileId()).getMode());
    }
}
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 10 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifyDelete.

private void verifyDelete(TestUser user, String path, boolean recursive) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        mFileSystemMaster.delete(new AlluxioURI(path), DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(recursive)));
        assertEquals(-1, mFileSystemMaster.getFileId(new AlluxioURI(path)));
    }
}
Also used : AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) AlluxioURI(alluxio.AlluxioURI)

Aggregations

AuthenticatedUserRule (alluxio.AuthenticatedUserRule)13 Closeable (java.io.Closeable)11 AlluxioURI (alluxio.AlluxioURI)10 FileInfo (alluxio.wire.FileInfo)9 Mode (alluxio.security.authorization.Mode)4 Test (org.junit.Test)4 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)2 UfsMode (alluxio.underfs.UfsMode)2 CreateDirectoryContext (alluxio.master.file.contexts.CreateDirectoryContext)1 CreateFileContext (alluxio.master.file.contexts.CreateFileContext)1 SetAttributeContext (alluxio.master.file.contexts.SetAttributeContext)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1