diff --git a/karma.conf.js b/karma.conf.js index 4d47ec4572a4101dae0311a9da43a9c75a330169..3bb69b01583c88d837af67ab7a938708c37ecbee 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -9,7 +9,8 @@ module.exports = function (config) { }, files: [ {pattern: './*.js', included: true, watched: true, served: true, type: 'module'}, - {pattern: './**/*', included: false, watched: true, served: true}, + // XXX: nocache is required or karma serves garbage binary data for some reason + {pattern: './**/*', included: false, watched: true, served: true, nocache: true}, ], autoWatch: true, browsers: ['ChromiumHeadlessNoSandbox', 'FirefoxHeadless'], diff --git a/rollup.config.js b/rollup.config.js index aea6a6265b703245aab2ab2fa42cef5a8dd231bf..55d9001c37eb6ff74817b893b935aa65e1c397db 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -183,6 +183,14 @@ Dependencies: emitFiles: true, fileName: 'shared/[name].[hash][extname]', }), + appEnv == 'test' && copy({ + targets: [ + { + src: 'test/data/*', + dest: 'dist/test', + }, + ] + }), copy({ targets: [ { diff --git a/src/utils.js b/src/utils.js index d4c585c1bdd9f3c6765f5d70a77f5c990110ec83..11c29c76d552305e59ff9c0b099e023918cbb6f8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -132,7 +132,7 @@ export const readArrayBufferFileContent = async (file) => { */ export const getPDFSignatureCount = async (file) => { const sigRegex = new RegExp( - '/Type\\s*/Sig(.|\\s)*?/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)', + '/Type\\s*/Sig[\\s\\S]*?/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)', 'g' ); const content = await readBinaryFileContent(file); diff --git a/test/data/QPDF-367-0.pdf b/test/data/QPDF-367-0.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e94313cf29ec108f4783ebc89ba79522cdf15b49 Binary files /dev/null and b/test/data/QPDF-367-0.pdf differ diff --git a/test/data/README.md b/test/data/README.md new file mode 100644 index 0000000000000000000000000000000000000000..43a1033c61d42831b8674306bd4899273f146ca7 --- /dev/null +++ b/test/data/README.md @@ -0,0 +1,2 @@ +QPDF-367-0.pdf: + From https://corpora.tika.apache.org/base/packaged/pdfs/archive/pdfs_202002/qpdf.zip \ No newline at end of file diff --git a/test/data/qual-sig-simple.pdf b/test/data/qual-sig-simple.pdf new file mode 100644 index 0000000000000000000000000000000000000000..85e222c771b9cd7966aaaa949985cef5403e0be6 Binary files /dev/null and b/test/data/qual-sig-simple.pdf differ diff --git a/test/data/qual-sig-tugraz-multiple.pdf b/test/data/qual-sig-tugraz-multiple.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3893716f494f1ee6eab37a23af55ba4e2fc3bd0c Binary files /dev/null and b/test/data/qual-sig-tugraz-multiple.pdf differ diff --git a/test/unit.js b/test/unit.js index 16959e8d801962c303741d59609cb513e41e5b16..82895c19a7fd4b7ab745babfc93ba0e7f6ebad93 100644 --- a/test/unit.js +++ b/test/unit.js @@ -66,4 +66,18 @@ suite('pdf signature detection', () => { assert((await getPDFSignatureCount(getPDFFile('foobar'))) === 0); assert((await getPDFSignatureCount(getPDFFile(''))) === 0); }); + + test('getPDFSignatureCount real files', async () => { + + async function getRealPDFFile(name) { + let url = new URL('test/' + name, import.meta.url).href; + let resp = await fetch(url); + assert(resp.ok); + return getPDFFile(await resp.arrayBuffer()); + } + + assert.equal((await getPDFSignatureCount(await getRealPDFFile('QPDF-367-0.pdf'))), 0); + assert.equal((await getPDFSignatureCount(await getRealPDFFile('qual-sig-simple.pdf'))), 1); + assert.equal((await getPDFSignatureCount(await getRealPDFFile('qual-sig-tugraz-multiple.pdf'))), 2); + }); });