1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 02:42:17 -05:00

Refactor admin and privatekey dao

This commit is contained in:
Tankred Hase 2014-12-11 19:07:04 +01:00
parent cc886ad402
commit 15b902acf6
4 changed files with 212 additions and 192 deletions

View File

@ -13,27 +13,24 @@ function Admin(adminRestDao) {
* @param {String} options.emailAddress The desired email address * @param {String} options.emailAddress The desired email address
* @param {String} options.password The password to be used for the account. * @param {String} options.password The password to be used for the account.
* @param {String} options.phone The user's mobile phone number (required for verification and password reset). * @param {String} options.phone The user's mobile phone number (required for verification and password reset).
* @param {Function} callback(error)
*/ */
Admin.prototype.createUser = function(options, callback) { Admin.prototype.createUser = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options.emailAddress || !options.password || !options.phone) {
throw new Error('Incomplete arguments!');
}
resolve();
if (!options.emailAddress || !options.password || !options.phone) { }).then(function() {
callback(new Error('Incomplete arguments!')); return self._restDao.post(options, '/user');
return;
}
uri = '/user'; }).catch(function(err) {
this._restDao.post(options, uri, function(err) {
if (err && err.code === 409) { if (err && err.code === 409) {
callback(new Error('User name is already taken!')); throw new Error('User name is already taken!');
return;
} else if (err) {
callback(new Error('Error creating new user!'));
return;
} }
callback(); throw new Error('Error creating new user!');
}); });
}; };
@ -41,23 +38,25 @@ Admin.prototype.createUser = function(options, callback) {
* Verify a user's phone number by confirming a token to the server. * Verify a user's phone number by confirming a token to the server.
* @param {String} options.emailAddress The desired email address * @param {String} options.emailAddress The desired email address
* @param {String} options.token The validation token. * @param {String} options.token The validation token.
* @param {Function} callback(error)
*/ */
Admin.prototype.validateUser = function(options, callback) { Admin.prototype.validateUser = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options.emailAddress || !options.token) { if (!options.emailAddress || !options.token) {
callback(new Error('Incomplete arguments!')); throw new Error('Incomplete arguments!');
return;
}
uri = '/user/validate';
this._restDao.post(options, uri, function(err) {
if (!err || (err && err.code === 202)) {
// success
callback();
} else {
callback(new Error('Validation failed!'));
} }
resolve();
}).then(function() {
var uri = '/user/validate';
return self._restDao.post(options, uri);
}).catch(function(err) {
if (err && err.code === 202) {
// success
return;
}
throw new Error('Validation failed!');
}); });
}; };

View File

