mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 00:42:20 -05:00
commit
0d17701ebd
@ -51,7 +51,7 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (availableKeys && availableKeys.publicKey && !availableKeys.publicKey.source && !availableKeys.privateKey) {
|
} else if (availableKeys && availableKeys.publicKey && !availableKeys.privateKey) {
|
||||||
// check if private key is synced
|
// check if private key is synced
|
||||||
return keychain.requestPrivateKeyDownload({
|
return keychain.requestPrivateKeyDownload({
|
||||||
userId: availableKeys.publicKey.userId,
|
userId: availableKeys.publicKey.userId,
|
||||||
|
@ -57,40 +57,6 @@ Keychain.prototype.verifyPublicKey = function(uuid) {
|
|||||||
return this._publicKeyDao.verify(uuid);
|
return this._publicKeyDao.verify(uuid);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an array of public keys by looking in local storage and
|
|
||||||
* fetching missing keys from the cloud service.
|
|
||||||
* @param ids [Array] the key ids as [{_id, userId}]
|
|
||||||
* @return [PublicKeyCollection] The requiested public keys
|
|
||||||
*/
|
|
||||||
Keychain.prototype.getPublicKeys = function(ids) {
|
|
||||||
var self = this,
|
|
||||||
jobs = [],
|
|
||||||
pubkeys = [];
|
|
||||||
|
|
||||||
ids.forEach(function(i) {
|
|
||||||
// lookup locally and in storage
|
|
||||||
var promise = self.lookupPublicKey(i._id).then(function(pubkey) {
|
|
||||||
if (!pubkey) {
|
|
||||||
throw new Error('Error looking up public key!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if public key with that id has already been fetched
|
|
||||||
var already = _.findWhere(pubkeys, {
|
|
||||||
_id: i._id
|
|
||||||
});
|
|
||||||
if (!already) {
|
|
||||||
pubkeys.push(pubkey);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
jobs.push(promise);
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(jobs).then(function() {
|
|
||||||
return pubkeys;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for public key updates of a given user id
|
* Checks for public key updates of a given user id
|
||||||
* @param {String} options.userId The user id (email address) for which to check the key
|
* @param {String} options.userId The user id (email address) for which to check the key
|
||||||
@ -191,7 +157,7 @@ Keychain.prototype.getReceiverPublicKey = function(userId) {
|
|||||||
var pubkey = _.findWhere(allPubkeys, {
|
var pubkey = _.findWhere(allPubkeys, {
|
||||||
userId: userId
|
userId: userId
|
||||||
});
|
});
|
||||||
// query mutliple userIds (for imported public keys)
|
// query mutliple userIds
|
||||||
if (!pubkey) {
|
if (!pubkey) {
|
||||||
for (var i = 0, match; i < allPubkeys.length; i++) {
|
for (var i = 0, match; i < allPubkeys.length; i++) {
|
||||||
userIds = self._pgp.getKeyParams(allPubkeys[i].publicKey).userIds;
|
userIds = self._pgp.getKeyParams(allPubkeys[i].publicKey).userIds;
|
||||||
@ -636,7 +602,7 @@ Keychain.prototype.getUserKeyPair = function(userId) {
|
|||||||
userId: userId
|
userId: userId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (pubkey && pubkey._id) {
|
if (pubkey && pubkey._id && !pubkey.source) {
|
||||||
// that user's public key is already in local storage...
|
// that user's public key is already in local storage...
|
||||||
// sync keypair to the cloud
|
// sync keypair to the cloud
|
||||||
return syncKeypair(pubkey._id);
|
return syncKeypair(pubkey._id);
|
||||||
@ -645,13 +611,13 @@ Keychain.prototype.getUserKeyPair = function(userId) {
|
|||||||
// no public key by that user id in storage
|
// no public key by that user id in storage
|
||||||
// find from cloud by email address
|
// find from cloud by email address
|
||||||
return self._publicKeyDao.getByUserId(userId).then(function(cloudPubkey) {
|
return self._publicKeyDao.getByUserId(userId).then(function(cloudPubkey) {
|
||||||
if (cloudPubkey && cloudPubkey._id) {
|
if (cloudPubkey && cloudPubkey._id && !cloudPubkey.source) {
|
||||||
// there is a public key for that user already in the cloud...
|
// there is a public key for that user already in the cloud...
|
||||||
// sync keypair to local storage
|
// sync keypair to local storage
|
||||||
return syncKeypair(cloudPubkey._id);
|
return syncKeypair(cloudPubkey._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// continue without keypair... generate in crypto.js
|
// continue without keypair... generate or import new keypair
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -660,10 +626,12 @@ Keychain.prototype.getUserKeyPair = function(userId) {
|
|||||||
// persist key pair in local storage
|
// persist key pair in local storage
|
||||||
return self.lookupPublicKey(keypairId).then(function(pub) {
|
return self.lookupPublicKey(keypairId).then(function(pub) {
|
||||||
savedPubkey = pub;
|
savedPubkey = pub;
|
||||||
|
|
||||||
// persist private key in local storage
|
// persist private key in local storage
|
||||||
return self.lookupPrivateKey(keypairId).then(function(priv) {
|
return self.lookupPrivateKey(keypairId);
|
||||||
savedPrivkey = priv;
|
|
||||||
});
|
}).then(function(priv) {
|
||||||
|
savedPrivkey = priv;
|
||||||
|
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
var keys = {};
|
var keys = {};
|
||||||
|
@ -86,7 +86,7 @@ describe('Login Controller unit test', function() {
|
|||||||
authMock.getEmailAddress.returns(resolves({}));
|
authMock.getEmailAddress.returns(resolves({}));
|
||||||
|
|
||||||
scope.init().then(function() {
|
scope.init().then(function() {
|
||||||
expect(goToStub.calledWith('/add-account')).to.be.true;
|
expect(goToStub.withArgs('/add-account').called).to.be.true;
|
||||||
expect(goToStub.calledOnce).to.be.true;
|
expect(goToStub.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -104,7 +104,7 @@ describe('Login Controller unit test', function() {
|
|||||||
emailMock.unlock.returns(rejects(new Error()));
|
emailMock.unlock.returns(rejects(new Error()));
|
||||||
|
|
||||||
scope.init().then(function() {
|
scope.init().then(function() {
|
||||||
expect(goToStub.calledWith('/login-existing')).to.be.true;
|
expect(goToStub.withArgs('/login-existing').called).to.be.true;
|
||||||
expect(goToStub.calledOnce).to.be.true;
|
expect(goToStub.calledOnce).to.be.true;
|
||||||
expect(authMock.storeCredentials.called).to.be.false;
|
expect(authMock.storeCredentials.called).to.be.false;
|
||||||
done();
|
done();
|
||||||
@ -142,7 +142,7 @@ describe('Login Controller unit test', function() {
|
|||||||
authMock.storeCredentials.returns(resolves());
|
authMock.storeCredentials.returns(resolves());
|
||||||
|
|
||||||
scope.init().then(function() {
|
scope.init().then(function() {
|
||||||
expect(goToStub.calledWith('/account')).to.be.true;
|
expect(goToStub.withArgs('/account').called).to.be.true;
|
||||||
expect(goToStub.calledOnce).to.be.true;
|
expect(goToStub.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -175,7 +175,7 @@ describe('Login Controller unit test', function() {
|
|||||||
keychainMock.requestPrivateKeyDownload.returns(resolves(true));
|
keychainMock.requestPrivateKeyDownload.returns(resolves(true));
|
||||||
|
|
||||||
scope.init().then(function() {
|
scope.init().then(function() {
|
||||||
expect(goToStub.calledWith('/login-privatekey-download')).to.be.true;
|
expect(goToStub.withArgs('/login-privatekey-download').called).to.be.true;
|
||||||
expect(goToStub.calledOnce).to.be.true;
|
expect(goToStub.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -192,25 +192,7 @@ describe('Login Controller unit test', function() {
|
|||||||
keychainMock.requestPrivateKeyDownload.returns(resolves());
|
keychainMock.requestPrivateKeyDownload.returns(resolves());
|
||||||
|
|
||||||
scope.init().then(function() {
|
scope.init().then(function() {
|
||||||
expect(goToStub.calledWith('/login-new-device')).to.be.true;
|
expect(goToStub.withArgs('/login-new-device').called).to.be.true;
|
||||||
expect(goToStub.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should redirect to /login-new-device', function(done) {
|
|
||||||
authMock.init.returns(resolves());
|
|
||||||
authMock.getEmailAddress.returns(resolves({
|
|
||||||
emailAddress: emailAddress
|
|
||||||
}));
|
|
||||||
accountMock.init.returns(resolves({
|
|
||||||
publicKey: {
|
|
||||||
source: 'foo'
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
scope.init().then(function() {
|
|
||||||
expect(goToStub.calledWith('/login-initial')).to.be.true;
|
|
||||||
expect(goToStub.calledOnce).to.be.true;
|
expect(goToStub.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -224,7 +206,7 @@ describe('Login Controller unit test', function() {
|
|||||||
accountMock.init.returns(resolves({}));
|
accountMock.init.returns(resolves({}));
|
||||||
|
|
||||||
scope.init().then(function() {
|
scope.init().then(function() {
|
||||||
expect(goToStub.calledWith('/login-initial')).to.be.true;
|
expect(goToStub.withArgs('/login-initial').called).to.be.true;
|
||||||
expect(goToStub.calledOnce).to.be.true;
|
expect(goToStub.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -417,45 +417,6 @@ describe('Keychain DAO unit tests', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('get public keys by id', function() {
|
|
||||||
it('should fail', function(done) {
|
|
||||||
keychainDao.getPublicKeys([]).then(function(keys) {
|
|
||||||
expect(keys.length).to.equal(0);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail', function(done) {
|
|
||||||
lawnchairDaoStub.read.returns(rejects(42));
|
|
||||||
|
|
||||||
var ids = [{
|
|
||||||
_id: '12345'
|
|
||||||
}];
|
|
||||||
keychainDao.getPublicKeys(ids).catch(function(err) {
|
|
||||||
expect(err).to.exist;
|
|
||||||
expect(lawnchairDaoStub.read.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should work from local storage', function(done) {
|
|
||||||
lawnchairDaoStub.read.returns(resolves({
|
|
||||||
_id: '12345',
|
|
||||||
publicKey: 'asdf'
|
|
||||||
}));
|
|
||||||
|
|
||||||
var ids = [{
|
|
||||||
_id: '12345'
|
|
||||||
}];
|
|
||||||
keychainDao.getPublicKeys(ids).then(function(keys) {
|
|
||||||
expect(keys.length).to.equal(1);
|
|
||||||
expect(keys[0]._id).to.equal('12345');
|
|
||||||
expect(lawnchairDaoStub.read.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('get receiver public key', function() {
|
describe('get receiver public key', function() {
|
||||||
it('should fail due to error in lawnchair list', function(done) {
|
it('should fail due to error in lawnchair list', function(done) {
|
||||||
lawnchairDaoStub.list.returns(rejects(42));
|
lawnchairDaoStub.list.returns(rejects(42));
|
||||||
@ -598,6 +559,40 @@ describe('Keychain DAO unit tests', function() {
|
|||||||
expect(keys.privateKey).to.exist;
|
expect(keys.privateKey).to.exist;
|
||||||
expect(lawnchairDaoStub.list.calledOnce).to.be.true;
|
expect(lawnchairDaoStub.list.calledOnce).to.be.true;
|
||||||
expect(lawnchairDaoStub.read.calledTwice).to.be.true;
|
expect(lawnchairDaoStub.read.calledTwice).to.be.true;
|
||||||
|
expect(pubkeyDaoStub.getByUserId.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work if local key is from a source other than the whiteout key server', function(done) {
|
||||||
|
lawnchairDaoStub.list.returns(resolves([{
|
||||||
|
_id: '12345',
|
||||||
|
userId: testUser,
|
||||||
|
publicKey: 'asdf',
|
||||||
|
source: 'pgp.mit.edu'
|
||||||
|
}]));
|
||||||
|
pubkeyDaoStub.getByUserId.returns(resolves());
|
||||||
|
|
||||||
|
keychainDao.getUserKeyPair(testUser).then(function(keys) {
|
||||||
|
expect(keys).to.not.exist;
|
||||||
|
expect(lawnchairDaoStub.list.calledOnce).to.be.true;
|
||||||
|
expect(lawnchairDaoStub.read.called).to.be.false;
|
||||||
|
expect(pubkeyDaoStub.getByUserId.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work if cloud public key is from a source other than the whiteout key server', function(done) {
|
||||||
|
lawnchairDaoStub.list.returns(resolves());
|
||||||
|
pubkeyDaoStub.getByUserId.returns(resolves({
|
||||||
|
_id: '12345',
|
||||||
|
publicKey: 'asdf',
|
||||||
|
source: 'pgp.mit.edu'
|
||||||
|
}));
|
||||||
|
|
||||||
|
keychainDao.getUserKeyPair(testUser).then(function(keys) {
|
||||||
|
expect(keys).to.not.exist;
|
||||||
|
expect(pubkeyDaoStub.getByUserId.calledOnce).to.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user