Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a couple of CipherTransformFactory unit-tests for blank passwords, and move the isDict unit-tests to the correct file #7211

Merged
merged 2 commits into from
Apr 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion test/unit/crypto_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
});
Expand All @@ -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');
});
Expand All @@ -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);
});
});
Expand Down
16 changes: 14 additions & 2 deletions test/unit/primitives_spec.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});
});
16 changes: 1 addition & 15 deletions test/unit/util_spec.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down