From 4523ae0b914a4c280c1bb9252275a357a85d47f0 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 16 Apr 2016 20:24:55 +0200 Subject: [PATCH] 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 e22381d40..e33fc184b 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); }); });