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