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'
|
2021-07-08 11:17:55 +02:00
|
|
|
import { expect } from 'chai'
|
2021-12-17 11:58:15 +01:00
|
|
|
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
|
|
|
|
import { HttpStatusCode, VideoBlacklistType } from '@shared/models'
|
2017-09-22 09:13:43 +02:00
|
|
|
import {
|
2021-07-08 11:17:55 +02:00
|
|
|
BlacklistCommand,
|
2019-04-24 15:10:37 +02:00
|
|
|
cleanupTests,
|
2021-07-16 09:47:51 +02:00
|
|
|
createMultipleServers,
|
2021-07-16 14:27:30 +02:00
|
|
|
doubleFollow,
|
2018-08-13 16:57:13 +02:00
|
|
|
makePostBodyRequest,
|
|
|
|
makePutBodyRequest,
|
2021-07-16 09:47:51 +02:00
|
|
|
PeerTubeServer,
|
2018-08-13 16:57:13 +02:00
|
|
|
setAccessTokensToServers,
|
2020-01-31 16:56:52 +01:00
|
|
|
waitJobs
|
2021-12-17 09:29:23 +01:00
|
|
|
} from '@shared/server-commands'
|
2017-09-22 09:13:43 +02:00
|
|
|
|
|
|
|
describe('Test video blacklist API validators', function () {
|
2021-07-16 09:47:51 +02:00
|
|
|
let servers: PeerTubeServer[]
|
2021-07-15 10:02:54 +02:00
|
|
|
let notBlacklistedVideoId: string
|
2019-01-10 15:39:51 +01:00
|
|
|
let remoteVideoUUID: string
|
2018-08-14 09:16:32 +02:00
|
|
|
let userAccessToken1 = ''
|
|
|
|
let userAccessToken2 = ''
|
2021-07-08 11:17:55 +02:00
|
|
|
let command: BlacklistCommand
|
2017-09-22 09:13:43 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
servers = await createMultipleServers(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'
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].users.create({ username: username, password: password })
|
|
|
|
userAccessToken1 = await servers[0].login.getAccessToken({ 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'
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].users.create({ username: username, password: password })
|
|
|
|
userAccessToken2 = await servers[0].login.getAccessToken({ username, password })
|
2018-08-14 09:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-22 14:28:03 +02:00
|
|
|
servers[0].store.videoCreated = await servers[0].videos.upload({ token: userAccessToken1 })
|
2018-08-13 16:57:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { uuid } = await servers[0].videos.upload()
|
2021-07-15 10:02:54 +02:00
|
|
|
notBlacklistedVideoId = uuid
|
2018-08-13 16:57:13 +02:00
|
|
|
}
|
2019-01-10 15:39:51 +01:00
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { uuid } = await servers[1].videos.upload()
|
2021-07-15 10:02:54 +02:00
|
|
|
remoteVideoUUID = uuid
|
2019-01-10 15:39:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
2021-07-08 11:17:55 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
command = servers[0].blacklist
|
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 () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated + '/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 () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated + '/blacklist'
|
2017-12-28 16:26:28 +01:00
|
|
|
const fields = {}
|
2021-07-16 10:42:24 +02:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated + '/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,
|
2021-07-16 10:42:24 +02:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2020-12-07 14:32:36 +01:00
|
|
|
})
|
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 () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated.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,
|
2021-07-16 10:42:24 +02:00
|
|
|
expectedStatus: HttpStatusCode.CONFLICT_409
|
2020-12-07 14:32:36 +01:00
|
|
|
})
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated.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,
|
2021-07-16 10:42:24 +02:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2020-12-07 14:32:36 +01:00
|
|
|
})
|
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,
|
2021-07-16 10:42:24 +02:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2020-12-07 14:32:36 +01:00
|
|
|
})
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated + '/blacklist'
|
2018-08-13 16:57:13 +02:00
|
|
|
const fields = {}
|
2021-07-16 10:42:24 +02:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated + '/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,
|
2021-07-16 10:42:24 +02:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2020-12-07 14:32:36 +01:00
|
|
|
})
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid reason', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated.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 () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const path = basePath + servers[0].store.videoCreated.shortUUID + '/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,
|
2021-07-16 10:42:24 +02:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2020-12-07 14:32:36 +01:00
|
|
|
})
|
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 () {
|
2021-07-22 14:28:03 +02:00
|
|
|
await servers[0].videos.get({ id: servers[0].store.videoCreated.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2018-08-14 09:16:32 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with another user', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].videos.getWithToken({
|
2021-07-15 10:02:54 +02:00
|
|
|
token: userAccessToken2,
|
2021-07-22 14:28:03 +02:00
|
|
|
id: servers[0].store.videoCreated.uuid,
|
2021-07-15 10:02:54 +02:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
|
|
|
})
|
2018-08-14 09:16:32 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the owner authenticated user', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const video = await servers[0].videos.getWithToken({ token: userAccessToken1, id: servers[0].store.videoCreated.uuid })
|
2018-08-14 09:16:32 +02:00
|
|
|
expect(video.blacklisted).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with an admin', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
const video = servers[0].store.videoCreated
|
2018-08-14 09:16:32 +02:00
|
|
|
|
2021-06-28 17:30:59 +02:00
|
|
|
for (const id of [ video.id, video.uuid, video.shortUUID ]) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const video = await servers[0].videos.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 })
|
2021-06-28 17:30:59 +02:00
|
|
|
expect(video.blacklisted).to.be.true
|
|
|
|
}
|
2018-08-14 09:16:32 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-22 09:13:43 +02:00
|
|
|
describe('When removing a video in blacklist', function () {
|
2021-07-08 11:17:55 +02:00
|
|
|
|
2017-09-22 09:13:43 +02:00
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
await command.remove({
|
|
|
|
token: 'fake token',
|
|
|
|
videoId: servers[0].store.videoCreated.uuid,
|
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
|
|
|
})
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
await command.remove({
|
|
|
|
token: userAccessToken2,
|
|
|
|
videoId: servers[0].store.videoCreated.uuid,
|
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
|
|
|
})
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect id', async function () {
|
2021-07-08 11:17:55 +02:00
|
|
|
await command.remove({ videoId: 'hello', expectedStatus: 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
|
2021-07-08 11:17:55 +02:00
|
|
|
await command.remove({ videoId: notBlacklistedVideoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
2018-08-13 16:57:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2021-07-22 14:28:03 +02:00
|
|
|
await command.remove({ videoId: servers[0].store.videoCreated.uuid, expectedStatus: 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 () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blacklist.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2017-09-22 09:13:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blacklist.list({ token: userAccessToken2, expectedStatus: 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 () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blacklist.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2019-04-02 11:26:47 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blacklist.list({ 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
|
|
|
})
|
|
|
|
})
|