Merge pull request #7211 from Snuffleupagus/crypto-tests-NEED_PASSWORD

Add a couple of `CipherTransformFactory` unit-tests for blank passwords, and move the `isDict` unit-tests to the correct file
This commit is contained in:
Yury Delendik 2016-04-16 20:02:05 -05:00
commit 0428fdf3ca
3 changed files with 38 additions and 18 deletions

View File

@ -481,6 +481,19 @@ describe('CipherTransformFactory', function() {
done();
}
function ensurePasswordNeeded(done, dict, fileId, password) {
try {
new CipherTransformFactory(dict, fileId, password);
} catch (ex) {
expect(ex instanceof PasswordException).toEqual(true);
expect(ex.code).toEqual(PasswordResponses.NEED_PASSWORD);
done();
return;
}
done.fail('Password should be rejected.');
}
function ensurePasswordIncorrect(done, dict, fileId, password) {
try {
new CipherTransformFactory(dict, fileId, password);
@ -609,6 +622,9 @@ describe('CipherTransformFactory', function() {
it('should accept owner password', function (done) {
ensurePasswordCorrect(done, aes256Dict, fileId1, 'owner');
});
it('should not accept blank password', function (done) {
ensurePasswordNeeded(done, aes256Dict, fileId1);
});
it('should not accept wrong password', function (done) {
ensurePasswordIncorrect(done, aes256Dict, fileId1, 'wrong');
});
@ -624,6 +640,9 @@ describe('CipherTransformFactory', function() {
it('should accept owner password', function (done) {
ensurePasswordCorrect(done, aes256IsoDict, fileId1, 'owner');
});
it('should not accept blank password', function (done) {
ensurePasswordNeeded(done, aes256IsoDict, fileId1);
});
it('should not accept wrong password', function (done) {
ensurePasswordIncorrect(done, aes256IsoDict, fileId1, 'wrong');
});
@ -638,10 +657,13 @@ describe('CipherTransformFactory', function() {
it('should accept owner password', function (done) {
ensurePasswordCorrect(done, dict1, fileId1, '654321');
});
it('should not accept blank password', function (done) {
ensurePasswordNeeded(done, dict1, fileId1);
});
it('should not accept wrong password', function (done) {
ensurePasswordIncorrect(done, dict1, fileId1, 'wrong');
});
it('should accept no password', function (done) {
it('should accept blank password', function (done) {
ensurePasswordCorrect(done, dict2, fileId2);
});
});

View File

@ -1,10 +1,9 @@
/* globals expect, it, describe, beforeEach, Name, Dict, Ref, RefSet, Cmd,
jasmine */
jasmine, isDict */
'use strict';
describe('primitives', function() {
describe('Name', function() {
it('should retain the given name', function() {
var givenName = 'Font';
@ -146,4 +145,17 @@ describe('primitives', function() {
expect(refset.has(anotherRef)).toBeFalsy();
});
});
describe('isDict', function() {
it('handles empty dictionaries with type check', function() {
var dict = new Dict();
expect(isDict(dict, 'Page')).toEqual(false);
});
it('handles dictionaries with type check', function() {
var dict = new Dict();
dict.set('Type', Name.get('Page'));
expect(isDict(dict, 'Page')).toEqual(true);
});
});
});

View File

@ -1,22 +1,8 @@
/* globals expect, it, describe, Dict, isDict, Name, PDFJS,
stringToPDFString, removeNullCharacters */
/* globals describe, it, expect, stringToPDFString, removeNullCharacters */
'use strict';
describe('util', function() {
describe('isDict', function() {
it('handles empty dictionaries with type check', function() {
var dict = new Dict();
expect(isDict(dict, 'Page')).toEqual(false);
});
it('handles dictionaries with type check', function() {
var dict = new Dict();
dict.set('Type', Name.get('Page'));
expect(isDict(dict, 'Page')).toEqual(true);
});
});
describe('stringToPDFString', function() {
it('handles ISO Latin 1 strings', function() {
var str = '\x8Dstring\x8E';