### Question:
CsvDatasourceServiceImpl extends PentahoBase implements ICsvDatasourceService { public ModelInfo stageFile( String fileName, String delimiter, String enclosure, boolean isFirstRowHeader, String encoding ) throws Exception { checkPermissions(); ModelInfo modelInfo; fileName = FilenameUtils.getName( fileName ); try { int headerRows = isFirstRowHeader ? 1 : 0; modelInfo = new CsvUtils().generateFields( "", fileName, AgileHelper.getCsvSampleRowSize(), delimiter, enclosure, headerRows, true, true, encoding ); } catch ( FileNotFoundException e ) { logger.error( e ); throw new Exception( "File was not found: " + fileName ); } catch ( Exception e ) { logger.error( e ); throw e; } return modelInfo; } CsvDatasourceServiceImpl(); Log getLogger(); String getEncoding( String fileName ); ModelInfo stageFile( String fileName, String delimiter, String enclosure, boolean isFirstRowHeader,
                              String encoding ); FileInfo[] getStagedFiles(); FileTransformStats generateDomain( DatasourceDTO datasourceDto ); List<String> getPreviewRows( String filename, boolean isFirstRowHeader, int rows, String encoding ); @Override BogoPojo gwtWorkaround( BogoPojo pojo ); static final byte[] lock; }### Answer:
@Test( expected = Exception.class ) public void stageFile_InvalidPath_Csv_ThrowsException() throws Exception { service.stageFile( "../../../secret-file.csv", ",", "\n", false, "utf-8" ); }
@Test( expected = Exception.class ) public void stageFile_InvalidPath_Tmp_ThrowsException() throws Exception { service.stageFile( "../../../secret-file.tmp", ",", "\n", false, "utf-8" ); }
@Test( expected = Exception.class ) public void stageFile_InvalidPath_WindowsStyle_ThrowsException() throws Exception { service.stageFile( "..\\..\\..\\secret-file.csv", ",", "\n", false, "utf-8" ); }
@Test( expected = Exception.class ) public void stageFile_InvalidPath_SlashAtEnd_ThrowsException() throws Exception { service.stageFile( "../../../secret-file/", ",", "\n", false, "utf-8" ); }
@Test public void stageFile_InvalidPath_DoesNotRevealInternalDetails() throws Exception { try { service.stageFile( "../../../secret-file.tmp", ",", "\n", false, "utf-8" ); fail( "Should throw exception" ); } catch ( Exception e ) { String message = e.getMessage(); assertFalse( message, message.contains( TMP_DIR ) ); } }
@Test public void stageFile_CsvFile() throws Exception { String filename = "stageFile_CsvFile.csv"; File file = createTmpCsvFile( filename ); file.deleteOnExit(); try { ModelInfo modelInfo = service.stageFile( filename, ",", "\n", true, "utf-8" ); CsvFileInfo fileInfo = modelInfo.getFileInfo(); assertEquals( "One header row", 1, fileInfo.getHeaderRows() ); assertEquals( "Header + content row", 2, fileInfo.getContents().size() ); assertEquals( filename, fileInfo.getTmpFilename() ); } finally { file.delete(); } }