]>
Commit | Line | Data |
---|---|---|
77e9f859 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
77e9f859 | 4 | import { omit } from 'lodash' |
4f219914 | 5 | import { VideoCreateResult, VideoPrivacy } from '@shared/models' |
3d470a53 | 6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
77e9f859 | 7 | import { |
3d470a53 | 8 | buildAbsoluteFixturePath, |
77e9f859 C |
9 | cleanupTests, |
10 | createUser, | |
11 | flushAndRunServer, | |
77e9f859 | 12 | getMyUserInformation, |
4f219914 | 13 | LiveCommand, |
77e9f859 C |
14 | makePostBodyRequest, |
15 | makeUploadRequest, | |
16 | sendRTMPStream, | |
17 | ServerInfo, | |
18 | setAccessTokensToServers, | |
19 | stopFfmpeg, | |
77e9f859 | 20 | uploadVideoAndGetId, |
4f219914 | 21 | userLogin |
77e9f859 C |
22 | } from '../../../../shared/extra-utils' |
23 | ||
24 | describe('Test video lives API validator', function () { | |
25 | const path = '/api/v1/videos/live' | |
26 | let server: ServerInfo | |
27 | let userAccessToken = '' | |
77e9f859 | 28 | let channelId: number |
d4a8e7a6 | 29 | let video: VideoCreateResult |
77e9f859 | 30 | let videoIdNotLive: number |
4f219914 | 31 | let command: LiveCommand |
77e9f859 C |
32 | |
33 | // --------------------------------------------------------------- | |
34 | ||
35 | before(async function () { | |
36 | this.timeout(30000) | |
37 | ||
38 | server = await flushAndRunServer(1) | |
39 | ||
40 | await setAccessTokensToServers([ server ]) | |
41 | ||
65e6e260 C |
42 | await server.configCommand.updateCustomSubConfig({ |
43 | newConfig: { | |
44 | live: { | |
45 | enabled: true, | |
46 | maxInstanceLives: 20, | |
47 | maxUserLives: 20, | |
48 | allowReplay: true | |
49 | } | |
77e9f859 C |
50 | } |
51 | }) | |
52 | ||
53 | const username = 'user1' | |
54 | const password = 'my super password' | |
55 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | |
56 | userAccessToken = await userLogin(server, { username, password }) | |
57 | ||
58 | { | |
59 | const res = await getMyUserInformation(server.url, server.accessToken) | |
60 | channelId = res.body.videoChannels[0].id | |
61 | } | |
62 | ||
63 | { | |
64 | videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id | |
65 | } | |
4f219914 C |
66 | |
67 | command = server.liveCommand | |
77e9f859 C |
68 | }) |
69 | ||
70 | describe('When creating a live', function () { | |
71 | let baseCorrectParams | |
72 | ||
73 | before(function () { | |
74 | baseCorrectParams = { | |
75 | name: 'my super name', | |
76 | category: 5, | |
77 | licence: 1, | |
78 | language: 'pt', | |
79 | nsfw: false, | |
80 | commentsEnabled: true, | |
81 | downloadEnabled: true, | |
82 | waitTranscoding: true, | |
83 | description: 'my super description', | |
84 | support: 'my super support text', | |
85 | tags: [ 'tag1', 'tag2' ], | |
86 | privacy: VideoPrivacy.PUBLIC, | |
87 | channelId, | |
bb4ba6d9 C |
88 | saveReplay: false, |
89 | permanentLive: false | |
77e9f859 C |
90 | } |
91 | }) | |
92 | ||
93 | it('Should fail with nothing', async function () { | |
94 | const fields = {} | |
95 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
96 | }) | |
97 | ||
98 | it('Should fail with a long name', async function () { | |
6c5065a0 | 99 | const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } |
77e9f859 C |
100 | |
101 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
102 | }) | |
103 | ||
104 | it('Should fail with a bad category', async function () { | |
6c5065a0 | 105 | const fields = { ...baseCorrectParams, category: 125 } |
77e9f859 C |
106 | |
107 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
108 | }) | |
109 | ||
110 | it('Should fail with a bad licence', async function () { | |
6c5065a0 | 111 | const fields = { ...baseCorrectParams, licence: 125 } |
77e9f859 C |
112 | |
113 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
114 | }) | |
115 | ||
116 | it('Should fail with a bad language', async function () { | |
6c5065a0 | 117 | const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } |
77e9f859 C |
118 | |
119 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
120 | }) | |
121 | ||
122 | it('Should fail with a long description', async function () { | |
6c5065a0 | 123 | const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } |
77e9f859 C |
124 | |
125 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
126 | }) | |
127 | ||
128 | it('Should fail with a long support text', async function () { | |
6c5065a0 | 129 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } |
77e9f859 C |
130 | |
131 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
132 | }) | |
133 | ||
134 | it('Should fail without a channel', async function () { | |
135 | const fields = omit(baseCorrectParams, 'channelId') | |
136 | ||
137 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
138 | }) | |
139 | ||
140 | it('Should fail with a bad channel', async function () { | |
6c5065a0 | 141 | const fields = { ...baseCorrectParams, channelId: 545454 } |
77e9f859 C |
142 | |
143 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
144 | }) | |
145 | ||
146 | it('Should fail with another user channel', async function () { | |
147 | const user = { | |
148 | username: 'fake', | |
149 | password: 'fake_password' | |
150 | } | |
151 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
152 | ||
153 | const accessTokenUser = await userLogin(server, user) | |
154 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
155 | const customChannelId = res.body.videoChannels[0].id | |
156 | ||
6c5065a0 | 157 | const fields = { ...baseCorrectParams, channelId: customChannelId } |
77e9f859 C |
158 | |
159 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | |
160 | }) | |
161 | ||
162 | it('Should fail with too many tags', async function () { | |
6c5065a0 | 163 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } |
77e9f859 C |
164 | |
165 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
166 | }) | |
167 | ||
168 | it('Should fail with a tag length too low', async function () { | |
6c5065a0 | 169 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } |
77e9f859 C |
170 | |
171 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
172 | }) | |
173 | ||
174 | it('Should fail with a tag length too big', async function () { | |
6c5065a0 | 175 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } |
77e9f859 C |
176 | |
177 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
178 | }) | |
179 | ||
180 | it('Should fail with an incorrect thumbnail file', async function () { | |
181 | const fields = baseCorrectParams | |
182 | const attaches = { | |
3d470a53 | 183 | thumbnailfile: buildAbsoluteFixturePath('video_short.mp4') |
77e9f859 C |
184 | } |
185 | ||
186 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
187 | }) | |
188 | ||
189 | it('Should fail with a big thumbnail file', async function () { | |
190 | const fields = baseCorrectParams | |
191 | const attaches = { | |
3d470a53 | 192 | thumbnailfile: buildAbsoluteFixturePath('preview-big.png') |
77e9f859 C |
193 | } |
194 | ||
195 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
196 | }) | |
197 | ||
198 | it('Should fail with an incorrect preview file', async function () { | |
199 | const fields = baseCorrectParams | |
200 | const attaches = { | |
3d470a53 | 201 | previewfile: buildAbsoluteFixturePath('video_short.mp4') |
77e9f859 C |
202 | } |
203 | ||
204 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
205 | }) | |
206 | ||
207 | it('Should fail with a big preview file', async function () { | |
208 | const fields = baseCorrectParams | |
209 | const attaches = { | |
3d470a53 | 210 | previewfile: buildAbsoluteFixturePath('preview-big.png') |
77e9f859 C |
211 | } |
212 | ||
213 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
214 | }) | |
215 | ||
bb4ba6d9 | 216 | it('Should fail with save replay and permanent live set to true', async function () { |
6c5065a0 | 217 | const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true } |
bb4ba6d9 C |
218 | |
219 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
220 | }) | |
221 | ||
77e9f859 C |
222 | it('Should succeed with the correct parameters', async function () { |
223 | this.timeout(30000) | |
224 | ||
225 | const res = await makePostBodyRequest({ | |
226 | url: server.url, | |
227 | path, | |
228 | token: server.accessToken, | |
229 | fields: baseCorrectParams, | |
2d53be02 | 230 | statusCodeExpected: HttpStatusCode.OK_200 |
77e9f859 C |
231 | }) |
232 | ||
d4a8e7a6 | 233 | video = res.body.video |
77e9f859 C |
234 | }) |
235 | ||
236 | it('Should forbid if live is disabled', async function () { | |
65e6e260 C |
237 | await server.configCommand.updateCustomSubConfig({ |
238 | newConfig: { | |
239 | live: { | |
240 | enabled: false | |
241 | } | |
77e9f859 C |
242 | } |
243 | }) | |
244 | ||
245 | await makePostBodyRequest({ | |
246 | url: server.url, | |
247 | path, | |
248 | token: server.accessToken, | |
249 | fields: baseCorrectParams, | |
2d53be02 | 250 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
77e9f859 C |
251 | }) |
252 | }) | |
253 | ||
254 | it('Should forbid to save replay if not enabled by the admin', async function () { | |
6c5065a0 | 255 | const fields = { ...baseCorrectParams, saveReplay: true } |
77e9f859 | 256 | |
65e6e260 C |
257 | await server.configCommand.updateCustomSubConfig({ |
258 | newConfig: { | |
259 | live: { | |
260 | enabled: true, | |
261 | allowReplay: false | |
262 | } | |
77e9f859 C |
263 | } |
264 | }) | |
265 | ||
266 | await makePostBodyRequest({ | |
267 | url: server.url, | |
268 | path, | |
269 | token: server.accessToken, | |
270 | fields, | |
2d53be02 | 271 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
77e9f859 C |
272 | }) |
273 | }) | |
274 | ||
275 | it('Should allow to save replay if enabled by the admin', async function () { | |
6c5065a0 | 276 | const fields = { ...baseCorrectParams, saveReplay: true } |
77e9f859 | 277 | |
65e6e260 C |
278 | await server.configCommand.updateCustomSubConfig({ |
279 | newConfig: { | |
280 | live: { | |
281 | enabled: true, | |
282 | allowReplay: true | |
283 | } | |
77e9f859 C |
284 | } |
285 | }) | |
286 | ||
287 | await makePostBodyRequest({ | |
288 | url: server.url, | |
289 | path, | |
290 | token: server.accessToken, | |
291 | fields, | |
2d53be02 | 292 | statusCodeExpected: HttpStatusCode.OK_200 |
77e9f859 C |
293 | }) |
294 | }) | |
295 | ||
296 | it('Should not allow live if max instance lives is reached', async function () { | |
65e6e260 C |
297 | await server.configCommand.updateCustomSubConfig({ |
298 | newConfig: { | |
299 | live: { | |
300 | enabled: true, | |
301 | maxInstanceLives: 1 | |
302 | } | |
77e9f859 C |
303 | } |
304 | }) | |
305 | ||
306 | await makePostBodyRequest({ | |
307 | url: server.url, | |
308 | path, | |
309 | token: server.accessToken, | |
310 | fields: baseCorrectParams, | |
2d53be02 | 311 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
77e9f859 C |
312 | }) |
313 | }) | |
314 | ||
315 | it('Should not allow live if max user lives is reached', async function () { | |
65e6e260 C |
316 | await server.configCommand.updateCustomSubConfig({ |
317 | newConfig: { | |
318 | live: { | |
319 | enabled: true, | |
320 | maxInstanceLives: 20, | |
321 | maxUserLives: 1 | |
322 | } | |
77e9f859 C |
323 | } |
324 | }) | |
325 | ||
326 | await makePostBodyRequest({ | |
327 | url: server.url, | |
328 | path, | |
329 | token: server.accessToken, | |
330 | fields: baseCorrectParams, | |
2d53be02 | 331 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
77e9f859 C |
332 | }) |
333 | }) | |
334 | }) | |
335 | ||
336 | describe('When getting live information', function () { | |
337 | ||
338 | it('Should fail without access token', async function () { | |
04aed767 | 339 | await command.get({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
77e9f859 C |
340 | }) |
341 | ||
342 | it('Should fail with a bad access token', async function () { | |
04aed767 | 343 | await command.get({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
77e9f859 C |
344 | }) |
345 | ||
346 | it('Should fail with access token of another user', async function () { | |
04aed767 | 347 | await command.get({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
77e9f859 C |
348 | }) |
349 | ||
350 | it('Should fail with a bad video id', async function () { | |
04aed767 | 351 | await command.get({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
77e9f859 C |
352 | }) |
353 | ||
354 | it('Should fail with an unknown video id', async function () { | |
04aed767 | 355 | await command.get({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
77e9f859 C |
356 | }) |
357 | ||
358 | it('Should fail with a non live video', async function () { | |
04aed767 | 359 | await command.get({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
77e9f859 C |
360 | }) |
361 | ||
362 | it('Should succeed with the correct params', async function () { | |
04aed767 C |
363 | await command.get({ videoId: video.id }) |
364 | await command.get({ videoId: video.uuid }) | |
365 | await command.get({ videoId: video.shortUUID }) | |
77e9f859 C |
366 | }) |
367 | }) | |
368 | ||
369 | describe('When updating live information', async function () { | |
370 | ||
371 | it('Should fail without access token', async function () { | |
04aed767 | 372 | await command.update({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
77e9f859 C |
373 | }) |
374 | ||
375 | it('Should fail with a bad access token', async function () { | |
04aed767 | 376 | await command.update({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
77e9f859 C |
377 | }) |
378 | ||
379 | it('Should fail with access token of another user', async function () { | |
04aed767 | 380 | await command.update({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
77e9f859 C |
381 | }) |
382 | ||
383 | it('Should fail with a bad video id', async function () { | |
04aed767 | 384 | await command.update({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
77e9f859 C |
385 | }) |
386 | ||
387 | it('Should fail with an unknown video id', async function () { | |
04aed767 | 388 | await command.update({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
77e9f859 C |
389 | }) |
390 | ||
391 | it('Should fail with a non live video', async function () { | |
04aed767 | 392 | await command.update({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
77e9f859 C |
393 | }) |
394 | ||
bb4ba6d9 C |
395 | it('Should fail with save replay and permanent live set to true', async function () { |
396 | const fields = { saveReplay: true, permanentLive: true } | |
397 | ||
04aed767 | 398 | await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
bb4ba6d9 C |
399 | }) |
400 | ||
77e9f859 | 401 | it('Should succeed with the correct params', async function () { |
04aed767 C |
402 | await command.update({ videoId: video.id, fields: { saveReplay: false } }) |
403 | await command.update({ videoId: video.uuid, fields: { saveReplay: false } }) | |
404 | await command.update({ videoId: video.shortUUID, fields: { saveReplay: false } }) | |
77e9f859 C |
405 | }) |
406 | ||
407 | it('Should fail to update replay status if replay is not allowed on the instance', async function () { | |
65e6e260 C |
408 | await server.configCommand.updateCustomSubConfig({ |
409 | newConfig: { | |
410 | live: { | |
411 | enabled: true, | |
412 | allowReplay: false | |
413 | } | |
77e9f859 C |
414 | } |
415 | }) | |
416 | ||
04aed767 | 417 | await command.update({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
77e9f859 C |
418 | }) |
419 | ||
420 | it('Should fail to update a live if it has already started', async function () { | |
59fd824c | 421 | this.timeout(40000) |
77e9f859 | 422 | |
04aed767 | 423 | const live = await command.get({ videoId: video.id }) |
77e9f859 | 424 | |
4f219914 | 425 | const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey) |
77e9f859 | 426 | |
04aed767 C |
427 | await command.waitUntilPublished({ videoId: video.id }) |
428 | await command.update({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | |
77e9f859 | 429 | |
4f219914 | 430 | await stopFfmpeg(ffmpegCommand) |
77e9f859 | 431 | }) |
97969c4e C |
432 | |
433 | it('Should fail to stream twice in the save live', async function () { | |
59fd824c | 434 | this.timeout(40000) |
97969c4e | 435 | |
04aed767 | 436 | const live = await command.get({ videoId: video.id }) |
97969c4e | 437 | |
4f219914 | 438 | const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey) |
97969c4e | 439 | |
04aed767 | 440 | await command.waitUntilPublished({ videoId: video.id }) |
97969c4e | 441 | |
04aed767 | 442 | await command.runAndTestStreamError({ videoId: video.id, shouldHaveError: true }) |
97969c4e | 443 | |
4f219914 | 444 | await stopFfmpeg(ffmpegCommand) |
97969c4e | 445 | }) |
77e9f859 C |
446 | }) |
447 | ||
448 | after(async function () { | |
449 | await cleanupTests([ server ]) | |
450 | }) | |
451 | }) |