From 4523ae0b914a4c280c1bb9252275a357a85d47f0 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 16 Apr 2016 20:24:55 +0200 Subject: [PATCH 1/2] Add a couple of `CipherTransformFactory` unit-tests to check that blank passwords are correctly rejected --- test/unit/crypto_spec.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/unit/crypto_spec.js b/test/unit/crypto_spec.js index e22381d40d9a6..e33fc184b5b2e 100644 --- a/test/unit/crypto_spec.js +++ b/test/unit/crypto_spec.js @@ -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); }); }); From b4a17323b6149c7f63b91a1959c8ef973ea2dcc9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 16 Apr 2016 20:32:46 +0200 Subject: [PATCH 2/2] Move `isDict` unit-tests from util_spec.js to primitives_spec.js This patch moves the unit-test to the correct file, since the `isDict` function was moved PR 6683. --- test/unit/primitives_spec.js | 16 ++++++++++++++-- test/unit/util_spec.js | 16 +--------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/test/unit/primitives_spec.js b/test/unit/primitives_spec.js index d751f3a0f65d2..a19801feb6a3c 100644 --- a/test/unit/primitives_spec.js +++ b/test/unit/primitives_spec.js @@ -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); + }); + }); }); diff --git a/test/unit/util_spec.js b/test/unit/util_spec.js index 5fa33f9f55bae..655e2dc1865ee 100644 --- a/test/unit/util_spec.js +++ b/test/unit/util_spec.js @@ -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';