Search in sources :

Example 1 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method readDirInfoFail.

@Test
public void readDirInfoFail() throws Exception {
    String dir = createUnreadableFileOrDir(false);
    mThrown.expect(AccessControlException.class);
    mThrown.expectMessage(ExceptionMessage.PERMISSION_DENIED.getMessage(toExceptionMessage(TEST_USER_2.getUser(), Mode.Bits.READ, dir, "onlyReadByUser1")));
    try (Closeable r = new AuthenticatedUserRule(TEST_USER_2.getUser(), ServerConfiguration.global()).toResource()) {
        verifyGetFileInfoOrList(TEST_USER_2, dir, false);
    }
}
Also used : AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 2 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifyCreateDirectory.

private void verifyCreateDirectory(TestUser user, String path, boolean recursive) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        CreateDirectoryContext context = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(recursive)).setOwner(SecurityUtils.getOwnerFromGrpcClient(ServerConfiguration.global())).setGroup(SecurityUtils.getGroupFromGrpcClient(ServerConfiguration.global()));
        mFileSystemMaster.createDirectory(new AlluxioURI(path), context);
        FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(path)));
        String[] pathComponents = path.split("/");
        assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
        assertEquals(true, fileInfo.isFolder());
        assertEquals(user.getUser(), fileInfo.getOwner());
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) CreateDirectoryContext(alluxio.master.file.contexts.CreateDirectoryContext) Closeable(java.io.Closeable) AlluxioURI(alluxio.AlluxioURI)

Example 3 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifyGetFileId.

/**
 * This method verifies the get fileId.
 * @param user the user
 * @param path the path of the file to verify
 * @throws Exception if it fails to verify
 */
private void verifyGetFileId(TestUser user, String path) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        long fileId = mFileSystemMaster.getFileId(new AlluxioURI(path));
        assertNotEquals(-1, fileId);
    }
}
Also used : AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) AlluxioURI(alluxio.AlluxioURI)

Example 4 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifyGetFileInfoOrList.

private void verifyGetFileInfoOrList(TestUser user, String path, boolean isFile) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        if (isFile) {
            assertEquals(path, mFileSystemMaster.getFileInfo(new AlluxioURI(path), GetStatusContext.defaults()).getPath());
            assertEquals(1, mFileSystemMaster.listStatus(new AlluxioURI(path), ListStatusContext.defaults()).size());
        } else {
            List<FileInfo> fileInfoList = mFileSystemMaster.listStatus(new AlluxioURI(path), ListStatusContext.defaults());
            if (fileInfoList.size() > 0) {
                assertTrue(PathUtils.getParent(fileInfoList.get(0).getPath()).equals(path));
            }
        }
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Closeable(java.io.Closeable) AlluxioURI(alluxio.AlluxioURI)

Example 5 with AuthenticatedUserRule

use of alluxio.AuthenticatedUserRule in project alluxio by Alluxio.

the class PermissionCheckTest method verifySetState.

private SetAttributePOptions verifySetState(TestUser user, String path, SetAttributePOptions options) throws Exception {
    try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) {
        mFileSystemMaster.setAttribute(new AlluxioURI(path), SetAttributeContext.mergeFrom(options.toBuilder()));
        FileInfo fileInfo = mFileSystemMaster.getFileInfo(new AlluxioURI(path), GetStatusContext.defaults());
        return FileSystemOptions.setAttributeDefaults(ServerConfiguration.global()).toBuilder().setPinned(fileInfo.isPinned()).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(fileInfo.getTtl()).build()).setPersisted(fileInfo.isPersisted()).build();
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) 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