diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js index 1c61756da8..c9549a1def 100644 --- a/src/controllers/accounts/edit.js +++ b/src/controllers/accounts/edit.js @@ -63,7 +63,7 @@ editController.email = function (req, res, next) { function renderRoute(name, req, res, next) { getUserData(req, next, function (err, userData) { - if (err) { + if (err || !userData) { return next(err); } if ((name === 'username' && userData['username:disableEdit']) || (name === 'email' && userData['email:disableEdit'])) { @@ -94,7 +94,7 @@ function getUserData(req, next, callback) { function (data, next) { userData = data; if (!userData) { - return next(); + return callback(); } db.getObjectField('user:' + userData.uid, 'password', next); } diff --git a/test/controllers-admin.js b/test/controllers-admin.js index 55abe69127..487e4ed0fb 100644 --- a/test/controllers-admin.js +++ b/test/controllers-admin.js @@ -126,6 +126,14 @@ describe('Admin Controllers', function () { }); }); + it('should 404 for edit/email page if user does not exist', function (done) { + request(nconf.get('url') + '/api/user/doesnotexist/edit/email', {jar: jar, json: true}, function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 404); + done(); + }); + }); + it('should load /admin/general/homepage', function (done) { request(nconf.get('url') + '/api/admin/general/homepage', {jar: jar, json: true}, function (err, res, body) { assert.ifError(err); diff --git a/test/user.js b/test/user.js index bf0649bb7d..114c4dfdc3 100644 --- a/test/user.js +++ b/test/user.js @@ -524,6 +524,24 @@ describe('User', function () { }); }); + it('should load edit page', function (done) { + request(nconf.get('url') + '/api/user/updatedagain/edit', {jar: jar, json: true}, function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + + it('should load edit/email page', function (done) { + request(nconf.get('url') + '/api/user/updatedagain/edit/email', {jar: jar, json: true}, function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + it('should load user\'s groups page', function (done) { groups.create({ name: 'Test',