1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { join } from 'path'
6 import { LiveVideo, VideoPrivacy } from '@shared/models'
16 runAndTestFfmpegStreamError,
19 setAccessTokensToServers,
21 updateCustomSubConfig,
26 } from '../../../../shared/extra-utils'
28 describe('Test video lives API validator', function () {
29 const path = '/api/v1/videos/live'
30 let server: ServerInfo
31 let userAccessToken = ''
34 let videoIdNotLive: number
36 // ---------------------------------------------------------------
38 before(async function () {
41 server = await flushAndRunServer(1)
43 await setAccessTokensToServers([ server ])
45 await updateCustomSubConfig(server.url, server.accessToken, {
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 })
60 const res = await getMyUserInformation(server.url, server.accessToken)
61 channelId = res.body.videoChannels[0].id
65 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
69 describe('When creating a live', function () {
74 name: 'my super name',
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,
91 it('Should fail with nothing', async function () {
93 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
96 it('Should fail with a long name', async function () {
97 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
99 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
102 it('Should fail with a bad category', async function () {
103 const fields = immutableAssign(baseCorrectParams, { category: 125 })
105 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
108 it('Should fail with a bad licence', async function () {
109 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 it('Should fail with a bad language', async function () {
115 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
117 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 it('Should fail with a long description', async function () {
121 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
126 it('Should fail with a long support text', async function () {
127 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
129 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
132 it('Should fail without a channel', async function () {
133 const fields = omit(baseCorrectParams, 'channelId')
135 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
138 it('Should fail with a bad channel', async function () {
139 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
141 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
144 it('Should fail with another user channel', async function () {
147 password: 'fake_password'
149 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
151 const accessTokenUser = await userLogin(server, user)
152 const res = await getMyUserInformation(server.url, accessTokenUser)
153 const customChannelId = res.body.videoChannels[0].id
155 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
157 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
160 it('Should fail with too many tags', async function () {
161 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
163 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
166 it('Should fail with a tag length too low', async function () {
167 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
169 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
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' ] })
175 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
178 it('Should fail with an incorrect thumbnail file', async function () {
179 const fields = baseCorrectParams
181 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
184 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
187 it('Should fail with a big thumbnail file', async function () {
188 const fields = baseCorrectParams
190 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
193 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
196 it('Should fail with an incorrect preview file', async function () {
197 const fields = baseCorrectParams
199 previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
202 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
205 it('Should fail with a big preview file', async function () {
206 const fields = baseCorrectParams
208 previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
211 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
214 it('Should succeed with the correct parameters', async function () {
217 const res = await makePostBodyRequest({
220 token: server.accessToken,
221 fields: baseCorrectParams,
222 statusCodeExpected: 200
225 videoId = res.body.video.id
228 it('Should forbid if live is disabled', async function () {
229 await updateCustomSubConfig(server.url, server.accessToken, {
235 await makePostBodyRequest({
238 token: server.accessToken,
239 fields: baseCorrectParams,
240 statusCodeExpected: 403
244 it('Should forbid to save replay if not enabled by the admin', async function () {
245 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
247 await updateCustomSubConfig(server.url, server.accessToken, {
254 await makePostBodyRequest({
257 token: server.accessToken,
259 statusCodeExpected: 403
263 it('Should allow to save replay if enabled by the admin', async function () {
264 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
266 await updateCustomSubConfig(server.url, server.accessToken, {
273 await makePostBodyRequest({
276 token: server.accessToken,
278 statusCodeExpected: 200
282 it('Should not allow live if max instance lives is reached', async function () {
283 await updateCustomSubConfig(server.url, server.accessToken, {
290 await makePostBodyRequest({
293 token: server.accessToken,
294 fields: baseCorrectParams,
295 statusCodeExpected: 403
299 it('Should not allow live if max user lives is reached', async function () {
300 await updateCustomSubConfig(server.url, server.accessToken, {
303 maxInstanceLives: 20,
308 await makePostBodyRequest({
311 token: server.accessToken,
312 fields: baseCorrectParams,
313 statusCodeExpected: 403
318 describe('When getting live information', function () {
320 it('Should fail without access token', async function () {
321 await getLive(server.url, '', videoId, 401)
324 it('Should fail with a bad access token', async function () {
325 await getLive(server.url, 'toto', videoId, 401)
328 it('Should fail with access token of another user', async function () {
329 await getLive(server.url, userAccessToken, videoId, 403)
332 it('Should fail with a bad video id', async function () {
333 await getLive(server.url, server.accessToken, 'toto', 400)
336 it('Should fail with an unknown video id', async function () {
337 await getLive(server.url, server.accessToken, 454555, 404)
340 it('Should fail with a non live video', async function () {
341 await getLive(server.url, server.accessToken, videoIdNotLive, 404)
344 it('Should succeed with the correct params', async function () {
345 await getLive(server.url, server.accessToken, videoId)
349 describe('When updating live information', async function () {
351 it('Should fail without access token', async function () {
352 await updateLive(server.url, '', videoId, {}, 401)
355 it('Should fail with a bad access token', async function () {
356 await updateLive(server.url, 'toto', videoId, {}, 401)
359 it('Should fail with access token of another user', async function () {
360 await updateLive(server.url, userAccessToken, videoId, {}, 403)
363 it('Should fail with a bad video id', async function () {
364 await updateLive(server.url, server.accessToken, 'toto', {}, 400)
367 it('Should fail with an unknown video id', async function () {
368 await updateLive(server.url, server.accessToken, 454555, {}, 404)
371 it('Should fail with a non live video', async function () {
372 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, 404)
375 it('Should succeed with the correct params', async function () {
376 await updateLive(server.url, server.accessToken, videoId, { saveReplay: false })
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, {
387 await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, 403)
390 it('Should fail to update a live if it has already started', async function () {
393 const resLive = await getLive(server.url, server.accessToken, videoId)
394 const live: LiveVideo = resLive.body
396 const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
398 await waitUntilLiveStarts(server.url, server.accessToken, videoId)
399 await updateLive(server.url, server.accessToken, videoId, {}, 400)
401 await stopFfmpeg(command)
404 it('Should fail to stream twice in the save live', async function () {
407 const resLive = await getLive(server.url, server.accessToken, videoId)
408 const live: LiveVideo = resLive.body
410 const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
412 await waitUntilLiveStarts(server.url, server.accessToken, videoId)
414 await runAndTestFfmpegStreamError(server.url, server.accessToken, videoId, true)
416 await stopFfmpeg(command)
420 after(async function () {
421 await cleanupTests([ server ])