Merge branch 'master' of github.com:whiteout-io/mail-html5

This commit is contained in:
Tankred Hase 2014-09-17 15:51:58 +02:00
commit ba9770b495
6 changed files with 103 additions and 21 deletions

View File

@ -61,9 +61,9 @@ define(function(require) {
$scope.checkServerForKey = function(callback) {
var keyParams = pgp.getKeyParams();
keychain.requestPrivateKeyDownload({
keychain.hasPrivateKey({
userId: keyParams.userId,
keyId: keyParams._id,
keyId: keyParams._id
}, function(err, privateKeySynced) {
if (err) {
$scope.onError(err);

View File

@ -641,6 +641,16 @@ define(function(require) {
this._privateKeyDao.requestDownload(options, callback);
};
/**
* Query if an encrypted private PGP key exists on the server without initializing the recovery procedure
* @param {String} options.userId The user's email address
* @param {String} options.keyId The private PGP key id
* @param {Function} callback(error)
*/
KeychainDAO.prototype.hasPrivateKey = function(options, callback) {
this._privateKeyDao.hasPrivateKey(options, callback);
};
/**
* Download the encrypted private PGP key from the server using the recovery token.
* @param {String} options.userId The user's email address

View File

@ -111,23 +111,51 @@ define(function() {
};
/**
* Request download for the encrypted private PGP key.
* Query if an encrypted private PGP key exists on the server without initializing the recovery procedure.
* @param {String} options.userId The user's email address
* @param {String} options.keyId The private PGP key id
* @param {Function} callback(error, found)
* @return {Boolean} weather the key was found on the server or not.
* @return {Boolean} whether the key was found on the server or not.
*/
PrivateKeyDAO.prototype.requestDownload = function(options, callback) {
var uri;
PrivateKeyDAO.prototype.hasPrivateKey = function(options, callback) {
if (!options.userId || !options.keyId) {
callback(new Error('Incomplete arguments!'));
return;
}
uri = '/privatekey/user/' + options.userId + '/key/' + options.keyId;
this._restDao.get({
uri: uri
uri: '/privatekey/user/' + options.userId + '/key/' + options.keyId + '?ignoreRecovery=true',
}, function(err) {
// 404: there is no encrypted private key on the server
if (err && err.code !== 200) {
callback(null, false);
return;
}
if (err) {
callback(err);
return;
}
callback(null, true);
});
};
/**
* Request download for the encrypted private PGP key.
* @param {String} options.userId The user's email address
* @param {String} options.keyId The private PGP key id
* @param {Function} callback(error, found)
* @return {Boolean} whether the key was found on the server or not.
*/
PrivateKeyDAO.prototype.requestDownload = function(options, callback) {
if (!options.userId || !options.keyId) {
callback(new Error('Incomplete arguments!'));
return;
}
this._restDao.get({
uri: '/privatekey/user/' + options.userId + '/key/' + options.keyId
}, function(err) {
// 404: there is no encrypted private key on the server
if (err && err.code !== 200) {

View File

@ -1202,7 +1202,8 @@ define(function(require) {
describe('requestPrivateKeyDownload', function() {
it('should work', function(done) {
var options = {
userId: testUser
userId: testUser,
keyId: 'someId'
};
privkeyDaoStub.requestDownload.withArgs(options).yields();
@ -1210,6 +1211,18 @@ define(function(require) {
});
});
describe('hasPrivateKey', function() {
it('should work', function(done) {
var options = {
userId: testUser,
keyId: 'someId'
};
privkeyDaoStub.hasPrivateKey.withArgs(options).yields();
keychainDao.hasPrivateKey(options, done);
});
});
describe('downloadPrivateKey', function() {
it('should work', function(done) {
var options = {

View File

@ -150,19 +150,44 @@ define(function(require) {
});
it('should work', function(done) {
var key = {
_id: '12345'
};
var keyId = '12345';
restDaoStub.get.withArgs({
uri: '/privatekey/user/' + emailAddress + '/key/' + key._id
uri: '/privatekey/user/' + emailAddress + '/key/' + keyId
}).yields();
privkeyDao.requestDownload({
userId: emailAddress,
keyId: key._id
}, function(err) {
keyId: keyId
}, function(err, found) {
expect(err).to.not.exist;
expect(found).to.be.true;
done();
});
});
});
describe('hasPrivateKey', function() {
it('should fail due to invalid args', function(done) {
privkeyDao.hasPrivateKey({}, function(err) {
expect(err).to.exist;
done();
});
});
it('should work', function(done) {
var keyId = '12345';
restDaoStub.get.withArgs({
uri: '/privatekey/user/' + emailAddress + '/key/' + keyId + '?ignoreRecovery=true'
}).yields();
privkeyDao.hasPrivateKey({
userId: emailAddress,
keyId: keyId
}, function(err, found) {
expect(err).to.not.exist;
expect(found).to.be.true;
done();
});
});

View File

@ -50,16 +50,16 @@ define(function(require) {
describe('checkServerForKey', function() {
var keyParams = {
userId: emailAddress,
_id: 'keyId'
_id: 'keyId',
};
it('should fail', function(done) {
pgpStub.getKeyParams.returns(keyParams);
keychainMock.requestPrivateKeyDownload.yields(42);
keychainMock.hasPrivateKey.yields(42);
scope.onError = function(err) {
expect(err).to.exist;
expect(keychainMock.requestPrivateKeyDownload.calledOnce).to.be.true;
expect(keychainMock.hasPrivateKey.calledOnce).to.be.true;
done();
};
@ -68,7 +68,10 @@ define(function(require) {
it('should return true', function(done) {
pgpStub.getKeyParams.returns(keyParams);
keychainMock.requestPrivateKeyDownload.yields(null, true);
keychainMock.hasPrivateKey.withArgs({
userId: keyParams.userId,
keyId: keyParams._id
}).yields(null, true);
scope.checkServerForKey(function(privateKeySynced) {
expect(privateKeySynced).to.be.true;
@ -78,7 +81,10 @@ define(function(require) {
it('should return undefined', function(done) {
pgpStub.getKeyParams.returns(keyParams);
keychainMock.requestPrivateKeyDownload.yields(null, false);
keychainMock.hasPrivateKey.withArgs({
userId: keyParams.userId,
keyId: keyParams._id
}).yields(null, false);
scope.checkServerForKey(function(privateKeySynced) {
expect(privateKeySynced).to.be.undefined;