Set application's id property only if it's empty.

Fix `Application.resetKeys()` to reset instance id only if it is not
already set. This fixes a bug where each call of resetKeys created
a new instance.
This commit is contained in:
wusuopu 2015-10-08 13:10:14 +08:00 committed by Miroslav Bajtoš
parent 34fca67ee0
commit ce48521efb
2 changed files with 27 additions and 1 deletions

View File

@ -92,7 +92,9 @@ module.exports = function(Application) {
var app = ctx.instance; var app = ctx.instance;
app.created = app.modified = new Date(); app.created = app.modified = new Date();
app.id = generateKey('id', 'md5'); if (!app.id) {
app.id = generateKey('id', 'md5');
}
app.clientKey = generateKey('client'); app.clientKey = generateKey('client');
app.javaScriptKey = generateKey('javaScript'); app.javaScriptKey = generateKey('javaScript');
app.restApiKey = generateKey('restApi'); app.restApiKey = generateKey('restApi');

View File

@ -174,6 +174,30 @@ describe('Application', function() {
}); });
}); });
it('Reset keys without create a new instance', function(done) {
Application.resetKeys(registeredApp.id, function(err, result) {
var app = result;
assert(app.id);
assert(app.id === registeredApp.id);
registeredApp = app;
done(err, result);
});
});
it('Reset keys without create a new instance - promise variant', function(done) {
Application.resetKeys(registeredApp.id)
.then(function(result) {
var app = result;
assert(app.id);
assert(app.id === registeredApp.id);
registeredApp = app;
done();
})
.catch(function(err) {
done(err);
});
});
it('Authenticate with application id & clientKey', function(done) { it('Authenticate with application id & clientKey', function(done) {
Application.authenticate(registeredApp.id, registeredApp.clientKey, Application.authenticate(registeredApp.id, registeredApp.clientKey,
function(err, result) { function(err, result) {