Fix user tests
authorChocobozzz <me@florianbigard.com>
Thu, 28 Dec 2017 15:45:32 +0000 (16:45 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 28 Dec 2017 15:45:32 +0000 (16:45 +0100)
server/middlewares/oauth.ts
server/tests/api/users/users.ts

index 9976993e03b8a08919ae3fe12fc8b74ae170369d..41a3fb71894133d759f867a288bc930ea0e62362 100644 (file)
@@ -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()
+  })
 }
 
 // ---------------------------------------------------------------------------
index b7ec3bc0fd8dca644766b08b081062f0065cd752..a13807b5c07a8eec32e1c69901c1f63c74b679e6 100644 (file)
@@ -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 () {