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:
commit
0428fdf3ca
@ -481,6 +481,19 @@ describe('CipherTransformFactory', function() {
|
|||||||
done();
|
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) {
|
function ensurePasswordIncorrect(done, dict, fileId, password) {
|
||||||
try {
|
try {
|
||||||
new CipherTransformFactory(dict, fileId, password);
|
new CipherTransformFactory(dict, fileId, password);
|
||||||
@ -609,6 +622,9 @@ describe('CipherTransformFactory', function() {
|
|||||||
it('should accept owner password', function (done) {
|
it('should accept owner password', function (done) {
|
||||||
ensurePasswordCorrect(done, aes256Dict, fileId1, 'owner');
|
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) {
|
it('should not accept wrong password', function (done) {
|
||||||
ensurePasswordIncorrect(done, aes256Dict, fileId1, 'wrong');
|
ensurePasswordIncorrect(done, aes256Dict, fileId1, 'wrong');
|
||||||
});
|
});
|
||||||
@ -624,6 +640,9 @@ describe('CipherTransformFactory', function() {
|
|||||||
it('should accept owner password', function (done) {
|
it('should accept owner password', function (done) {
|
||||||
ensurePasswordCorrect(done, aes256IsoDict, fileId1, 'owner');
|
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) {
|
it('should not accept wrong password', function (done) {
|
||||||
ensurePasswordIncorrect(done, aes256IsoDict, fileId1, 'wrong');
|
ensurePasswordIncorrect(done, aes256IsoDict, fileId1, 'wrong');
|
||||||
});
|
});
|
||||||
@ -638,10 +657,13 @@ describe('CipherTransformFactory', function() {
|
|||||||
it('should accept owner password', function (done) {
|
it('should accept owner password', function (done) {
|
||||||
ensurePasswordCorrect(done, dict1, fileId1, '654321');
|
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) {
|
it('should not accept wrong password', function (done) {
|
||||||
ensurePasswordIncorrect(done, dict1, fileId1, 'wrong');
|
ensurePasswordIncorrect(done, dict1, fileId1, 'wrong');
|
||||||
});
|
});
|
||||||
it('should accept no password', function (done) {
|
it('should accept blank password', function (done) {
|
||||||
ensurePasswordCorrect(done, dict2, fileId2);
|
ensurePasswordCorrect(done, dict2, fileId2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
/* globals expect, it, describe, beforeEach, Name, Dict, Ref, RefSet, Cmd,
|
/* globals expect, it, describe, beforeEach, Name, Dict, Ref, RefSet, Cmd,
|
||||||
jasmine */
|
jasmine, isDict */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('primitives', function() {
|
describe('primitives', function() {
|
||||||
|
|
||||||
describe('Name', function() {
|
describe('Name', function() {
|
||||||
it('should retain the given name', function() {
|
it('should retain the given name', function() {
|
||||||
var givenName = 'Font';
|
var givenName = 'Font';
|
||||||
@ -146,4 +145,17 @@ describe('primitives', function() {
|
|||||||
expect(refset.has(anotherRef)).toBeFalsy();
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,22 +1,8 @@
|
|||||||
/* globals expect, it, describe, Dict, isDict, Name, PDFJS,
|
/* globals describe, it, expect, stringToPDFString, removeNullCharacters */
|
||||||
stringToPDFString, removeNullCharacters */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('util', function() {
|
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() {
|
describe('stringToPDFString', function() {
|
||||||
it('handles ISO Latin 1 strings', function() {
|
it('handles ISO Latin 1 strings', function() {
|
||||||
var str = '\x8Dstring\x8E';
|
var str = '\x8Dstring\x8E';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user