2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
var SetPassphraseCtrl = require('../../../../src/js/controller/app/set-passphrase'),
|
|
|
|
PGP = require('../../../../src/js/crypto/pgp'),
|
|
|
|
Keychain = require('../../../../src/js/service/keychain'),
|
|
|
|
Dialog = require('../../../../src/js/util/dialog');
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
describe('Set Passphrase Controller unit test', function() {
|
|
|
|
var scope, setPassphraseCtrl,
|
|
|
|
dummyFingerprint, expectedFingerprint,
|
|
|
|
dummyKeyId, expectedKeyId,
|
2014-11-25 12:19:40 -05:00
|
|
|
emailAddress, keySize, pgpStub, keychainStub, dialogStub;
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-11-25 12:19:40 -05:00
|
|
|
pgpStub = sinon.createStubInstance(PGP);
|
|
|
|
keychainStub = sinon.createStubInstance(Keychain);
|
|
|
|
dialogStub = sinon.createStubInstance(Dialog);
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
dummyFingerprint = '3A2D39B4E1404190B8B949DE7D7E99036E712926';
|
|
|
|
expectedFingerprint = '3A2D 39B4 E140 4190 B8B9 49DE 7D7E 9903 6E71 2926';
|
|
|
|
dummyKeyId = '9FEB47936E712926';
|
|
|
|
expectedKeyId = '6E712926';
|
2014-11-25 12:19:40 -05:00
|
|
|
pgpStub.getFingerprint.returns(dummyFingerprint);
|
|
|
|
pgpStub.getKeyId.returns(dummyKeyId);
|
2014-10-07 14:32:23 -04:00
|
|
|
emailAddress = 'fred@foo.com';
|
|
|
|
keySize = 1234;
|
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
pgpStub.getKeyParams.returns({
|
2014-10-07 14:32:23 -04:00
|
|
|
_id: dummyKeyId,
|
|
|
|
fingerprint: dummyFingerprint,
|
|
|
|
userId: emailAddress,
|
|
|
|
userIds: [],
|
|
|
|
bitSize: keySize
|
|
|
|
});
|
2014-04-11 12:39:13 -04:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
angular.module('setpassphrasetest', ['woServices', 'woUtil']);
|
|
|
|
angular.mock.module('setpassphrasetest');
|
|
|
|
angular.mock.inject(function($rootScope, $controller) {
|
2014-10-07 14:32:23 -04:00
|
|
|
scope = $rootScope.$new();
|
|
|
|
scope.state = {};
|
|
|
|
setPassphraseCtrl = $controller(SetPassphraseCtrl, {
|
2014-11-25 12:19:40 -05:00
|
|
|
$scope: scope,
|
|
|
|
pgp: pgpStub,
|
|
|
|
keychain: keychainStub,
|
|
|
|
dialog: dialogStub
|
2014-04-11 12:39:13 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-04-11 12:39:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
afterEach(function() {});
|
2014-04-11 12:39:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('setPassphrase', function() {
|
2014-11-25 12:19:40 -05:00
|
|
|
it('should work', function() {
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.oldPassphrase = 'old';
|
|
|
|
scope.newPassphrase = 'new';
|
2014-04-11 12:39:13 -04:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
keychainStub.lookupPrivateKey.withArgs(dummyKeyId).yields(null, {
|
2014-10-07 14:32:23 -04:00
|
|
|
encryptedKey: 'encrypted'
|
|
|
|
});
|
2014-04-11 12:39:13 -04:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
pgpStub.changePassphrase.withArgs({
|
2014-10-07 14:32:23 -04:00
|
|
|
privateKeyArmored: 'encrypted',
|
|
|
|
oldPassphrase: 'old',
|
|
|
|
newPassphrase: 'new'
|
|
|
|
}).yields(null, 'newArmoredKey');
|
2014-04-11 12:39:13 -04:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
keychainStub.saveLocalPrivateKey.withArgs({
|
2014-10-07 14:32:23 -04:00
|
|
|
_id: dummyKeyId,
|
|
|
|
userId: emailAddress,
|
|
|
|
userIds: [],
|
|
|
|
encryptedKey: 'newArmoredKey'
|
|
|
|
}).yields();
|
2014-04-11 12:39:13 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.setPassphrase();
|
2014-11-25 12:19:40 -05:00
|
|
|
|
|
|
|
expect(dialogStub.info.calledOnce).to.be.true;
|
2014-04-11 12:39:13 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('check passphrase quality', function() {
|
|
|
|
it('should be too short', function() {
|
|
|
|
scope.newPassphrase = '&§DG36';
|
|
|
|
scope.checkPassphraseQuality();
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(scope.passphraseMsg).to.equal('Very weak');
|
|
|
|
expect(scope.passphraseRating).to.equal(0);
|
|
|
|
});
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should be very weak', function() {
|
|
|
|
scope.newPassphrase = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
|
|
|
scope.checkPassphraseQuality();
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(scope.passphraseMsg).to.equal('Very weak');
|
|
|
|
expect(scope.passphraseRating).to.equal(0);
|
|
|
|
});
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should be weak', function() {
|
|
|
|
scope.newPassphrase = 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf';
|
|
|
|
scope.checkPassphraseQuality();
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(scope.passphraseMsg).to.equal('Weak');
|
|
|
|
expect(scope.passphraseRating).to.equal(1);
|
|
|
|
});
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should be good', function() {
|
|
|
|
scope.newPassphrase = 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf5';
|
|
|
|
scope.checkPassphraseQuality();
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(scope.passphraseMsg).to.equal('Good');
|
|
|
|
expect(scope.passphraseRating).to.equal(2);
|
|
|
|
});
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should be strong', function() {
|
|
|
|
scope.newPassphrase = '&§DG36abcd';
|
|
|
|
scope.checkPassphraseQuality();
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(scope.passphraseMsg).to.equal('Strong');
|
|
|
|
expect(scope.passphraseRating).to.equal(3);
|
2014-09-12 11:11:05 -04:00
|
|
|
});
|
2014-04-11 12:39:13 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
|
2014-04-11 12:39:13 -04:00
|
|
|
});
|