2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2017-09-22 09:13:43 +02:00
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
|
|
|
|
import {
|
2019-04-24 15:10:37 +02:00
|
|
|
cleanupTests,
|
2018-08-13 16:57:13 +02:00
|
|
|
createUser,
|
2019-01-10 15:39:51 +01:00
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
|
|
|
getBlacklistedVideosList,
|
|
|
|
getVideo,
|
|
|
|
getVideoWithToken,
|
2018-08-13 16:57:13 +02:00
|
|
|
makePostBodyRequest,
|
|
|
|
makePutBodyRequest,
|
|
|
|
removeVideoFromBlacklist,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
uploadVideo,
|
2020-01-31 16:56:52 +01:00
|
|
|
userLogin,
|
|
|
|
waitJobs
|
2019-04-15 15:26:15 +02:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-10-29 17:48:31 +01:00
|
|
|
import {
|
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination
|
2019-04-15 15:26:15 +02:00
|
|
|
} from '../../../../shared/extra-utils/requests/check-api-params'
|
2020-01-31 16:56:52 +01:00
|
|
|
import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
|
2018-08-14 09:16:32 +02:00
|
|
|
import { expect } from 'chai'
|
2020-12-07 14:32:36 +01:00
|
|
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
2017-09-22 09:13:43 +02:00
|
|
|
|
|
|
|
describe('Test video blacklist API validators', function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
let servers: ServerInfo[]
|
2018-08-13 16:57:13 +02:00
|
|
|
let notBlacklistedVideoId: number
|
2019-01-10 15:39:51 +01:00
|
|
|
let remoteVideoUUID: string
|
2018-08-14 09:16:32 +02:00
|
|
|
let userAccessToken1 = ''
|
|
|
|
let userAccessToken2 = ''
|
2017-09-22 09:13:43 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2019-01-10 15:39:51 +01:00
|
|
|
servers = await flushAndRunMultipleServers(2)
|
2017-09-22 09:13:43 +02:00
|
|
|
|
2019-01-10 15:39:51 +01:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
2017-09-22 09:13:43 +02:00
|
|
|
|
2018-08-14 09:16:32 +02:00
|
|
|
{
|
|
|
|
const username = 'user1'
|
|
|
|
const password = 'my super password'
|
2020-01-31 16:56:52 +01:00
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
|
2019-01-10 15:39:51 +01:00
|
|
|
userAccessToken1 = await userLogin(servers[0], { username, password })
|
2018-08-14 09:16:32 +02:00
|
|
|
}
|
2017-09-22 09:13:43 +02:00
|
|
|
|
2018-08-13 16:57:13 +02:00
|
|
|
{
|
2018-08-14 09:16:32 +02:00
|
|
|
const username = 'user2'
|
|
|
|
const password = 'my super password'
|
2020-01-31 16:56:52 +01:00
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
|
2019-01-10 15:39:51 +01:00
|
|
|
userAccessToken2 = await userLogin(servers[0], { username, password })
|
2018-08-14 09:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-01-10 15:39:51 +01:00
|
|
|
const res = await uploadVideo(servers[0].url, userAccessToken1, {})
|
|
|
|
servers[0].video = res.body.video
|
2018-08-13 16:57:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-01-10 15:39:51 +01:00
|
|
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
|
2018-08-13 16:57:13 +02:00
|
|
|
notBlacklistedVideoId = res.body.video.uuid
|
|
|
|
}
|
2019-01-10 15:39:51 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
|
|
|
|
remoteVideoUUID = res.body.video.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When adding a video in blacklist', function () {
|
|
|
|
const basePath = '/api/v1/videos/'
|
|
|
|
|
|
|
|
it('Should fail with nothing', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2017-09-22 09:13:43 +02:00
|
|
|
const fields = {}
|
2019-01-10 15:39:51 +01:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a wrong video', async function () {
|
|
|
|
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
|
|
|
const fields = {}
|
2019-01-10 15:39:51 +01:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2017-12-28 16:26:28 +01:00
|
|
|
const fields = {}
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2017-12-28 16:26:28 +01:00
|
|
|
const fields = {}
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path,
|
|
|
|
token: userAccessToken2,
|
|
|
|
fields,
|
|
|
|
statusCodeExpected: HttpStatusCode.FORBIDDEN_403
|
|
|
|
})
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
2018-08-13 16:57:13 +02:00
|
|
|
it('Should fail with an invalid reason', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
2018-08-13 16:57:13 +02:00
|
|
|
const fields = { reason: 'a'.repeat(305) }
|
|
|
|
|
2019-01-10 15:39:51 +01:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail to unfederate a remote video', async function () {
|
|
|
|
const path = basePath + remoteVideoUUID + '/blacklist'
|
|
|
|
const fields = { unfederate: true }
|
|
|
|
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path,
|
|
|
|
token: servers[0].accessToken,
|
|
|
|
fields,
|
|
|
|
statusCodeExpected: HttpStatusCode.CONFLICT_409
|
|
|
|
})
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
2020-01-31 16:56:52 +01:00
|
|
|
const fields = {}
|
2018-08-13 16:57:13 +02:00
|
|
|
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path,
|
|
|
|
token: servers[0].accessToken,
|
|
|
|
fields,
|
|
|
|
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When updating a video in blacklist', function () {
|
|
|
|
const basePath = '/api/v1/videos/'
|
|
|
|
|
|
|
|
it('Should fail with a wrong video', async function () {
|
|
|
|
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
|
|
|
const fields = {}
|
2019-01-10 15:39:51 +01:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a video not blacklisted', async function () {
|
|
|
|
const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
|
|
|
|
const fields = {}
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path,
|
|
|
|
token: servers[0].accessToken,
|
|
|
|
fields,
|
|
|
|
statusCodeExpected: HttpStatusCode.NOT_FOUND_404
|
|
|
|
})
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2018-08-13 16:57:13 +02:00
|
|
|
const fields = {}
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2017-12-28 16:26:28 +01:00
|
|
|
const fields = {}
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path,
|
|
|
|
token: userAccessToken2,
|
|
|
|
fields,
|
|
|
|
statusCodeExpected: HttpStatusCode.FORBIDDEN_403
|
|
|
|
})
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid reason', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
2018-08-13 16:57:13 +02:00
|
|
|
const fields = { reason: 'a'.repeat(305) }
|
|
|
|
|
2019-01-10 15:39:51 +01:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
2018-08-13 16:57:13 +02:00
|
|
|
const fields = { reason: 'hello' }
|
|
|
|
|
2020-12-07 14:32:36 +01:00
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path,
|
|
|
|
token: servers[0].accessToken,
|
|
|
|
fields,
|
|
|
|
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
|
|
|
|
})
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-14 09:16:32 +02:00
|
|
|
describe('When getting blacklisted video', function () {
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
|
2018-08-14 09:16:32 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with another user', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
|
2018-08-14 09:16:32 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the owner authenticated user', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200)
|
2018-08-14 09:16:32 +02:00
|
|
|
const video: VideoDetails = res.body
|
|
|
|
|
|
|
|
expect(video.blacklisted).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with an admin', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.OK_200)
|
2018-08-14 09:16:32 +02:00
|
|
|
const video: VideoDetails = res.body
|
|
|
|
|
|
|
|
expect(video.blacklisted).to.be.true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-22 09:13:43 +02:00
|
|
|
describe('When removing a video in blacklist', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect id', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a not blacklisted video', async function () {
|
|
|
|
// The video was not added to the blacklist so it should fail
|
2020-12-07 14:32:36 +01:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404)
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When listing videos in blacklist', function () {
|
2017-10-10 10:02:18 +02:00
|
|
|
const basePath = '/api/v1/videos/blacklist/'
|
2017-09-22 09:13:43 +02:00
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 })
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
2019-01-10 15:39:51 +01:00
|
|
|
await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
2019-04-02 11:26:47 +02:00
|
|
|
|
|
|
|
it('Should fail with an invalid type', async function () {
|
2020-12-07 14:32:36 +01:00
|
|
|
await getBlacklistedVideosList({
|
|
|
|
url: servers[0].url,
|
|
|
|
token: servers[0].accessToken,
|
|
|
|
type: 0,
|
|
|
|
specialStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
2019-04-02 11:26:47 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2019-04-15 10:49:46 +02:00
|
|
|
await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
|
2019-04-02 11:26:47 +02:00
|
|
|
})
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
2019-04-24 15:10:37 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
})
|