Search in sources :

Example 66 with RepositoryFile

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());
}
Also used : RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 67 with RepositoryFile

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());
        }
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 68 with RepositoryFile

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();
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ArrayList(java.util.ArrayList) IRepositoryAccessVoterManager(org.pentaho.platform.api.repository2.unified.IRepositoryAccessVoterManager) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) AccessDeniedException(javax.jcr.AccessDeniedException) RepositoryException(javax.jcr.RepositoryException) ExpectedException(org.junit.rules.ExpectedException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 69 with RepositoryFile

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);
}
Also used : SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 70 with RepositoryFile

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);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) SpringSecurityCurrentUserProvider(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository.SpringSecurityCurrentUserProvider) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) Test(org.junit.Test)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32