diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 62bfa3a9b..db9276ada 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -55,6 +55,8 @@ !pdfkit_compressed.pdf !TAMReview.pdf !pr4922.pdf +!pr6531_1.pdf +!pr6531_2.pdf !bug900822.pdf !issue918.pdf !issue1905.pdf diff --git a/test/pdfs/pr6531_1.pdf b/test/pdfs/pr6531_1.pdf new file mode 100644 index 000000000..b1f905f59 Binary files /dev/null and b/test/pdfs/pr6531_1.pdf differ diff --git a/test/pdfs/pr6531_2.pdf b/test/pdfs/pr6531_2.pdf new file mode 100644 index 000000000..396e18b1f --- /dev/null +++ b/test/pdfs/pr6531_2.pdf @@ -0,0 +1,44 @@ +%PDF-1.4 +%쏢 +1 0 obj<> +endobj +2 0 obj<> +endobj +3 0 obj<> +endobj +4 0 obj<> +endobj +5 0 obj<> +endobj +6 0 obj<>/DA(y\232\036\214A#\357n\310NA\315\213m\277X7\302\301\264\254!x\331\215\315\036\354s\017\334\346m\000\344\222\277\326\347#\347r"f\003NC\266)/DS(\201\2323\356\332\26605\216\266q\340c\027\356\226\364'f\365w\257\021\265\366\352\027\207\033\350\377\323\325w\232\345K~\b\031\321\032\237\312\206\002\321\216*\274\216\262\370&[\253\0179\311\007\326\023"H\032\t\226t>\003\304=\302+\234\250t&d\324wr+Q\264\313\306\374\027\\\344\327\341\242\250Ej\376\352h\317\(\245\275\(\215\005\242\n\265\320\207)/M(e\333\215\b\321ZA2\315\037\337z\263XM\355;\335\025A\006\022\230\227\223\216\205\253\276\017\251\3002X\020m~\357\303\334I8\203\216\312\017\350\331)/AP<>/Rect[33.30177 551.7525 488.2271 746.2612]/NM(|\362Z\355\322b{\302j\347\374\212\260\017\013\260\205\030\216\f\200?L\235\344\321{\255\202\327\231\346\206BB\023\031\261\021\2148\006\245\n\256\253\251\257)/RC(_\251h\256\336\266\205&Y\000!\273\326\264\2016@\242'\270\037|\315\220<\322\020\371\245\276\277\266\\\242\361\('\355A\322\242*W.\254\367u8\221\377\220\275\025\372\0035\021X0\034\203r\272@\024\224> +endobj +7 0 obj[6 0 R] +endobj +8 0 obj<>>> +endobj +9 0 obj<>>>/Matrix[1 0 0 1 -33.30179 -551.7524]/Length 160>> +stream +\,#+ǞzӂvEU0 Zg˶u[_iE [ed|blk 'aB +\@drrҹ[OOBz]f$ir9iК\kS:/'Ц7ZP5NM̳Y<JKdW]J*_G +endstream +endobj +11 0 obj<>>>/StmF/StdCF/StrF/StdCF/P -4/U<86270432ecb25433a37e461bfc3721bed1d73810583503f1be6afb42ad523da86adfe4b76358edf0738fbc8e053fb121>/UE<556ca676e248a3198b38f63302d3ff73c316b0e5b60010714ba511ae91687686>/O<384415c370731d581955244d1e475204d084d4b5be9a943e55f0a21d0a354d86002175233d6899ac4a244104ea74aaaa>/OE/Perms>> +endobj +xref +0 12 +0000000000 65535 f +0000000015 00000 n +0000000744 00000 n +0000000788 00000 n +0000000838 00000 n +0000000901 00000 n +0000000978 00000 n +0000003557 00000 n +0000003579 00000 n +0000004847 00000 n +0000000000 65535 f +0000005223 00000 n +trailer<]/Root 2 0 R/Encrypt 11 0 R>> +startxref +5738 +%%EOF diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 5a85a5435..4a7a7820c 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2,6 +2,7 @@ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ /* globals PDFJS, expect, it, describe, Promise, combineUrl, waitsFor, InvalidPDFException, MissingPDFException, StreamType, FontType, + PDFDocumentProxy, PasswordException, PasswordResponses, PDFPageProxy */ 'use strict'; @@ -97,6 +98,60 @@ describe('api', function() { expect(error instanceof MissingPDFException).toEqual(true); }); }); + it('creates pdf doc from PDF file protected with user and owner password', + function () { + var url = combineUrl(window.location.href, '../pdfs/pr6531_1.pdf'); + + var passwordNeededPromise = PDFJS.getDocument({ + url: url, password: '', + }); + waitsForPromiseRejected(passwordNeededPromise, function (data) { + expect(data instanceof PasswordException).toEqual(true); + expect(data.code).toEqual(PasswordResponses.NEED_PASSWORD); + }); + + var passwordIncorrectPromise = PDFJS.getDocument({ + url: url, password: 'qwerty', + }); + waitsForPromiseRejected(passwordIncorrectPromise, function (data) { + expect(data instanceof PasswordException).toEqual(true); + expect(data.code).toEqual(PasswordResponses.INCORRECT_PASSWORD); + }); + + var passwordAcceptedPromise = PDFJS.getDocument({ + url: url, password: 'asdfasdf', + }); + waitsForPromiseResolved(passwordAcceptedPromise, function (data) { + expect(data instanceof PDFDocumentProxy).toEqual(true); + }); + }); + it('creates pdf doc from PDF file protected with only a user password', + function () { + var url = combineUrl(window.location.href, '../pdfs/pr6531_2.pdf'); + + var passwordNeededPromise = PDFJS.getDocument({ + url: url, password: '', + }); + waitsForPromiseRejected(passwordNeededPromise, function (data) { + expect(data instanceof PasswordException).toEqual(true); + expect(data.code).toEqual(PasswordResponses.NEED_PASSWORD); + }); + + var passwordIncorrectPromise = PDFJS.getDocument({ + url: url, password: 'qwerty', + }); + waitsForPromiseRejected(passwordIncorrectPromise, function (data) { + expect(data instanceof PasswordException).toEqual(true); + expect(data.code).toEqual(PasswordResponses.INCORRECT_PASSWORD); + }); + + var passwordAcceptedPromise = PDFJS.getDocument({ + url: url, password: 'asdfasdf', + }); + waitsForPromiseResolved(passwordAcceptedPromise, function (data) { + expect(data instanceof PDFDocumentProxy).toEqual(true); + }); + }); }); }); describe('PDFDocument', function() {