From 444dc1b64c015197bf6b5219da9459bc0cf6f787 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 10 Sep 2025 16:40:27 +0100 Subject: Support disabling external file access --- .../org/zwobble/mammoth/tests/MammothTests.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/test/java/org/zwobble/mammoth/tests/MammothTests.java') diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index 85a20ce..a072185 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -120,6 +120,29 @@ public class MammothTests { } } + @Test + public void warnIfDocumentHasImagesStoredOutsideOfDocumentWhenExternalFileAccessIsDisabled() 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()), + allOf( + hasProperty("value", equalTo("")), + hasProperty("warnings", contains( + equalTo("could not open external image 'tiny-picture.png': external file access is disabled") + )) + ) + ); + } finally { + tempDirectory.toFile().delete(); + } + } + @Test public void warnIfImagesStoredOutsideOfDocumentAreNotFound() throws IOException { Path tempDirectory = Files.createTempDirectory("mammoth-"); -- cgit v1.2.3