@Test public void should_validate_file() throws Exception { assertThatThrownBy(() -> PropertiesUtils.fileFromTmpFolder("../test")) .isInstanceOf(VitamRuntimeException.class) .hasMessageContaining("invalid path"); assertThatCode(() -> PropertiesUtils.fileFromTmpFolder("./test")).doesNotThrowAnyException(); assertThatCode(() -> PropertiesUtils.fileFromTmpFolder("/test")).doesNotThrowAnyException(); assertThatCode(() -> PropertiesUtils.fileFromTmpFolder("test")).doesNotThrowAnyException(); }
public static File fileFromTmpFolder(String subpath) { try { String canonicalPath = new File(VitamConfiguration.getVitamTmpFolder()).getCanonicalPath(); File file = new File(VitamConfiguration.getVitamTmpFolder(), subpath); String fileCanonicalPath = file.getCanonicalPath(); if (!fileCanonicalPath.startsWith(canonicalPath)) { throw new VitamRuntimeException(String.format("invalid path with subpath: %s", subpath)); } return file; } catch (IOException e) { throw new VitamRuntimeException(e); } }
PropertiesUtils { public static File fileFromTmpFolder(String subpath) { try { String canonicalPath = new File(VitamConfiguration.getVitamTmpFolder()).getCanonicalPath(); File file = new File(VitamConfiguration.getVitamTmpFolder(), subpath); String fileCanonicalPath = file.getCanonicalPath(); if (!fileCanonicalPath.startsWith(canonicalPath)) { throw new VitamRuntimeException(String.format("invalid path with subpath: %s", subpath)); } return file; } catch (IOException e) { throw new VitamRuntimeException(e); } } }
PropertiesUtils { public static File fileFromTmpFolder(String subpath) { try { String canonicalPath = new File(VitamConfiguration.getVitamTmpFolder()).getCanonicalPath(); File file = new File(VitamConfiguration.getVitamTmpFolder(), subpath); String fileCanonicalPath = file.getCanonicalPath(); if (!fileCanonicalPath.startsWith(canonicalPath)) { throw new VitamRuntimeException(String.format("invalid path with subpath: %s", subpath)); } return file; } catch (IOException e) { throw new VitamRuntimeException(e); } } private  PropertiesUtils(); }
PropertiesUtils { public static File fileFromTmpFolder(String subpath) { try { String canonicalPath = new File(VitamConfiguration.getVitamTmpFolder()).getCanonicalPath(); File file = new File(VitamConfiguration.getVitamTmpFolder(), subpath); String fileCanonicalPath = file.getCanonicalPath(); if (!fileCanonicalPath.startsWith(canonicalPath)) { throw new VitamRuntimeException(String.format("invalid path with subpath: %s", subpath)); } return file; } catch (IOException e) { throw new VitamRuntimeException(e); } } private  PropertiesUtils(); static InputStream getConfigAsStream(String resourcesFile); static InputStream getResourceAsStream(String resourcesFile); static File getResourceFile(String resourcesFile); static Path getResourcePath(String resourcesFile); static Stream<String> getResourceListing(Class clazz, String path); static File findFile(String filename); static File fileFromConfigFolder(String subpath); static File fileFromDataFolder(String subpath); static File fileFromTmpFolder(String subpath); static Properties readProperties(File propertiesFile); static C readYaml(File yamlFile, Class<C> clasz); static C readYaml(File yamlFile, TypeReference<C> typeReference); static C readYaml(InputStream yamlInputStream, Class<C> clasz); static C readYaml(Path yamlPath, Class<C> clasz); static void writeYaml(File destination, Object config); static String getResourceAsString(String resourcesFile); }
PropertiesUtils { public static File fileFromTmpFolder(String subpath) { try { String canonicalPath = new File(VitamConfiguration.getVitamTmpFolder()).getCanonicalPath(); File file = new File(VitamConfiguration.getVitamTmpFolder(), subpath); String fileCanonicalPath = file.getCanonicalPath(); if (!fileCanonicalPath.startsWith(canonicalPath)) { throw new VitamRuntimeException(String.format("invalid path with subpath: %s", subpath)); } return file; } catch (IOException e) { throw new VitamRuntimeException(e); } } private  PropertiesUtils(); static InputStream getConfigAsStream(String resourcesFile); static InputStream getResourceAsStream(String resourcesFile); static File getResourceFile(String resourcesFile); static Path getResourcePath(String resourcesFile); static Stream<String> getResourceListing(Class clazz, String path); static File findFile(String filename); static File fileFromConfigFolder(String subpath); static File fileFromDataFolder(String subpath); static File fileFromTmpFolder(String subpath); static Properties readProperties(File propertiesFile); static C readYaml(File yamlFile, Class<C> clasz); static C readYaml(File yamlFile, TypeReference<C> typeReference); static C readYaml(InputStream yamlInputStream, Class<C> clasz); static C readYaml(Path yamlPath, Class<C> clasz); static void writeYaml(File destination, Object config); static String getResourceAsString(String resourcesFile);  }