test: prove IconService safely sanitizes SVG filenames (#2776)

This commit is contained in:
James Ward
2026-09-27 05:18:01 -04:00
committed by GitHub
parent b5a9ed5e67
commit 39eb515683
@@ -4,6 +4,8 @@ import org.booklore.config.AppProperties;
import org.booklore.exception.APIException;
import org.booklore.model.dto.request.SvgIconCreateRequest;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.data.domain.Page;
import java.io.IOException;
@@ -74,6 +76,23 @@ class IconServiceTest {
assertEquals(SVG_DATA, iconService.getSvgIcon(SVG_NAME));
}
@ParameterizedTest
@CsvSource(delimiter = ':', value = {
"foo/bar.svg:foo_bar.svg",
"../../etc/passwd:.._.._etc_passwd.svg",
"..:...svg",
".:..svg",
"..\0example:.._example.svg"
})
void saveSvgIcon_sanitizesFilename(String input, String expected) throws IOException {
SvgIconCreateRequest req = new SvgIconCreateRequest();
req.setSvgName(input);
req.setSvgData(SVG_DATA);
iconService.saveSvgIcon(req);
Path filePath = iconsSvgPath.resolve(expected);
assertTrue(Files.exists(filePath));
}
@Test
void saveSvgIcon_validXmlSvg_savesFileAndCaches() {
SvgIconCreateRequest req = new SvgIconCreateRequest();