1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
12 flushAndRunMultipleServers, makeDeleteRequest,
13 makeGetRequest, makePostBodyRequest,
16 setAccessTokensToServers, uploadVideoAndGetId,
17 userLogin, waitJobs, getVideoIdFromUUID
18 } from '../../../../shared/extra-utils'
20 describe('Test server redundancy API validators', function () {
21 let servers: ServerInfo[]
22 let userAccessToken = null
23 let videoIdLocal: number
24 let videoIdRemote: number
26 // ---------------------------------------------------------------
28 before(async function () {
31 servers = await flushAndRunMultipleServers(2)
33 await setAccessTokensToServers(servers)
34 await doubleFollow(servers[0], servers[1])
41 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
42 userAccessToken = await userLogin(servers[0], user)
44 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
46 const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid
48 await waitJobs(servers)
50 videoIdRemote = await getVideoIdFromUUID(servers[0].url, remoteUUID)
53 describe('When listing redundancies', function () {
54 const path = '/api/v1/server/redundancy/videos'
61 token = servers[0].accessToken
64 it('Should fail with an invalid token', async function () {
65 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
68 it('Should fail if the user is not an administrator', async function () {
69 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
72 it('Should fail with a bad start pagination', async function () {
73 await checkBadStartPagination(url, path, servers[0].accessToken)
76 it('Should fail with a bad count pagination', async function () {
77 await checkBadCountPagination(url, path, servers[0].accessToken)
80 it('Should fail with an incorrect sort', async function () {
81 await checkBadSortPagination(url, path, servers[0].accessToken)
84 it('Should fail with a bad target', async function () {
85 await makeGetRequest({ url, path, token, query: { target: 'bad target' } })
88 it('Should fail without target', async function () {
89 await makeGetRequest({ url, path, token })
92 it('Should succeed with the correct params', async function () {
93 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: 200 })
97 describe('When manually adding a redundancy', function () {
98 const path = '/api/v1/server/redundancy/videos'
105 token = servers[0].accessToken
108 it('Should fail with an invalid token', async function () {
109 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
112 it('Should fail if the user is not an administrator', async function () {
113 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
116 it('Should fail without a video id', async function () {
117 await makePostBodyRequest({ url, path, token })
120 it('Should fail with an incorrect video id', async function () {
121 await makePostBodyRequest({ url, path, token, fields: { videoId: 'peertube' } })
124 it('Should fail with a not found video id', async function () {
125 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: 404 })
128 it('Should fail with a local a video id', async function () {
129 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdLocal } })
132 it('Should succeed with the correct params', async function () {
133 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 204 })
136 it('Should fail if the video is already duplicated', async function () {
139 await waitJobs(servers)
141 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 409 })
145 describe('When manually removing a redundancy', function () {
146 const path = '/api/v1/server/redundancy/videos/'
153 token = servers[0].accessToken
156 it('Should fail with an invalid token', async function () {
157 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: 401 })
160 it('Should fail if the user is not an administrator', async function () {
161 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: 403 })
164 it('Should fail with an incorrect video id', async function () {
165 await makeDeleteRequest({ url, path: path + 'toto', token })
168 it('Should fail with a not found video redundancy', async function () {
169 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: 404 })
173 describe('When updating server redundancy', function () {
174 const path = '/api/v1/server/redundancy'
176 it('Should fail with an invalid token', async function () {
177 await makePutBodyRequest({
179 path: path + '/localhost:' + servers[1].port,
180 fields: { redundancyAllowed: true },
182 statusCodeExpected: 401
186 it('Should fail if the user is not an administrator', async function () {
187 await makePutBodyRequest({
189 path: path + '/localhost:' + servers[1].port,
190 fields: { redundancyAllowed: true },
191 token: userAccessToken,
192 statusCodeExpected: 403
196 it('Should fail if we do not follow this server', async function () {
197 await makePutBodyRequest({
199 path: path + '/example.com',
200 fields: { redundancyAllowed: true },
201 token: servers[0].accessToken,
202 statusCodeExpected: 404
206 it('Should fail without de redundancyAllowed param', async function () {
207 await makePutBodyRequest({
209 path: path + '/localhost:' + servers[1].port,
210 fields: { blabla: true },
211 token: servers[0].accessToken,
212 statusCodeExpected: 400
216 it('Should succeed with the correct parameters', async function () {
217 await makePutBodyRequest({
219 path: path + '/localhost:' + servers[1].port,
220 fields: { redundancyAllowed: true },
221 token: servers[0].accessToken,
222 statusCodeExpected: 204
227 after(async function () {
228 await cleanupTests(servers)