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