]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/redundancy.ts
Fix big play button
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / redundancy.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
c48e82b5
C
2
3import 'mocha'
4
5import {
b764380a
C
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
7c3b7976 9 cleanupTests,
c48e82b5
C
10 createUser,
11 doubleFollow,
b764380a
C
12 flushAndRunMultipleServers, makeDeleteRequest,
13 makeGetRequest, makePostBodyRequest,
c48e82b5
C
14 makePutBodyRequest,
15 ServerInfo,
b764380a 16 setAccessTokensToServers, uploadVideoAndGetId,
f9b6d51f 17 userLogin, waitJobs, getVideoIdFromUUID
94565d52 18} from '../../../../shared/extra-utils'
2d53be02 19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
c48e82b5
C
20
21describe('Test server redundancy API validators', function () {
22 let servers: ServerInfo[]
23 let userAccessToken = null
b764380a
C
24 let videoIdLocal: number
25 let videoIdRemote: number
c48e82b5
C
26
27 // ---------------------------------------------------------------
28
29 before(async function () {
496b5a5b 30 this.timeout(80000)
c48e82b5 31
c48e82b5
C
32 servers = await flushAndRunMultipleServers(2)
33
34 await setAccessTokensToServers(servers)
35 await doubleFollow(servers[0], servers[1])
36
37 const user = {
38 username: 'user1',
39 password: 'password'
40 }
41
a1587156 42 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
c48e82b5 43 userAccessToken = await userLogin(servers[0], user)
b764380a
C
44
45 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
f9b6d51f
C
46
47 const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid
b764380a
C
48
49 await waitJobs(servers)
f9b6d51f
C
50
51 videoIdRemote = await getVideoIdFromUUID(servers[0].url, remoteUUID)
b764380a
C
52 })
53
54 describe('When listing redundancies', function () {
55 const path = '/api/v1/server/redundancy/videos'
56
57 let url: string
58 let token: string
59
60 before(function () {
61 url = servers[0].url
62 token = servers[0].accessToken
63 })
64
65 it('Should fail with an invalid token', async function () {
2d53be02 66 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
b764380a
C
67 })
68
69 it('Should fail if the user is not an administrator', async function () {
2d53be02 70 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
b764380a
C
71 })
72
73 it('Should fail with a bad start pagination', async function () {
74 await checkBadStartPagination(url, path, servers[0].accessToken)
75 })
76
77 it('Should fail with a bad count pagination', async function () {
78 await checkBadCountPagination(url, path, servers[0].accessToken)
79 })
80
81 it('Should fail with an incorrect sort', async function () {
82 await checkBadSortPagination(url, path, servers[0].accessToken)
83 })
84
85 it('Should fail with a bad target', async function () {
86 await makeGetRequest({ url, path, token, query: { target: 'bad target' } })
87 })
88
89 it('Should fail without target', async function () {
90 await makeGetRequest({ url, path, token })
91 })
92
93 it('Should succeed with the correct params', async function () {
2d53be02 94 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: HttpStatusCode.OK_200 })
b764380a
C
95 })
96 })
97
98 describe('When manually adding a redundancy', function () {
99 const path = '/api/v1/server/redundancy/videos'
100
101 let url: string
102 let token: string
103
104 before(function () {
105 url = servers[0].url
106 token = servers[0].accessToken
107 })
108
109 it('Should fail with an invalid token', async function () {
2d53be02 110 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
b764380a
C
111 })
112
113 it('Should fail if the user is not an administrator', async function () {
2d53be02 114 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
b764380a
C
115 })
116
117 it('Should fail without a video id', async function () {
118 await makePostBodyRequest({ url, path, token })
119 })
120
121 it('Should fail with an incorrect video id', async function () {
122 await makePostBodyRequest({ url, path, token, fields: { videoId: 'peertube' } })
123 })
124
125 it('Should fail with a not found video id', async function () {
2d53be02 126 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
b764380a
C
127 })
128
129 it('Should fail with a local a video id', async function () {
130 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdLocal } })
131 })
132
133 it('Should succeed with the correct params', async function () {
2d53be02 134 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
b764380a
C
135 })
136
137 it('Should fail if the video is already duplicated', async function () {
138 this.timeout(30000)
139
140 await waitJobs(servers)
141
2d53be02 142 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.CONFLICT_409 })
b764380a
C
143 })
144 })
145
146 describe('When manually removing a redundancy', function () {
147 const path = '/api/v1/server/redundancy/videos/'
148
149 let url: string
150 let token: string
151
152 before(function () {
153 url = servers[0].url
154 token = servers[0].accessToken
155 })
156
157 it('Should fail with an invalid token', async function () {
2d53be02 158 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
b764380a
C
159 })
160
161 it('Should fail if the user is not an administrator', async function () {
2d53be02 162 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
b764380a
C
163 })
164
165 it('Should fail with an incorrect video id', async function () {
166 await makeDeleteRequest({ url, path: path + 'toto', token })
167 })
168
169 it('Should fail with a not found video redundancy', async function () {
2d53be02 170 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
b764380a 171 })
c48e82b5
C
172 })
173
b764380a 174 describe('When updating server redundancy', function () {
c48e82b5
C
175 const path = '/api/v1/server/redundancy'
176
177 it('Should fail with an invalid token', async function () {
178 await makePutBodyRequest({
179 url: servers[0].url,
7c3b7976 180 path: path + '/localhost:' + servers[1].port,
c48e82b5
C
181 fields: { redundancyAllowed: true },
182 token: 'fake_token',
2d53be02 183 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
c48e82b5
C
184 })
185 })
186
187 it('Should fail if the user is not an administrator', async function () {
188 await makePutBodyRequest({
189 url: servers[0].url,
7c3b7976 190 path: path + '/localhost:' + servers[1].port,
c48e82b5
C
191 fields: { redundancyAllowed: true },
192 token: userAccessToken,
2d53be02 193 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
c48e82b5
C
194 })
195 })
196
197 it('Should fail if we do not follow this server', async function () {
198 await makePutBodyRequest({
199 url: servers[0].url,
200 path: path + '/example.com',
201 fields: { redundancyAllowed: true },
202 token: servers[0].accessToken,
2d53be02 203 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
c48e82b5
C
204 })
205 })
206
207 it('Should fail without de redundancyAllowed param', async function () {
208 await makePutBodyRequest({
209 url: servers[0].url,
7c3b7976 210 path: path + '/localhost:' + servers[1].port,
c48e82b5
C
211 fields: { blabla: true },
212 token: servers[0].accessToken,
2d53be02 213 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
c48e82b5
C
214 })
215 })
216
217 it('Should succeed with the correct parameters', async function () {
218 await makePutBodyRequest({
219 url: servers[0].url,
7c3b7976 220 path: path + '/localhost:' + servers[1].port,
c48e82b5
C
221 fields: { redundancyAllowed: true },
222 token: servers[0].accessToken,
2d53be02 223 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
c48e82b5
C
224 })
225 })
226 })
227
7c3b7976
C
228 after(async function () {
229 await cleanupTests(servers)
c48e82b5
C
230 })
231})