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