From 1494d3c3a6283a00701ac452b8a9a5f8f2f4e9dd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 10 Sep 2025 15:55:27 +0100 Subject: Support disabling external file access --- test/docx/files.tests.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'test/docx') diff --git a/test/docx/files.tests.js b/test/docx/files.tests.js index 9a39acb..5ddda4a 100644 --- a/test/docx/files.tests.js +++ b/test/docx/files.tests.js @@ -13,9 +13,16 @@ var readFile = promises.promisify(fs.readFile.bind(fs)); test("Files", { + "when external file access is disabled then reading file raises error": function() { + var files = new Files({externalFileAccess: false}); + return assertError(files.read("/tmp/image.png", "base64"), function(err) { + assert.strictEqual(err.message, "could not read external image '/tmp/image.png', external file access is disabled"); + }); + }, + "can open files with file URI": function() { var filePath = path.resolve(testing.testPath("tiny-picture.png")); - var files = new Files({}); + var files = new Files({externalFileAccess: true}); return files.read("file:///" + filePath.replace(/^\//, ""), "base64").then(function(contents) { return readFile(filePath, "base64").then(function(expectedContents) { assert.deepEqual(contents, expectedContents); @@ -25,7 +32,10 @@ test("Files", { "can open files with relative URI": function() { var filePath = path.resolve(testing.testPath("tiny-picture.png")); - var files = new Files({relativeToFile: testing.testPath("./document.docx")}); + var files = new Files({ + externalFileAccess: true, + relativeToFile: testing.testPath("./document.docx") + }); return files.read("tiny-picture.png", "base64").then(function(contents) { return readFile(filePath, "base64").then(function(expectedContents) { assert.deepEqual(contents, expectedContents); @@ -34,14 +44,17 @@ test("Files", { }, "given base is not set when opening relative uri then error is raised": function() { - var files = new Files({}); + var files = new Files({externalFileAccess: true}); return assertError(files.read("not-a-real-file.png", "base64"), function(err) { assert.equal(err.message, "could not find external image 'not-a-real-file.png', path of input document is unknown"); }); }, "error if relative uri cannot be opened": function() { - var files = new Files({relativeToFile: "/tmp/document.docx"}); + var files = new Files({ + externalFileAccess: true, + relativeToFile: "/tmp/document.docx" + }); return assertError(files.read("not-a-real-file.png", "base64"), function(err) { assertRegex(err.message, /could not open external image: 'not-a-real-file.png' \(document directory: '\/tmp'\)\nENOENT.*\/tmp\/not-a-real-file.png.*/); }); -- cgit v1.2.3