1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { omit } from 'lodash'
6 import { join } from 'path'
7 import { LiveVideo, VideoPrivacy } from '@shared/models'
19 setAccessTokensToServers,
21 testFfmpegStreamError,
22 updateCustomSubConfig,
27 } from '../../../../shared/extra-utils'
29 describe('Test video lives API validator', function () {
30 const path = '/api/v1/videos/live'
31 let server: ServerInfo
32 let userAccessToken = ''
33 let accountName: string
35 let channelName: string
37 let videoIdNotLive: number
39 // ---------------------------------------------------------------
41 before(async function () {
44 server = await flushAndRunServer(1)
46 await setAccessTokensToServers([ server ])
48 await updateCustomSubConfig(server.url, server.accessToken, {
57 const username = 'user1'
58 const password = 'my super password'
59 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
60 userAccessToken = await userLogin(server, { username, password })
63 const res = await getMyUserInformation(server.url, server.accessToken)
64 channelId = res.body.videoChannels[0].id
68 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
72 describe('When creating a live', function () {
77 name: 'my super name',
82 commentsEnabled: true,
83 downloadEnabled: true,
84 waitTranscoding: true,
85 description: 'my super description',
86 support: 'my super support text',
87 tags: [ 'tag1', 'tag2' ],
88 privacy: VideoPrivacy.PUBLIC,
94 it('Should fail with nothing', async function () {
96 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 it('Should fail with a long name', async function () {
100 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
102 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
105 it('Should fail with a bad category', async function () {
106 const fields = immutableAssign(baseCorrectParams, { category: 125 })
108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
111 it('Should fail with a bad licence', async function () {
112 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 it('Should fail with a bad language', async function () {
118 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 it('Should fail with a long description', async function () {
124 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 it('Should fail with a long support text', async function () {
130 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 it('Should fail without a channel', async function () {
136 const fields = omit(baseCorrectParams, 'channelId')
138 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 it('Should fail with a bad channel', async function () {
142 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 it('Should fail with another user channel', async function () {
150 password: 'fake_password'
152 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
154 const accessTokenUser = await userLogin(server, user)
155 const res = await getMyUserInformation(server.url, accessTokenUser)
156 const customChannelId = res.body.videoChannels[0].id
158 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
160 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
163 it('Should fail with too many tags', async function () {
164 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
166 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
169 it('Should fail with a tag length too low', async function () {
170 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
172 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
175 it('Should fail with a tag length too big', async function () {
176 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
178 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 it('Should fail with an incorrect thumbnail file', async function () {
182 const fields = baseCorrectParams
184 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
187 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
190 it('Should fail with a big thumbnail file', async function () {
191 const fields = baseCorrectParams
193 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
196 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
199 it('Should fail with an incorrect preview file', async function () {
200 const fields = baseCorrectParams
202 previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
205 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
208 it('Should fail with a big preview file', async function () {
209 const fields = baseCorrectParams
211 previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
214 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
217 it('Should succeed with the correct parameters', async function () {
220 const res = await makePostBodyRequest({
223 token: server.accessToken,
224 fields: baseCorrectParams,
225 statusCodeExpected: 200
228 videoId = res.body.video.id
231 it('Should forbid if live is disabled', async function () {
232 await updateCustomSubConfig(server.url, server.accessToken, {
238 await makePostBodyRequest({
241 token: server.accessToken,
242 fields: baseCorrectParams,
243 statusCodeExpected: 403
247 it('Should forbid to save replay if not enabled by the admin', async function () {
248 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
250 await updateCustomSubConfig(server.url, server.accessToken, {
257 await makePostBodyRequest({
260 token: server.accessToken,
262 statusCodeExpected: 403
266 it('Should allow to save replay if enabled by the admin', async function () {
267 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
269 await updateCustomSubConfig(server.url, server.accessToken, {
276 await makePostBodyRequest({
279 token: server.accessToken,
281 statusCodeExpected: 200
285 it('Should not allow live if max instance lives is reached', async function () {
286 await updateCustomSubConfig(server.url, server.accessToken, {
293 await makePostBodyRequest({
296 token: server.accessToken,
297 fields: baseCorrectParams,
298 statusCodeExpected: 403
302 it('Should not allow live if max user lives is reached', async function () {
303 await updateCustomSubConfig(server.url, server.accessToken, {
306 maxInstanceLives: 20,
311 await makePostBodyRequest({
314 token: server.accessToken,
315 fields: baseCorrectParams,
316 statusCodeExpected: 403
321 describe('When getting live information', function () {
323 it('Should fail without access token', async function () {
324 await getLive(server.url, '', videoId, 401)
327 it('Should fail with a bad access token', async function () {
328 await getLive(server.url, 'toto', videoId, 401)
331 it('Should fail with access token of another user', async function () {
332 await getLive(server.url, userAccessToken, videoId, 403)
335 it('Should fail with a bad video id', async function () {
336 await getLive(server.url, server.accessToken, 'toto', 400)
339 it('Should fail with an unknown video id', async function () {
340 await getLive(server.url, server.accessToken, 454555, 404)
343 it('Should fail with a non live video', async function () {
344 await getLive(server.url, server.accessToken, videoIdNotLive, 404)
347 it('Should succeed with the correct params', async function () {
348 await getLive(server.url, server.accessToken, videoId)
352 describe('When updating live information', async function () {
354 it('Should fail without access token', async function () {
355 await updateLive(server.url, '', videoId, {}, 401)
358 it('Should fail with a bad access token', async function () {
359 await updateLive(server.url, 'toto', videoId, {}, 401)
362 it('Should fail with access token of another user', async function () {
363 await updateLive(server.url, userAccessToken, videoId, {}, 403)
366 it('Should fail with a bad video id', async function () {
367 await updateLive(server.url, server.accessToken, 'toto', {}, 400)
370 it('Should fail with an unknown video id', async function () {
371 await updateLive(server.url, server.accessToken, 454555, {}, 404)
374 it('Should fail with a non live video', async function () {
375 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, 404)
378 it('Should succeed with the correct params', async function () {
379 await updateLive(server.url, server.accessToken, videoId, { saveReplay: false })
382 it('Should fail to update replay status if replay is not allowed on the instance', async function () {
383 await updateCustomSubConfig(server.url, server.accessToken, {
390 await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, 403)
393 it('Should fail to update a live if it has already started', async function () {
396 const resLive = await getLive(server.url, server.accessToken, videoId)
397 const live: LiveVideo = resLive.body
399 const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
401 await waitUntilLiveStarts(server.url, server.accessToken, videoId)
402 await updateLive(server.url, server.accessToken, videoId, {}, 400)
404 await stopFfmpeg(command)
407 it('Should fail to stream twice in the save live', async function () {
410 const resLive = await getLive(server.url, server.accessToken, videoId)
411 const live: LiveVideo = resLive.body
413 const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
415 await waitUntilLiveStarts(server.url, server.accessToken, videoId)
417 await testFfmpegStreamError(server.url, server.accessToken, videoId, true)
419 await stopFfmpeg(command)
423 after(async function () {
424 await cleanupTests([ server ])