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