use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class InheritDefaultAclHandlerTest method testCreateDefaultAcl.
@Test
public void testCreateDefaultAcl() {
RepositoryFileAcl repositoryFileAcl = inheritDefaultAclHandler.createDefaultAcl(repositoryFile);
assertTrue(repositoryFileAcl.isEntriesInheriting());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class JcrRepositoryFileDaoTest method shouldConsultAccessVoterWhenCopyingOrMovingFiles.
@Test
public void shouldConsultAccessVoterWhenCopyingOrMovingFiles() {
RepositoryFile filePermitted = mock(RepositoryFile.class);
RepositoryFile fileNotPermitted = mock(RepositoryFile.class);
RepositoryFile destinationPermitted = mock(RepositoryFile.class);
RepositoryFile destinationNotPermitted = mock(RepositoryFile.class);
doReturn(filePermitted).when(dao).getFileById("/filePermitted");
doReturn(fileNotPermitted).when(dao).getFileById("/fileNotPermitted");
doReturn(destinationPermitted).when(dao).getFile("/destinationPermitted");
doReturn(destinationNotPermitted).when(dao).getFile("/destinationNotPermitted");
doReturn(true).when(accessVoterManager).hasAccess(filePermitted, RepositoryFilePermission.WRITE, null, pentahoSession);
doReturn(false).when(accessVoterManager).hasAccess(fileNotPermitted, RepositoryFilePermission.WRITE, null, pentahoSession);
doReturn(true).when(accessVoterManager).hasAccess(destinationPermitted, RepositoryFilePermission.WRITE, null, pentahoSession);
doReturn(false).when(accessVoterManager).hasAccess(destinationNotPermitted, RepositoryFilePermission.WRITE, null, pentahoSession);
// and write permissions to the destination folder.
try {
dao.moveFile("/filePermitted", "/destinationPermitted", null);
} catch (Throwable e) {
fail(e.getMessage());
}
// but does not have write permissions to the source file.
try {
dao.moveFile("/fileNotPermitted", "/destinationPermitted", null);
} catch (Throwable e) {
// unwrap original exception and check it
if (!(e instanceof RuntimeException) || !(e.getCause() instanceof AccessDeniedException)) {
fail(e.getMessage());
}
}
// but does not have write permissions to the destination folder.
try {
dao.moveFile("/filePermitted", "/destinationNotPermitted", null);
} catch (Throwable e) {
// unwrap original exception and check it
if (!(e instanceof RuntimeException) || !(e.getCause() instanceof AccessDeniedException)) {
fail(e.getMessage());
}
}
// nor has write permissions to the destination folder.
try {
dao.moveFile("/fileNotPermitted", "/destinationNotPermitted", null);
} catch (Throwable e) {
// unwrap original exception and check it
if (!(e instanceof RuntimeException) || !(e.getCause() instanceof AccessDeniedException)) {
fail(e.getMessage());
}
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class JcrRepositoryFileUtilsTest method testCheckNodeForTree.
@Test
public void testCheckNodeForTree() throws Exception {
List<RepositoryFileTree> children = new ArrayList<>();
IPathConversionHelper pathConversionHelper = new DefaultPathConversionHelper();
ILockHelper lockHelperMock = mock(ILockHelper.class);
IRepositoryAccessVoterManager repositoryAccessVoterManagerMock = mock(IRepositoryAccessVoterManager.class);
MutableBoolean foundFiltered = new MutableBoolean();
RepositoryFile fileMock = mock(RepositoryFile.class);
when(fileMock.getId()).thenReturn(1);
PowerMockito.mockStatic(JcrRepositoryFileUtils.class);
PowerMockito.mockStatic(JcrRepositoryFileAclUtils.class);
PowerMockito.doCallRealMethod().when(JcrRepositoryFileUtils.class, "checkNodeForTree", nodeMock, children, sessionMock, pJcrConstMock, pathConversionHelper, "childNodeFilter", lockHelperMock, 0, false, repositoryAccessVoterManagerMock, RepositoryRequest.FILES_TYPE_FILTER.FOLDERS, foundFiltered, true, false, "/");
when(JcrRepositoryFileUtils.nodeToFile(sessionMock, pJcrConstMock, pathConversionHelper, lockHelperMock, nodeMock)).thenReturn(fileMock);
when(JcrRepositoryFileUtils.isSupportedNodeType(pJcrConstMock, nodeMock)).thenReturn(true);
when(JcrRepositoryFileAclUtils.getAcl(sessionMock, pJcrConstMock, 1)).thenThrow(new AccessDeniedException());
try {
JcrRepositoryFileUtils.checkNodeForTree(nodeMock, children, sessionMock, pJcrConstMock, pathConversionHelper, "childNodeFilter", lockHelperMock, 0, false, repositoryAccessVoterManagerMock, RepositoryRequest.FILES_TYPE_FILTER.FOLDERS, foundFiltered, true, false, "/");
} catch (Exception e) {
fail();
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryBase method createSampleFile.
protected RepositoryFile createSampleFile(final String parentFolderPath, final String fileName, final String sampleString, final boolean sampleBoolean, final int sampleInteger, boolean versioned) throws Exception {
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
final SampleRepositoryFileData content = new SampleRepositoryFileData(sampleString, sampleBoolean, sampleInteger);
return repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName).versioned(versioned).build(), content, null);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class RepositoryUtilsTest method testGetFolder.
@Test
public void testGetFolder() throws Exception {
final MockUnifiedRepository repository = new MockUnifiedRepository(new SpringSecurityCurrentUserProvider());
final RepositoryUtils repositoryUtils = new RepositoryUtils(repository);
RepositoryFile test = repositoryUtils.getFolder("/public/one/two/three", true, true, null);
assertNotNull(test);
assertEquals("The folder name is invalid", "three", test.getName());
assertEquals("The path is invalid", "/public/one/two/three", test.getPath());
assertTrue("The folder should be defined as a folder", test.isFolder());
// Make sure it created the parents
RepositoryFile one = repositoryUtils.getFolder("/public/one", false, false, null);
assertNotNull(one);
RepositoryFile two = repositoryUtils.getFolder("/public/one/two", false, false, null);
assertNotNull(two);
}
Aggregations