Merge pull request #1716 from wusuopu/feature/fix-issue-1689

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

Close #1716
Fix #1689
This commit is contained in:
Miroslav Bajtoš 2015-10-12 11:25:03 +02:00
commit 14e6ec554a
2 changed files with 27 additions and 1 deletions

View File

@ -92,7 +92,9 @@ module.exports = function(Application) {
var app = ctx.instance;
app.created = app.modified = new Date();
app.id = generateKey('id', 'md5');
if (!app.id) {
app.id = generateKey('id', 'md5');
}
app.clientKey = generateKey('client');
app.javaScriptKey = generateKey('javaScript');
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) {
Application.authenticate(registeredApp.id, registeredApp.clientKey,
function(err, result) {