mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 08:52:15 -05:00
Merge pull request #112 from whiteout-io/dev/WO-531
[WO-531] introduce option to query key w/o starting recovery
This commit is contained in:
commit
0aff411c3f
@ -60,9 +60,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);
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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 = {
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user