From 81628e5069e0168b11857f276fe8e03b93102dde Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 2 Jun 2021 14:28:30 +0200 Subject: refactor error code values for URI compatibility --- server/middlewares/validators/videos/videos.ts | 6 +++--- server/tests/api/users/users.ts | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'server') diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index fd0e543f1..64e09234e 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -252,7 +252,7 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R return res.fail({ status: HttpStatusCode.FORBIDDEN_403, - message: 'Cannot get this video regarding follow constraints.', + message: 'Cannot get this video regarding follow constraints', type: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS, data: { originUrl: video.url @@ -285,11 +285,11 @@ const videosCustomGetValidator = ( const user = res.locals.oauth ? res.locals.oauth.token.User : null - // Only the owner or a user that have blacklist rights can see the video + // Only the owner or a user that have blocklist rights can see the video if (!user || !user.canGetVideo(video)) { return res.fail({ status: HttpStatusCode.FORBIDDEN_403, - message: 'Cannot get this private/internal or blacklisted video.' + message: 'Cannot get this private/internal or blocklisted video' }) } diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 464c11d34..87ba775f6 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' -import { CustomConfig } from '@shared/models/server' +import { CustomConfig, OAuth2ErrorCode } from '@shared/models/server' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { addVideoCommentThread, @@ -93,20 +93,20 @@ describe('Test users', function () { const client = { id: 'client', secret: server.client.secret } const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_client') + expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) expect(res.body.error).to.contain('client is invalid') expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain('invalid_client') + expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) }) it('Should not login with an invalid client secret', async function () { const client = { id: server.client.id, secret: 'coucou' } const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_client') + expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) expect(res.body.error).to.contain('client is invalid') expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain('invalid_client') + expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) }) }) @@ -116,20 +116,20 @@ describe('Test users', function () { const user = { username: 'captain crochet', password: server.user.password } const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_grant') + expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) expect(res.body.error).to.contain('credentials are invalid') expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain('invalid_grant') + expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) }) it('Should not login with an invalid password', async function () { const user = { username: server.user.username, password: 'mew_three' } const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_grant') + expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) expect(res.body.error).to.contain('credentials are invalid') expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain('invalid_grant') + expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) }) it('Should not be able to upload a video', async function () { -- cgit v1.2.3