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);
}
}
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());
}
}
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);
}
}
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));
}
}
}
}
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();
}
}
Aggregations