From 5960f92395e81cc851d4536325bee72ba930de3f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 28 Dec 2017 16:45:32 +0100 Subject: [PATCH] Fix user tests --- server/middlewares/oauth.ts | 15 +++++++++++++-- server/tests/api/users/users.ts | 8 ++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index 9976993e0..41a3fb718 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts @@ -15,7 +15,7 @@ function authenticate (req: express.Request, res: express.Response, next: expres if (err) { return res.status(err.status) .json({ - error: 'Authentication failed.', + error: 'Token is invalid.', code: err.name }) .end() @@ -26,7 +26,18 @@ function authenticate (req: express.Request, res: express.Response, next: expres } function token (req: express.Request, res: express.Response, next: express.NextFunction) { - return oAuthServer.token()(req, res, next) + return oAuthServer.token()(req, res, err => { + if (err) { + return res.status(err.status) + .json({ + error: 'Authentication failed.', + code: err.name + }) + .end() + } + + return next() + }) } // --------------------------------------------------------------------------- diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index b7ec3bc0f..a13807b5c 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -42,7 +42,7 @@ describe('Test users', function () { expect(res.body.error) .to - .equal('invalid_client') + .equal('Authentication failed.') }) it('Should not login with an invalid client secret', async function () { @@ -51,7 +51,7 @@ describe('Test users', function () { expect(res.body.error) .to - .equal('invalid_client') + .equal('Authentication failed.') }) it('Should not login with an invalid username', async function () { @@ -60,7 +60,7 @@ describe('Test users', function () { expect(res.body.error) .to - .equal('invalid_grant') + .equal('Authentication failed.') }) it('Should not login with an invalid password', async function () { @@ -69,7 +69,7 @@ describe('Test users', function () { expect(res.body.error) .to - .equal('invalid_grant') + .equal('Authentication failed.') }) it('Should not be able to upload a video', async function () {