From a929dc7164a5acc6a199ee5139d8511f61780350 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 19 Sep 2025 11:26:30 +0100 Subject: Disable external file access by default --- .../org/zwobble/mammoth/tests/MammothTests.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index a072185..9058162 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -89,14 +89,16 @@ public class MammothTests { } @Test - public void imagesStoredOutsideOfDocumentAreIncludedInOutput() throws IOException { + public void whenExternalFileAccessIsEnabledThenImagesStoredOutsideOfDocumentAreIncludedInOutput() throws IOException { Path tempDirectory = Files.createTempDirectory("mammoth-"); try { Path documentPath = tempDirectory.resolve("external-picture.docx"); Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); Files.copy(TestData.file("tiny-picture.png").toPath(), tempDirectory.resolve("tiny-picture.png")); assertThat( - new DocumentConverter().convertToHtml(documentPath.toFile()), + new DocumentConverter() + .enableExternalFileAccess() + .convertToHtml(documentPath.toFile()), isSuccess("

")); } finally { tempDirectory.toFile().delete(); @@ -104,13 +106,15 @@ public class MammothTests { } @Test - public void warnIfDocumentHasImagesStoredOutsideOfDocumentWhenPathOfDocumentIsUnknown() throws IOException { + public void whenExternalFileAccessIsEnabledThenWarnIfDocumentHasImagesStoredOutsideOfDocumentWhenPathOfDocumentIsUnknown() throws IOException { Path tempDirectory = Files.createTempDirectory("mammoth-"); try { Path documentPath = tempDirectory.resolve("external-picture.docx"); Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); assertThat( - new DocumentConverter().convertToHtml(documentPath.toUri().toURL().openStream()), + new DocumentConverter() + .enableExternalFileAccess() + .convertToHtml(documentPath.toUri().toURL().openStream()), allOf( hasProperty("value", equalTo("")), hasProperty("warnings", contains( @@ -121,16 +125,14 @@ public class MammothTests { } @Test - public void warnIfDocumentHasImagesStoredOutsideOfDocumentWhenExternalFileAccessIsDisabled() throws IOException { + public void givenExternalFileAccessIsDisabledByDefaultThenWarnIfDocumentHasImagesStoredOutsideOfDocument() throws IOException { Path tempDirectory = Files.createTempDirectory("mammoth-"); try { Path documentPath = tempDirectory.resolve("external-picture.docx"); Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); Files.copy(TestData.file("tiny-picture.png").toPath(), tempDirectory.resolve("tiny-picture.png")); assertThat( - new DocumentConverter() - .disableExternalFileAccess() - .convertToHtml(documentPath.toFile()), + new DocumentConverter().convertToHtml(documentPath.toFile()), allOf( hasProperty("value", equalTo("")), hasProperty("warnings", contains( @@ -144,13 +146,15 @@ public class MammothTests { } @Test - public void warnIfImagesStoredOutsideOfDocumentAreNotFound() throws IOException { + public void whenExternalFileAccessIsEnabledWarnIfImagesStoredOutsideOfDocumentAreNotFound() throws IOException { Path tempDirectory = Files.createTempDirectory("mammoth-"); try { Path documentPath = tempDirectory.resolve("external-picture.docx"); Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); assertThat( - new DocumentConverter().convertToHtml(documentPath.toFile()), + new DocumentConverter() + .enableExternalFileAccess() + .convertToHtml(documentPath.toFile()), allOf( hasProperty("value", equalTo("")), hasProperty("warnings", contains( -- cgit v1.2.3