From 13b83219864c0648ca6824090a29664094b89d3d Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 6 Oct 2021 13:24:57 +0200 Subject: [PATCH] Merge pull request #5375 from overleaf/jpa-401-failed-login [web] send a non success status code for failed logins in Server CE/Pro GitOrigin-RevId: 1aace4456c8602af26a362346bfc462e1476b0f7 --- .../AuthenticationController.js | 4 ++++ .../acceptance/src/AuthenticationTests.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/services/web/app/src/Features/Authentication/AuthenticationController.js b/services/web/app/src/Features/Authentication/AuthenticationController.js index 6064a88b98..a8641cdad5 100644 --- a/services/web/app/src/Features/Authentication/AuthenticationController.js +++ b/services/web/app/src/Features/Authentication/AuthenticationController.js @@ -72,6 +72,8 @@ const AuthenticationController = { if (info.redir != null) { return res.json({ redir: info.redir }) } else { + res.status(info.status || 200) + delete info.status return res.json({ message: info }) } } @@ -154,6 +156,7 @@ const AuthenticationController = { return done(null, null, { text: req.i18n.translate('to_many_login_requests_2_mins'), type: 'error', + status: 429, }) } AuthenticationManager.authenticate( @@ -172,6 +175,7 @@ const AuthenticationController = { done(null, false, { text: req.i18n.translate('email_or_password_wrong_try_again'), type: 'error', + status: 401, }) } } diff --git a/services/web/test/acceptance/src/AuthenticationTests.js b/services/web/test/acceptance/src/AuthenticationTests.js index 90e6b929e1..47e3fe7231 100644 --- a/services/web/test/acceptance/src/AuthenticationTests.js +++ b/services/web/test/acceptance/src/AuthenticationTests.js @@ -1,5 +1,6 @@ const { expect } = require('chai') const { ObjectId } = require('mongodb') +const Settings = require('@overleaf/settings') const User = require('./helpers/User').promises describe('Authentication', function () { @@ -71,4 +72,22 @@ describe('Authentication', function () { }) }) }) + + describe('failed login', function () { + beforeEach('fetchCsrfToken', async function () { + await user.getCsrfToken() + }) + it('should return a 401', async function () { + const { + response: { statusCode }, + } = await user.doRequest('POST', { + url: Settings.enableLegacyLogin ? '/login/legacy' : '/login', + json: { + email: user.email, + password: 'foo-bar-baz', + }, + }) + expect(statusCode).to.equal(401) + }) + }) })