aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-09-19 11:26:30 +0100
committerMichael Williamson <mike@zwobble.org>2025-09-19 11:26:30 +0100
commita929dc7164a5acc6a199ee5139d8511f61780350 (patch)
tree4cd8f3232fc0f8acdfa5c19b44ded6c775ea9609 /src/test/java
parent98c98549a237be0db4689bf38436a24fc30ac111 (diff)
Disable external file access by default
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/MammothTests.java24
1 files changed, 14 insertions, 10 deletions
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("<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>"));
} 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(