From 35bd0aeb6099890a5d5dd66130487cda36a96d4e Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Mon, 19 Jun 2017 15:37:58 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Fix=20error=20message=20for?= =?UTF-8?q?=20login=20when=20password=20wrong=20(#8594)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #8565 - isPasswordCorrect fn returns a specific error, which we simply forward - no need to wrap a custom error into a new custom error - the rule is always: if you are using a Ghost unit/function, you can expect that this unit returns a custom error --- core/server/models/user.js | 7 ++----- core/test/functional/routes/api/authentication_spec.js | 4 ++-- core/test/functional/routes/api/spam_prevention_spec.js | 6 +++--- core/test/integration/model/model_users_spec.js | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/core/server/models/user.js b/core/server/models/user.js index 32780a1754..37f173678c 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -673,11 +673,7 @@ User = ghostBookshelf.Model.extend({ }); }) .catch(function onError(err) { - return Promise.reject(new errors.UnauthorizedError({ - err: err, - context: i18n.t('errors.models.user.incorrectPassword'), - help: i18n.t('errors.models.user.userUpdateError.help') - })); + return Promise.reject(err); }); }, function handleError(error) { if (error.message === 'NotFound' || error.message === 'EmptyResponse') { @@ -705,6 +701,7 @@ User = ghostBookshelf.Model.extend({ } return Promise.reject(new errors.ValidationError({ + context: i18n.t('errors.models.user.incorrectPassword'), message: i18n.t('errors.models.user.incorrectPassword'), help: i18n.t('errors.models.user.userUpdateError.help'), code: 'PASSWORD_INCORRECT' diff --git a/core/test/functional/routes/api/authentication_spec.js b/core/test/functional/routes/api/authentication_spec.js index 9c7da89f1f..dcbd21ab29 100644 --- a/core/test/functional/routes/api/authentication_spec.js +++ b/core/test/functional/routes/api/authentication_spec.js @@ -120,14 +120,14 @@ describe('Authentication API', function () { client_secret: 'not_available' }).expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .expect(401) + .expect(422) .end(function (err, res) { if (err) { return done(err); } var jsonResponse = res.body; should.exist(jsonResponse.errors[0].errorType); - jsonResponse.errors[0].errorType.should.eql('UnauthorizedError'); + jsonResponse.errors[0].errorType.should.eql('ValidationError'); done(); }); }); diff --git a/core/test/functional/routes/api/spam_prevention_spec.js b/core/test/functional/routes/api/spam_prevention_spec.js index 162bef2da2..54da72b6e8 100644 --- a/core/test/functional/routes/api/spam_prevention_spec.js +++ b/core/test/functional/routes/api/spam_prevention_spec.js @@ -98,7 +98,7 @@ describe('Spam Prevention API', function () { client_secret: 'not_available' }) .expect('Content-Type', /json/) - .expect(401) + .expect(422) .end(function (err) { if (err) { return done(err); @@ -155,7 +155,7 @@ describe('Spam Prevention API', function () { client_id: 'ghost-admin', client_secret: 'not_available' }).expect('Content-Type', /json/) - .expect(401) + .expect(422) .end(function (err) { if (err) { return done(err); @@ -220,7 +220,7 @@ describe('Spam Prevention API', function () { client_id: 'ghost-admin', client_secret: 'not_available' }).expect('Content-Type', /json/) - .expect(401) + .expect(422) .end(function (err) { if (err) { return done(err); diff --git a/core/test/integration/model/model_users_spec.js b/core/test/integration/model/model_users_spec.js index e33b87b07f..35d73b3bc0 100644 --- a/core/test/integration/model/model_users_spec.js +++ b/core/test/integration/model/model_users_spec.js @@ -628,7 +628,7 @@ describe('User Model', function run() { return UserModel.check(object).then(userWasLoggedIn) .catch(function checkError(error) { should.exist(error); - error.errorType.should.equal('UnauthorizedError'); + error.errorType.should.equal('ValidationError'); }); }); });