2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-09-11 10:27:07 -04:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
|
|
|
|
import { HttpStatusCode, VideoCreateResult } from '@shared/models'
|
2018-09-11 10:27:07 -04:00
|
|
|
import {
|
2019-04-24 09:10:37 -04:00
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createMultipleServers,
|
2021-07-16 04:42:24 -04:00
|
|
|
doubleFollow,
|
2021-06-28 11:30:59 -04:00
|
|
|
makeDeleteRequest,
|
|
|
|
makeGetRequest,
|
|
|
|
makePostBodyRequest,
|
2018-09-11 10:27:07 -04:00
|
|
|
makePutBodyRequest,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2021-06-28 11:30:59 -04:00
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
2021-12-17 03:29:23 -05:00
|
|
|
} from '@shared/server-commands'
|
2018-09-11 10:27:07 -04:00
|
|
|
|
|
|
|
describe('Test server redundancy API validators', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let servers: PeerTubeServer[]
|
2018-09-11 10:27:07 -04:00
|
|
|
let userAccessToken = null
|
2020-01-10 04:11:28 -05:00
|
|
|
let videoIdLocal: number
|
2021-06-28 11:30:59 -04:00
|
|
|
let videoRemote: VideoCreateResult
|
2018-09-11 10:27:07 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
2020-12-15 09:09:12 -05:00
|
|
|
this.timeout(80000)
|
2018-09-11 10:27:07 -04:00
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
servers = await createMultipleServers(2)
|
2018-09-11 10:27:07 -04:00
|
|
|
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
username: 'user1',
|
|
|
|
password: 'password'
|
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].users.create({ username: user.username, password: user.password })
|
|
|
|
userAccessToken = await servers[0].login.getAccessToken(user)
|
2020-01-10 04:11:28 -05:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id
|
2020-06-10 09:35:20 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid
|
2020-01-10 04:11:28 -05:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
2020-06-10 09:35:20 -04:00
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
videoRemote = await servers[0].videos.get({ id: remoteUUID })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When listing redundancies', function () {
|
|
|
|
const path = '/api/v1/server/redundancy/videos'
|
|
|
|
|
|
|
|
let url: string
|
|
|
|
let token: string
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
url = servers[0].url
|
|
|
|
token = servers[0].accessToken
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
|
|
|
await checkBadStartPagination(url, path, servers[0].accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
|
|
|
await checkBadCountPagination(url, path, servers[0].accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
|
|
|
await checkBadSortPagination(url, path, servers[0].accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad target', async function () {
|
|
|
|
await makeGetRequest({ url, path, token, query: { target: 'bad target' } })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail without target', async function () {
|
|
|
|
await makeGetRequest({ url, path, token })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When manually adding a redundancy', function () {
|
|
|
|
const path = '/api/v1/server/redundancy/videos'
|
|
|
|
|
|
|
|
let url: string
|
|
|
|
let token: string
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
url = servers[0].url
|
|
|
|
token = servers[0].accessToken
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail without a video id', async function () {
|
|
|
|
await makePostBodyRequest({ url, path, token })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect video id', async function () {
|
|
|
|
await makePostBodyRequest({ url, path, token, fields: { videoId: 'peertube' } })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a not found video id', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a local a video id', async function () {
|
|
|
|
await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdLocal } })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
2021-06-28 11:30:59 -04:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token,
|
|
|
|
fields: { videoId: videoRemote.shortUUID },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2021-06-28 11:30:59 -04:00
|
|
|
})
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the video is already duplicated', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-06-28 11:30:59 -04:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token,
|
|
|
|
fields: { videoId: videoRemote.uuid },
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.CONFLICT_409
|
2021-06-28 11:30:59 -04:00
|
|
|
})
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When manually removing a redundancy', function () {
|
|
|
|
const path = '/api/v1/server/redundancy/videos/'
|
|
|
|
|
|
|
|
let url: string
|
|
|
|
let token: string
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
url = servers[0].url
|
|
|
|
token = servers[0].accessToken
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect video id', async function () {
|
|
|
|
await makeDeleteRequest({ url, path: path + 'toto', token })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a not found video redundancy', async function () {
|
2021-07-16 04:42:24 -04:00
|
|
|
await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
2020-01-10 04:11:28 -05:00
|
|
|
})
|
2018-09-11 10:27:07 -04:00
|
|
|
})
|
|
|
|
|
2020-01-10 04:11:28 -05:00
|
|
|
describe('When updating server redundancy', function () {
|
2018-09-11 10:27:07 -04:00
|
|
|
const path = '/api/v1/server/redundancy'
|
|
|
|
|
|
|
|
it('Should fail with an invalid token', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
2019-04-24 09:10:37 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 10:27:07 -04:00
|
|
|
fields: { redundancyAllowed: true },
|
|
|
|
token: 'fake_token',
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
2018-09-11 10:27:07 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
2019-04-24 09:10:37 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 10:27:07 -04:00
|
|
|
fields: { redundancyAllowed: true },
|
|
|
|
token: userAccessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2018-09-11 10:27:07 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if we do not follow this server', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path: path + '/example.com',
|
|
|
|
fields: { redundancyAllowed: true },
|
|
|
|
token: servers[0].accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2018-09-11 10:27:07 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail without de redundancyAllowed param', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
2019-04-24 09:10:37 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 10:27:07 -04:00
|
|
|
fields: { blabla: true },
|
|
|
|
token: servers[0].accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
2018-09-11 10:27:07 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
2019-04-24 09:10:37 -04:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 10:27:07 -04:00
|
|
|
fields: { redundancyAllowed: true },
|
|
|
|
token: servers[0].accessToken,
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.NO_CONTENT_204
|
2018-09-11 10:27:07 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-09-11 10:27:07 -04:00
|
|
|
})
|
|
|
|
})
|