2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-09-11 09:27:07 -05:00
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
|
|
|
|
import {
|
2020-01-10 03:11:28 -06:00
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination,
|
2019-04-24 08:10:37 -05:00
|
|
|
cleanupTests,
|
2018-09-11 09:27:07 -05:00
|
|
|
createUser,
|
|
|
|
doubleFollow,
|
2020-01-10 03:11:28 -06:00
|
|
|
flushAndRunMultipleServers, makeDeleteRequest,
|
|
|
|
makeGetRequest, makePostBodyRequest,
|
2018-09-11 09:27:07 -05:00
|
|
|
makePutBodyRequest,
|
|
|
|
ServerInfo,
|
2020-01-10 03:11:28 -06:00
|
|
|
setAccessTokensToServers, uploadVideoAndGetId,
|
2020-06-10 08:35:20 -05:00
|
|
|
userLogin, waitJobs, getVideoIdFromUUID
|
2019-04-15 08:26:15 -05:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-09-11 09:27:07 -05:00
|
|
|
|
|
|
|
describe('Test server redundancy API validators', function () {
|
|
|
|
let servers: ServerInfo[]
|
|
|
|
let userAccessToken = null
|
2020-01-10 03:11:28 -06:00
|
|
|
let videoIdLocal: number
|
|
|
|
let videoIdRemote: number
|
2018-09-11 09:27:07 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
username: 'user1',
|
|
|
|
password: 'password'
|
|
|
|
}
|
|
|
|
|
2020-01-31 09:56:52 -06:00
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
2018-09-11 09:27:07 -05:00
|
|
|
userAccessToken = await userLogin(servers[0], user)
|
2020-01-10 03:11:28 -06:00
|
|
|
|
|
|
|
videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
|
2020-06-10 08:35:20 -05:00
|
|
|
|
|
|
|
const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid
|
2020-01-10 03:11:28 -06:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
2020-06-10 08:35:20 -05:00
|
|
|
|
|
|
|
videoIdRemote = await getVideoIdFromUUID(servers[0].url, remoteUUID)
|
2020-01-10 03:11:28 -06: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 () {
|
|
|
|
await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: 200 })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: 404 })
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 204 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the video is already duplicated', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 409 })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: 401 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: 403 })
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: 404 })
|
|
|
|
})
|
2018-09-11 09:27:07 -05:00
|
|
|
})
|
|
|
|
|
2020-01-10 03:11:28 -06:00
|
|
|
describe('When updating server redundancy', function () {
|
2018-09-11 09:27:07 -05: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 08:10:37 -05:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 09:27:07 -05:00
|
|
|
fields: { redundancyAllowed: true },
|
|
|
|
token: 'fake_token',
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if the user is not an administrator', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
2019-04-24 08:10:37 -05:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 09:27:07 -05:00
|
|
|
fields: { redundancyAllowed: true },
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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,
|
|
|
|
statusCodeExpected: 404
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail without de redundancyAllowed param', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
2019-04-24 08:10:37 -05:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 09:27:07 -05:00
|
|
|
fields: { blabla: true },
|
|
|
|
token: servers[0].accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
|
|
|
await makePutBodyRequest({
|
|
|
|
url: servers[0].url,
|
2019-04-24 08:10:37 -05:00
|
|
|
path: path + '/localhost:' + servers[1].port,
|
2018-09-11 09:27:07 -05:00
|
|
|
fields: { redundancyAllowed: true },
|
|
|
|
token: servers[0].accessToken,
|
|
|
|
statusCodeExpected: 204
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 08:10:37 -05:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-09-11 09:27:07 -05:00
|
|
|
})
|
|
|
|
})
|