1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Implement a permissions API

This commit is contained in:
Tim van der Meij 2018-08-26 21:37:05 +02:00
parent 4874e9ace0
commit 959ed3705b
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
9 changed files with 137 additions and 4 deletions

View file

@ -325,3 +325,6 @@
!transparent.pdf
!xobject-image.pdf
!ccitt_EndOfBlock_false.pdf
!issue9972-1.pdf
!issue9972-2.pdf
!issue9972-3.pdf

BIN
test/pdfs/issue9972-1.pdf Normal file

Binary file not shown.

BIN
test/pdfs/issue9972-2.pdf Normal file

Binary file not shown.

BIN
test/pdfs/issue9972-3.pdf Normal file

Binary file not shown.

View file

@ -18,7 +18,8 @@ import {
} from './test_utils';
import {
createPromiseCapability, FontType, InvalidPDFException, MissingPDFException,
OPS, PasswordException, PasswordResponses, StreamType, stringToBytes
OPS, PasswordException, PasswordResponses, PermissionFlag, StreamType,
stringToBytes
} from '../../src/shared/util';
import {
DOMCanvasFactory, RenderingCancelledException, StatTimer
@ -822,6 +823,63 @@ describe('api', function() {
done.fail(reason);
});
});
it('gets non-existent permissions', function(done) {
doc.getPermissions().then(function(permissions) {
expect(permissions).toEqual(null);
done();
}).catch(function(reason) {
done.fail(reason);
});
});
it('gets permissions', function (done) {
// Editing not allowed.
const loadingTask0 =
getDocument(buildGetDocumentParams('issue9972-1.pdf'));
const promise0 = loadingTask0.promise.then(function(pdfDocument) {
return pdfDocument.getPermissions();
});
// Printing not allowed.
const loadingTask1 =
getDocument(buildGetDocumentParams('issue9972-2.pdf'));
const promise1 = loadingTask1.promise.then(function(pdfDocument) {
return pdfDocument.getPermissions();
});
// Copying not allowed.
const loadingTask2 =
getDocument(buildGetDocumentParams('issue9972-3.pdf'));
const promise2 = loadingTask2.promise.then(function(pdfDocument) {
return pdfDocument.getPermissions();
});
const totalPermissionCount = Object.keys(PermissionFlag).length;
Promise.all([promise0, promise1, promise2]).then(function(permissions) {
expect(permissions[0].length).toEqual(totalPermissionCount - 1);
expect(permissions[0].includes(PermissionFlag.MODIFY_CONTENTS))
.toBeFalsy();
expect(permissions[1].length).toEqual(totalPermissionCount - 2);
expect(permissions[1].includes(PermissionFlag.PRINT)).toBeFalsy();
expect(permissions[1].includes(PermissionFlag.PRINT_HIGH_QUALITY))
.toBeFalsy();
expect(permissions[2].length).toEqual(totalPermissionCount - 1);
expect(permissions[2].includes(PermissionFlag.COPY)).toBeFalsy();
Promise.all([
loadingTask0.destroy(),
loadingTask1.destroy(),
loadingTask2.destroy(),
]).then(done);
}).catch(function(reason) {
done.fail(reason);
});
});
it('gets metadata', function(done) {
var promise = doc.getMetadata();
promise.then(function({ info, metadata, contentDispositionFilename, }) {