SystemUtils { public static boolean canUpload( String uploadDir ) { IAuthorizationPolicy policy = PentahoSystem.get( IAuthorizationPolicy.class ); boolean isAdmin = policy.isAllowed( RepositoryReadAction.NAME ) && policy.isAllowed( RepositoryCreateAction.NAME ) && ( policy.isAllowed( AdministerSecurityAction.NAME ) || policy.isAllowed( PublishAction.NAME ) ); if ( !isAdmin && !StringUtils.isEmpty( uploadDir ) ) { return validateAccessToHomeFolder( uploadDir ); } return isAdmin; }  static boolean canAdminister(); static boolean canUpload( String uploadDir ); static boolean canDownload( String downloadDir ); static boolean validateAccessToHomeFolder( String dir );  }
@Test public void testCanUpload() { IAuthorizationPolicy mockAuthPolicy = mock( IAuthorizationPolicy.class ); PentahoSystem.registerObject( mockAuthPolicy ); doReturn( true ).when( mockAuthPolicy ).isAllowed( RepositoryReadAction.NAME ); doReturn( true ).when( mockAuthPolicy ).isAllowed( RepositoryCreateAction.NAME ); doReturn( false ).when( mockAuthPolicy ).isAllowed( AdministerSecurityAction.NAME ); doReturn( false ).when( mockAuthPolicy ).isAllowed( PublishAction.NAME ); assertFalse( SystemUtils.canUpload( "" ) ); doReturn( true ).when( mockAuthPolicy ).isAllowed( AdministerSecurityAction.NAME ); assertTrue( SystemUtils.canUpload( "/mock/path" ) ); doReturn( false ).when( mockAuthPolicy ).isAllowed( AdministerSecurityAction.NAME ); doReturn( true ).when( mockAuthPolicy ).isAllowed( PublishAction.NAME ); assertFalse( SystemUtils.canDownload( "/mock/path" ) ); assertTrue( SystemUtils.canDownload( IMPORT_DIR ) ); doReturn( false ).when( mockAuthPolicy ).isAllowed( RepositoryReadAction.NAME ); assertFalse( SystemUtils.canDownload( IMPORT_DIR ) ); doReturn( true ).when( mockAuthPolicy ).isAllowed( RepositoryReadAction.NAME ); doReturn( false ).when( mockAuthPolicy ).isAllowed( RepositoryCreateAction.NAME ); assertFalse( SystemUtils.canDownload( IMPORT_DIR ) ); }