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