1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 19:02:20 -05:00
mail/test/unit/set-passphrase-ctrl-test.js

122 lines
4.1 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-10-09 09:56:35 -04:00
var mocks = angular.mock,
2014-10-07 14:32:23 -04:00
SetPassphraseCtrl = require('../../src/js/controller/set-passphrase'),
PGP = require('../../src/js/crypto/pgp'),
appController = require('../../src/js/app-controller'),
KeychainDAO = require('../../src/js/dao/keychain-dao');
describe('Set Passphrase Controller unit test', function() {
var scope, setPassphraseCtrl,
dummyFingerprint, expectedFingerprint,
dummyKeyId, expectedKeyId,
emailAddress, keySize, cryptoMock, keychainMock;
beforeEach(function() {
appController._pgp = cryptoMock = sinon.createStubInstance(PGP);
appController._keychain = keychainMock = sinon.createStubInstance(KeychainDAO);
dummyFingerprint = '3A2D39B4E1404190B8B949DE7D7E99036E712926';
expectedFingerprint = '3A2D 39B4 E140 4190 B8B9 49DE 7D7E 9903 6E71 2926';
dummyKeyId = '9FEB47936E712926';
expectedKeyId = '6E712926';
cryptoMock.getFingerprint.returns(dummyFingerprint);
cryptoMock.getKeyId.returns(dummyKeyId);
emailAddress = 'fred@foo.com';
keySize = 1234;
cryptoMock.getKeyParams.returns({
_id: dummyKeyId,
fingerprint: dummyFingerprint,
userId: emailAddress,
userIds: [],
bitSize: keySize
});
2014-10-07 14:32:23 -04:00
angular.module('setpassphrasetest', []);
mocks.module('setpassphrasetest');
mocks.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.state = {};
setPassphraseCtrl = $controller(SetPassphraseCtrl, {
$scope: scope
});
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
afterEach(function() {});
2014-10-07 14:32:23 -04:00
describe('setPassphrase', function() {
it('should work', function(done) {
scope.oldPassphrase = 'old';
scope.newPassphrase = 'new';
2014-10-07 14:32:23 -04:00
keychainMock.lookupPrivateKey.withArgs(dummyKeyId).yields(null, {
encryptedKey: 'encrypted'
});
2014-10-07 14:32:23 -04:00
cryptoMock.changePassphrase.withArgs({
privateKeyArmored: 'encrypted',
oldPassphrase: 'old',
newPassphrase: 'new'
}).yields(null, 'newArmoredKey');
2014-10-07 14:32:23 -04:00
keychainMock.saveLocalPrivateKey.withArgs({
_id: dummyKeyId,
userId: emailAddress,
userIds: [],
encryptedKey: 'newArmoredKey'
}).yields();
2014-10-07 14:32:23 -04:00
scope.onError = function(err) {
expect(err.title).to.equal('Success');
done();
};
2014-10-07 14:32:23 -04:00
scope.setPassphrase();
});
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-10-07 14:32:23 -04:00
});