@ -16,19 +16,20 @@ function PrivateKey(privateKeyRestDao) {
* Request registration of a new device by fetching registration session key. * Request registration of a new device by fetching registration session key.
* @param {String} options.userId The user's email address * @param {String} options.userId The user's email address
* @param {String} options.deviceName The device's memorable name * @param {String} options.deviceName The device's memorable name
* @param {Function} callback(error, regSessionKey)
* @return {Object} {encryptedRegSessionKey:[base64]} * @return {Object} {encryptedRegSessionKey:[base64]}
*/ */
PrivateKey.prototype.requestDeviceRegistration = function(options, callback) { PrivateKey.prototype.requestDeviceRegistration = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options.userId || !options.deviceName) {
throw new Error('Incomplete arguments!');
}
resolve();
if (!options.userId || !options.deviceName) { }).then(function() {
callback(new Error('Incomplete arguments!')); var uri = '/device/user/' + options.userId + '/devicename/' + options.deviceName;
return; return self._restDao.post(undefined, uri);
} });
uri = '/device/user/' + options.userId + '/devicename/' + options.deviceName;
this._restDao.post(undefined, uri, callback);
}; };
/** /**
@ -37,18 +38,19 @@ PrivateKey.prototype.requestDeviceRegistration = function(options, callback) {
* @param {String} options.deviceName The device's memorable name * @param {String} options.deviceName The device's memorable name
* @param {String} options.encryptedDeviceSecret The base64 encoded encrypted device secret * @param {String} options.encryptedDeviceSecret The base64 encoded encrypted device secret
* @param {String} options.iv The iv used for encryption * @param {String} options.iv The iv used for encryption
* @param {Function} callback(error)
*/ */
PrivateKey.prototype.uploadDeviceSecret = function(options, callback) { PrivateKey.prototype.uploadDeviceSecret = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options.userId || !options.deviceName || !options.encryptedDeviceSecret || !options.iv) {
throw new Error('Incomplete arguments!');
}
resolve();
if (!options.userId || !options.deviceName || !options.encryptedDeviceSecret || !options.iv) { }).then(function() {
callback(new Error('Incomplete arguments!')); var uri = '/device/user/' + options.userId + '/devicename/' + options.deviceName;
return; return self._restDao.put(options, uri);
} });
uri = '/device/user/' + options.userId + '/devicename/' + options.deviceName;
this._restDao.put(options, uri, callback);
}; };
// //
@ -58,19 +60,20 @@ PrivateKey.prototype.uploadDeviceSecret = function(options, callback) {
/** /**
* Request authSessionKeys required for upload the encrypted private PGP key. * Request authSessionKeys required for upload the encrypted private PGP key.
* @param {String} options.userId The user's email address * @param {String} options.userId The user's email address
* @param {Function} callback(error, authSessionKey)
* @return {Object} {sessionId, encryptedAuthSessionKey:[base64 encoded], encryptedChallenge:[base64 encoded]} * @return {Object} {sessionId, encryptedAuthSessionKey:[base64 encoded], encryptedChallenge:[base64 encoded]}
*/ */
PrivateKey.prototype.requestAuthSessionKey = function(options, callback) { PrivateKey.prototype.requestAuthSessionKey = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options.userId) {
throw new Error('Incomplete arguments!');
}
resolve();
if (!options.userId) { }).then(function() {
callback(new Error('Incomplete arguments!')); var uri = '/auth/user/' + options.userId;
return; return self._restDao.post(undefined, uri);
} });
uri = '/auth/user/' + options.userId;
this._restDao.post(undefined, uri, callback);
}; };
/** /**
@ -79,18 +82,19 @@ PrivateKey.prototype.requestAuthSessionKey = function(options, callback) {
* @param {String} options.encryptedChallenge The server's base64 encoded challenge encrypted using the authSessionKey * @param {String} options.encryptedChallenge The server's base64 encoded challenge encrypted using the authSessionKey
* @param {String} options.encryptedDeviceSecret The server's base64 encoded deviceSecret encrypted using the authSessionKey * @param {String} options.encryptedDeviceSecret The server's base64 encoded deviceSecret encrypted using the authSessionKey
* @param {String} options.iv The iv used for encryption * @param {String} options.iv The iv used for encryption
* @param {Function} callback(error)
*/ */
PrivateKey.prototype.verifyAuthentication = function(options, callback) { PrivateKey.prototype.verifyAuthentication = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options.userId || !options.sessionId || !options.encryptedChallenge || !options.encryptedDeviceSecret || !options.iv) {
throw new Error('Incomplete arguments!');
}
resolve();
if (!options.userId || !options.sessionId || !options.encryptedChallenge || !options.encryptedDeviceSecret || !options.iv) { }).then(function() {
callback(new Error('Incomplete arguments!')); var uri = '/auth/user/' + options.userId + '/session/' + options.sessionId;
return; return self._restDao.put(options, uri);
} });
uri = '/auth/user/' + options.userId + '/session/' + options.sessionId;
this._restDao.put(options, uri, callback);
}; };
/** /**
@ -99,48 +103,50 @@ PrivateKey.prototype.verifyAuthentication = function(options, callback) {
* @param {String} options.userId The user's email address * @param {String} options.userId The user's email address
* @param {String} options.encryptedPrivateKey The base64 encoded encrypted private PGP key * @param {String} options.encryptedPrivateKey The base64 encoded encrypted private PGP key
* @param {String} options.sessionId The session id * @param {String} options.sessionId The session id
* @param {Function} callback(error)
*/ */
PrivateKey.prototype.upload = function(options, callback) { PrivateKey.prototype.upload = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options._id || !options.userId || !options.encryptedPrivateKey || !options.sessionId || !options.salt || !options.iv) {
throw new Error('Incomplete arguments!');
}
resolve();
if (!options._id || !options.userId || !options.encryptedPrivateKey || !options.sessionId || !options.salt || !options.iv) { }).then(function() {
callback(new Error('Incomplete arguments!')); var uri = '/privatekey/user/' + options.userId + '/session/' + options.sessionId;
return; return self._restDao.post(options, uri);
} });
uri = '/privatekey/user/' + options.userId + '/session/' + options.sessionId;
this._restDao.post(options, uri, callback);
}; };
/** /**
* Query if an encrypted private PGP key exists on the server without initializing the recovery procedure. * 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.userId The user's email address
* @param {String} options.keyId The private PGP key id * @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. * @return {Boolean} whether the key was found on the server or not.
*/ */
PrivateKey.prototype.hasPrivateKey = function(options, callback) { PrivateKey.prototype.hasPrivateKey = function(options) {
if (!options.userId || !options.keyId) { var self = this;
callback(new Error('Incomplete arguments!')); return new Promise(function(resolve) {
return; if (!options.userId || !options.keyId) {
} throw new Error('Incomplete arguments!');
}
resolve();
this._restDao.get({ }).then(function() {
uri: '/privatekey/user/' + options.userId + '/key/' + options.keyId + '?ignoreRecovery=true', return self._restDao.get({
}, function(err) { uri: '/privatekey/user/' + options.userId + '/key/' + options.keyId + '?ignoreRecovery=true',
});
}).then(function() {
return true;
}).catch(function(err) {
// 404: there is no encrypted private key on the server // 404: there is no encrypted private key on the server
if (err && err.code !== 200) { if (err.code && err.code !== 200) {
callback(null, false); return false;
return;
} }
if (err) { throw err;
callback(err);
return;
}
callback(null, true);
}); });
}; };
@ -148,30 +154,31 @@ PrivateKey.prototype.hasPrivateKey = function(options, callback) {
* Request download for the encrypted private PGP key. * Request download for the encrypted private PGP key.
* @param {String} options.userId The user's email address * @param {String} options.userId The user's email address
* @param {String} options.keyId The private PGP key id * @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. * @return {Boolean} whether the key was found on the server or not.
*/ */
PrivateKey.prototype.requestDownload = function(options, callback) { PrivateKey.prototype.requestDownload = function(options) {
if (!options.userId || !options.keyId) { var self = this;
callback(new Error('Incomplete arguments!')); return new Promise(function(resolve) {
return; if (!options.userId || !options.keyId) {
} throw new Error('Incomplete arguments!');
}
resolve();
this._restDao.get({ }).then(function() {
uri: '/privatekey/user/' + options.userId + '/key/' + options.keyId return self._restDao.get({
}, function(err) { uri: '/privatekey/user/' + options.userId + '/key/' + options.keyId
});
}).then(function() {
return true;
}).catch(function(err) {
// 404: there is no encrypted private key on the server // 404: there is no encrypted private key on the server
if (err && err.code !== 200) { if (err.code && err.code !== 200) {
callback(null, false); return false;
return;
} }
if (err) { throw err;
callback(err);
return;
}
callback(null, true);
}); });
}; };
@ -180,19 +187,19 @@ PrivateKey.prototype.requestDownload = function(options, callback) {
* @param {String} options.userId The user's email address * @param {String} options.userId The user's email address
* @param {String} options.keyId The private key id * @param {String} options.keyId The private key id
* @param {String} options.recoveryToken The token proving the user own the email account * @param {String} options.recoveryToken The token proving the user own the email account
* @param {Function} callback(error, encryptedPrivateKey)
* @return {Object} {_id:[hex encoded capital 16 char key id], encryptedPrivateKey:[base64 encoded], encryptedUserId: [base64 encoded]} * @return {Object} {_id:[hex encoded capital 16 char key id], encryptedPrivateKey:[base64 encoded], encryptedUserId: [base64 encoded]}
*/ */
PrivateKey.prototype.download = function(options, callback) { PrivateKey.prototype.download = function(options) {
var uri; var self = this;
return new Promise(function(resolve) {
if (!options.userId || !options.keyId || !options.recoveryToken) {
throw new Error('Incomplete arguments!');
}
resolve();
if (!options.userId || !options.keyId || !options.recoveryToken) { }).then(function() {
callback(new Error('Incomplete arguments!')); return self._restDao.get({
return; uri: '/privatekey/user/' + options.userId + '/key/' + options.keyId + '/recovery/' + options.recoveryToken
} });
});
uri = '/privatekey/user/' + options.userId + '/key/' + options.keyId + '/recovery/' + options.recoveryToken;
this._restDao.get({
uri: uri
}, callback);
}; };

View File

@ -23,7 +23,7 @@ describe('Admin DAO unit tests', function() {
emailAddress: emailAddress emailAddress: emailAddress
}; };
adminDao.createUser(opt, function(err) { adminDao.createUser(opt).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
@ -36,11 +36,11 @@ describe('Admin DAO unit tests', function() {
phone: '12345' phone: '12345'
}; };
restDaoStub.post.withArgs(opt, '/user').yields({ restDaoStub.post.withArgs(opt, '/user').returns(rejects({
code: 409 code: 409
}); }));
adminDao.createUser(opt, function(err) { adminDao.createUser(opt).catch(function(err) {
expect(err.message).to.contain('already taken'); expect(err.message).to.contain('already taken');
expect(restDaoStub.post.calledOnce).to.be.true; expect(restDaoStub.post.calledOnce).to.be.true;
done(); done();
@ -54,9 +54,9 @@ describe('Admin DAO unit tests', function() {
phone: '12345' phone: '12345'
}; };
restDaoStub.post.withArgs(opt, '/user').yields(new Error()); restDaoStub.post.withArgs(opt, '/user').returns(rejects(new Error()));
adminDao.createUser(opt, function(err) { adminDao.createUser(opt).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
expect(restDaoStub.post.calledOnce).to.be.true; expect(restDaoStub.post.calledOnce).to.be.true;
done(); done();
@ -70,10 +70,9 @@ describe('Admin DAO unit tests', function() {
phone: '12345' phone: '12345'
}; };
restDaoStub.post.withArgs(opt, '/user').yields(); restDaoStub.post.withArgs(opt, '/user').returns(resolves());
adminDao.createUser(opt, function(err) { adminDao.createUser(opt).then(function() {
expect(err).to.not.exist;
expect(restDaoStub.post.calledOnce).to.be.true; expect(restDaoStub.post.calledOnce).to.be.true;
done(); done();
}); });
@ -86,7 +85,7 @@ describe('Admin DAO unit tests', function() {
emailAddress: emailAddress emailAddress: emailAddress
}; };
adminDao.validateUser(opt, function(err) { adminDao.validateUser(opt).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
@ -98,9 +97,9 @@ describe('Admin DAO unit tests', function() {
token: 'H45Z6D' token: 'H45Z6D'
}; };
restDaoStub.post.withArgs(opt, '/user/validate').yields(new Error()); restDaoStub.post.withArgs(opt, '/user/validate').returns(rejects(new Error()));
adminDao.validateUser(opt, function(err) { adminDao.validateUser(opt).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
expect(restDaoStub.post.calledOnce).to.be.true; expect(restDaoStub.post.calledOnce).to.be.true;
done(); done();
@ -113,10 +112,9 @@ describe('Admin DAO unit tests', function() {
token: 'H45Z6D' token: 'H45Z6D'
}; };
restDaoStub.post.withArgs(opt, '/user/validate').yields(); restDaoStub.post.withArgs(opt, '/user/validate').returns(resolves());
adminDao.validateUser(opt, function(err) { adminDao.validateUser(opt).then(function() {
expect(err).to.not.exist;
expect(restDaoStub.post.calledOnce).to.be.true; expect(restDaoStub.post.calledOnce).to.be.true;
done(); done();
}); });
@ -128,12 +126,11 @@ describe('Admin DAO unit tests', function() {
token: 'H45Z6D' token: 'H45Z6D'
}; };
restDaoStub.post.withArgs(opt, '/user/validate').yields({ restDaoStub.post.withArgs(opt, '/user/validate').returns(rejects({
code: 202 code: 202
}); }));
adminDao.validateUser(opt, function(err) { adminDao.validateUser(opt).then(function() {
expect(err).to.not.exist;
expect(restDaoStub.post.calledOnce).to.be.true; expect(restDaoStub.post.calledOnce).to.be.true;
done(); done();
}); });

View File

@ -19,23 +19,21 @@ describe('Private Key DAO unit tests', function() {
describe('requestDeviceRegistration', function() { describe('requestDeviceRegistration', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.requestDeviceRegistration({}, function(err, sessionKey) { privkeyDao.requestDeviceRegistration({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
expect(sessionKey).to.not.exist;
done(); done();
}); });
}); });
it('should work', function(done) { it('should work', function(done) {
restDaoStub.post.yields(null, { restDaoStub.post.returns(resolves({
encryptedRegSessionKey: 'asdf' encryptedRegSessionKey: 'asdf'
}); }));
privkeyDao.requestDeviceRegistration({ privkeyDao.requestDeviceRegistration({
userId: emailAddress, userId: emailAddress,
deviceName: deviceName deviceName: deviceName
}, function(err, sessionKey) { }).then(function(sessionKey) {
expect(err).to.not.exist;
expect(sessionKey).to.exist; expect(sessionKey).to.exist;
done(); done();
}); });
@ -44,50 +42,44 @@ describe('Private Key DAO unit tests', function() {
describe('uploadDeviceSecret', function() { describe('uploadDeviceSecret', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.uploadDeviceSecret({}, function(err) { privkeyDao.uploadDeviceSecret({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
}); });
it('should work', function(done) { it('should work', function(done) {
restDaoStub.put.yields(); restDaoStub.put.returns(resolves());
privkeyDao.uploadDeviceSecret({ privkeyDao.uploadDeviceSecret({
userId: emailAddress, userId: emailAddress,
deviceName: deviceName, deviceName: deviceName,
encryptedDeviceSecret: 'asdf', encryptedDeviceSecret: 'asdf',
iv: 'iv' iv: 'iv'
}, function(err) { }).then(done);
expect(err).to.not.exist;
done();
});
}); });
}); });
describe('requestAuthSessionKey', function() { describe('requestAuthSessionKey', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.requestAuthSessionKey({}, function(err) { privkeyDao.requestAuthSessionKey({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
}); });
it('should work', function(done) { it('should work', function(done) {
restDaoStub.post.withArgs(undefined, '/auth/user/' + emailAddress).yields(); restDaoStub.post.withArgs(undefined, '/auth/user/' + emailAddress).returns(resolves());
privkeyDao.requestAuthSessionKey({ privkeyDao.requestAuthSessionKey({
userId: emailAddress userId: emailAddress
}, function(err) { }).then(done);
expect(err).to.not.exist;
done();
});
}); });
}); });
describe('verifyAuthentication', function() { describe('verifyAuthentication', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.verifyAuthentication({}, function(err) { privkeyDao.verifyAuthentication({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
@ -104,18 +96,15 @@ describe('Private Key DAO unit tests', function() {
iv: ' iv' iv: ' iv'
}; };
restDaoStub.put.withArgs(options, '/auth/user/' + emailAddress + '/session/' + sessionId).yields(); restDaoStub.put.withArgs(options, '/auth/user/' + emailAddress + '/session/' + sessionId).returns(resolves());
privkeyDao.verifyAuthentication(options, function(err) { privkeyDao.verifyAuthentication(options).then(done);
expect(err).to.not.exist;
done();
});
}); });
}); });
describe('upload', function() { describe('upload', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.upload({}, function(err) { privkeyDao.upload({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
@ -131,35 +120,49 @@ describe('Private Key DAO unit tests', function() {
iv: 'iv' iv: 'iv'
}; };
restDaoStub.post.withArgs(options, '/privatekey/user/' + emailAddress + '/session/' + options.sessionId).yields(); restDaoStub.post.withArgs(options, '/privatekey/user/' + emailAddress + '/session/' + options.sessionId).returns(resolves());
privkeyDao.upload(options, function(err) { privkeyDao.upload(options).then(done);
expect(err).to.not.exist;
done();
});
}); });
}); });
describe('requestDownload', function() { describe('requestDownload', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.requestDownload({}, function(err) { privkeyDao.requestDownload({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
}); });
it('should not find a key', function(done) {
var keyId = '12345';
restDaoStub.get.withArgs({
uri: '/privatekey/user/' + emailAddress + '/key/' + keyId
}).returns(rejects({
code: 404
}));
privkeyDao.requestDownload({
userId: emailAddress,
keyId: keyId
}).then(function(found) {
expect(found).to.be.false;
done();
});
});
it('should work', function(done) { it('should work', function(done) {
var keyId = '12345'; var keyId = '12345';
restDaoStub.get.withArgs({ restDaoStub.get.withArgs({
uri: '/privatekey/user/' + emailAddress + '/key/' + keyId uri: '/privatekey/user/' + emailAddress + '/key/' + keyId
}).yields(); }).returns(resolves());
privkeyDao.requestDownload({ privkeyDao.requestDownload({
userId: emailAddress, userId: emailAddress,
keyId: keyId keyId: keyId
}, function(err, found) { }).then(function(found) {
expect(err).to.not.exist;
expect(found).to.be.true; expect(found).to.be.true;
done(); done();
}); });
@ -168,24 +171,41 @@ describe('Private Key DAO unit tests', function() {
describe('hasPrivateKey', function() { describe('hasPrivateKey', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.hasPrivateKey({}, function(err) { privkeyDao.hasPrivateKey({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
}); });
it('should not find a key', function(done) {
var keyId = '12345';
restDaoStub.get.withArgs({
uri: '/privatekey/user/' + emailAddress + '/key/' + keyId + '?ignoreRecovery=true'
}).returns(rejects({
code: 404
}));
privkeyDao.hasPrivateKey({
userId: emailAddress,
keyId: keyId
}).then(function(found) {
expect(found).to.be.false;
done();
});
});
it('should work', function(done) { it('should work', function(done) {
var keyId = '12345'; var keyId = '12345';
restDaoStub.get.withArgs({ restDaoStub.get.withArgs({
uri: '/privatekey/user/' + emailAddress + '/key/' + keyId + '?ignoreRecovery=true' uri: '/privatekey/user/' + emailAddress + '/key/' + keyId + '?ignoreRecovery=true'
}).yields(); }).returns(resolves());
privkeyDao.hasPrivateKey({ privkeyDao.hasPrivateKey({
userId: emailAddress, userId: emailAddress,
keyId: keyId keyId: keyId
}, function(err, found) { }).then(function(found) {
expect(err).to.not.exist;
expect(found).to.be.true; expect(found).to.be.true;
done(); done();
}); });
@ -194,7 +214,7 @@ describe('Private Key DAO unit tests', function() {
describe('download', function() { describe('download', function() {
it('should fail due to invalid args', function(done) { it('should fail due to invalid args', function(done) {
privkeyDao.download({}, function(err) { privkeyDao.download({}).catch(function(err) {
expect(err).to.exist; expect(err).to.exist;
done(); done();
}); });
@ -207,16 +227,13 @@ describe('Private Key DAO unit tests', function() {
restDaoStub.get.withArgs({ restDaoStub.get.withArgs({
uri: '/privatekey/user/' + emailAddress + '/key/' + key._id + '/recovery/token' uri: '/privatekey/user/' + emailAddress + '/key/' + key._id + '/recovery/token'
}).yields(); }).returns(resolves());
privkeyDao.download({ privkeyDao.download({
userId: emailAddress, userId: emailAddress,
keyId: key._id, keyId: key._id,
recoveryToken: 'token' recoveryToken: 'token'
}, function(err) { }).then(done);
expect(err).to.not.exist;
done();
});
}); });
}); });