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'
|
|
|
|
|
|
|
|
import {
|
2019-04-24 09:10:37 -04:00
|
|
|
cleanupTests,
|
2018-08-13 10:57:13 -04:00
|
|
|
createUser,
|
2019-01-10 09:39:51 -05:00
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
|
|
|
getBlacklistedVideosList,
|
|
|
|
getVideo,
|
|
|
|
getVideoWithToken,
|
2018-08-13 10:57:13 -04:00
|
|
|
makePostBodyRequest,
|
|
|
|
makePutBodyRequest,
|
|
|
|
removeVideoFromBlacklist,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
uploadVideo,
|
2020-01-31 10:56:52 -05:00
|
|
|
userLogin,
|
|
|
|
waitJobs
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-10-29 12:48:31 -04:00
|
|
|
import {
|
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils/requests/check-api-params'
|
2020-01-31 10:56:52 -05:00
|
|
|
import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
|
2018-08-14 03:16:32 -04:00
|
|
|
import { expect } from 'chai'
|
2017-09-22 03:13:43 -04:00
|
|
|
|
|
|
|
describe('Test video blacklist API validators', function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
let servers: ServerInfo[]
|
2018-08-13 10:57:13 -04:00
|
|
|
let notBlacklistedVideoId: number
|
2019-01-10 09:39:51 -05:00
|
|
|
let remoteVideoUUID: string
|
2018-08-14 03:16:32 -04:00
|
|
|
let userAccessToken1 = ''
|
|
|
|
let userAccessToken2 = ''
|
2017-09-22 03:13:43 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2019-01-10 09:39:51 -05:00
|
|
|
servers = await flushAndRunMultipleServers(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'
|
2020-01-31 10:56:52 -05:00
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
|
2019-01-10 09:39:51 -05:00
|
|
|
userAccessToken1 = await userLogin(servers[0], { 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'
|
2020-01-31 10:56:52 -05:00
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
|
2019-01-10 09:39:51 -05:00
|
|
|
userAccessToken2 = await userLogin(servers[0], { username, password })
|
2018-08-14 03:16:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-01-10 09:39:51 -05:00
|
|
|
const res = await uploadVideo(servers[0].url, userAccessToken1, {})
|
|
|
|
servers[0].video = res.body.video
|
2018-08-13 10:57:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-01-10 09:39:51 -05:00
|
|
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
|
2018-08-13 10:57:13 -04:00
|
|
|
notBlacklistedVideoId = res.body.video.uuid
|
|
|
|
}
|
2019-01-10 09:39:51 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
|
|
|
|
remoteVideoUUID = res.body.video.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
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 () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video + '/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 () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2017-12-28 10:26:28 -05:00
|
|
|
const fields = {}
|
2019-01-10 09:39:51 -05:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
2017-09-22 03:13:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2017-12-28 10:26:28 -05:00
|
|
|
const fields = {}
|
2019-01-10 09:39:51 -05:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
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 () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video.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 }
|
|
|
|
|
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
|
2018-08-13 10:57:13 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
2020-01-31 10:56:52 -05:00
|
|
|
const fields = {}
|
2018-08-13 10:57:13 -04:00
|
|
|
|
2019-01-10 09:39:51 -05:00
|
|
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
|
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 = {}
|
2019-01-10 09:39:51 -05:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
|
2018-08-13 10:57:13 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2018-08-13 10:57:13 -04:00
|
|
|
const fields = {}
|
2019-01-10 09:39:51 -05:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
2018-08-13 10:57:13 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video + '/blacklist'
|
2017-12-28 10:26:28 -05:00
|
|
|
const fields = {}
|
2019-01-10 09:39:51 -05:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
2018-08-13 10:57:13 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid reason', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video.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 () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
2018-08-13 10:57:13 -04:00
|
|
|
const fields = { reason: 'hello' }
|
|
|
|
|
2019-01-10 09:39:51 -05:00
|
|
|
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
|
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 () {
|
2019-01-10 09:39:51 -05:00
|
|
|
await getVideo(servers[0].url, servers[0].video.uuid, 401)
|
2018-08-14 03:16:32 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with another user', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
|
2018-08-14 03:16:32 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the owner authenticated user', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
|
2018-08-14 03:16:32 -04:00
|
|
|
const video: VideoDetails = res.body
|
|
|
|
|
|
|
|
expect(video.blacklisted).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with an admin', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
|
2018-08-14 03:16:32 -04:00
|
|
|
const video: VideoDetails = res.body
|
|
|
|
|
|
|
|
expect(video.blacklisted).to.be.true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-22 03:13:43 -04:00
|
|
|
describe('When removing a video in blacklist', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
|
2017-09-22 03:13:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
|
2017-09-22 03:13:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect id', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 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
|
2019-01-10 09:39:51 -05:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
|
2018-08-13 10:57:13 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2019-01-10 09:39:51 -05:00
|
|
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 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 () {
|
2019-04-15 04:49:46 -04:00
|
|
|
await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 })
|
2017-09-22 03:13:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non admin user', async function () {
|
2019-04-15 04:49:46 -04:00
|
|
|
await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 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 () {
|
2019-04-15 04:49:46 -04:00
|
|
|
await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 })
|
2019-04-02 05:26:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2019-04-15 04:49:46 -04:00
|
|
|
await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, 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
|
|
|
})
|
|
|
|
})
|