1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { VideoCreateResult, VideoPrivacy } from '@shared/models'
6 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8 buildAbsoluteFixturePath,
18 setAccessTokensToServers,
22 } from '../../../../shared/extra-utils'
24 describe('Test video lives API validator', function () {
25 const path = '/api/v1/videos/live'
26 let server: ServerInfo
27 let userAccessToken = ''
29 let video: VideoCreateResult
30 let videoIdNotLive: number
31 let command: LiveCommand
33 // ---------------------------------------------------------------
35 before(async function () {
38 server = await flushAndRunServer(1)
40 await setAccessTokensToServers([ server ])
42 await server.configCommand.updateCustomSubConfig({
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 })
59 const res = await getMyUserInformation(server.url, server.accessToken)
60 channelId = res.body.videoChannels[0].id
64 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
67 command = server.liveCommand
70 describe('When creating a live', function () {
75 name: 'my super name',
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,
93 it('Should fail with nothing', async function () {
95 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
98 it('Should fail with a long name', async function () {
99 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
101 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
104 it('Should fail with a bad category', async function () {
105 const fields = { ...baseCorrectParams, category: 125 }
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
110 it('Should fail with a bad licence', async function () {
111 const fields = { ...baseCorrectParams, licence: 125 }
113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
116 it('Should fail with a bad language', async function () {
117 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
122 it('Should fail with a long description', async function () {
123 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
128 it('Should fail with a long support text', async function () {
129 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
131 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
134 it('Should fail without a channel', async function () {
135 const fields = omit(baseCorrectParams, 'channelId')
137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
140 it('Should fail with a bad channel', async function () {
141 const fields = { ...baseCorrectParams, channelId: 545454 }
143 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
146 it('Should fail with another user channel', async function () {
149 password: 'fake_password'
151 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
153 const accessTokenUser = await userLogin(server, user)
154 const res = await getMyUserInformation(server.url, accessTokenUser)
155 const customChannelId = res.body.videoChannels[0].id
157 const fields = { ...baseCorrectParams, channelId: customChannelId }
159 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
162 it('Should fail with too many tags', async function () {
163 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
165 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
168 it('Should fail with a tag length too low', async function () {
169 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
171 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
174 it('Should fail with a tag length too big', async function () {
175 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
177 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
180 it('Should fail with an incorrect thumbnail file', async function () {
181 const fields = baseCorrectParams
183 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
186 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
189 it('Should fail with a big thumbnail file', async function () {
190 const fields = baseCorrectParams
192 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
195 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
198 it('Should fail with an incorrect preview file', async function () {
199 const fields = baseCorrectParams
201 previewfile: buildAbsoluteFixturePath('video_short.mp4')
204 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
207 it('Should fail with a big preview file', async function () {
208 const fields = baseCorrectParams
210 previewfile: buildAbsoluteFixturePath('preview-big.png')
213 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
216 it('Should fail with save replay and permanent live set to true', async function () {
217 const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true }
219 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
222 it('Should succeed with the correct parameters', async function () {
225 const res = await makePostBodyRequest({
228 token: server.accessToken,
229 fields: baseCorrectParams,
230 statusCodeExpected: HttpStatusCode.OK_200
233 video = res.body.video
236 it('Should forbid if live is disabled', async function () {
237 await server.configCommand.updateCustomSubConfig({
245 await makePostBodyRequest({
248 token: server.accessToken,
249 fields: baseCorrectParams,
250 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
254 it('Should forbid to save replay if not enabled by the admin', async function () {
255 const fields = { ...baseCorrectParams, saveReplay: true }
257 await server.configCommand.updateCustomSubConfig({
266 await makePostBodyRequest({
269 token: server.accessToken,
271 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
275 it('Should allow to save replay if enabled by the admin', async function () {
276 const fields = { ...baseCorrectParams, saveReplay: true }
278 await server.configCommand.updateCustomSubConfig({
287 await makePostBodyRequest({
290 token: server.accessToken,
292 statusCodeExpected: HttpStatusCode.OK_200
296 it('Should not allow live if max instance lives is reached', async function () {
297 await server.configCommand.updateCustomSubConfig({
306 await makePostBodyRequest({
309 token: server.accessToken,
310 fields: baseCorrectParams,
311 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
315 it('Should not allow live if max user lives is reached', async function () {
316 await server.configCommand.updateCustomSubConfig({
320 maxInstanceLives: 20,
326 await makePostBodyRequest({
329 token: server.accessToken,
330 fields: baseCorrectParams,
331 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
336 describe('When getting live information', function () {
338 it('Should fail without access token', async function () {
339 await command.get({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
342 it('Should fail with a bad access token', async function () {
343 await command.get({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
346 it('Should fail with access token of another user', async function () {
347 await command.get({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
350 it('Should fail with a bad video id', async function () {
351 await command.get({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
354 it('Should fail with an unknown video id', async function () {
355 await command.get({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
358 it('Should fail with a non live video', async function () {
359 await command.get({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
362 it('Should succeed with the correct params', async function () {
363 await command.get({ videoId: video.id })
364 await command.get({ videoId: video.uuid })
365 await command.get({ videoId: video.shortUUID })
369 describe('When updating live information', async function () {
371 it('Should fail without access token', async function () {
372 await command.update({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
375 it('Should fail with a bad access token', async function () {
376 await command.update({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
379 it('Should fail with access token of another user', async function () {
380 await command.update({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
383 it('Should fail with a bad video id', async function () {
384 await command.update({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
387 it('Should fail with an unknown video id', async function () {
388 await command.update({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
391 it('Should fail with a non live video', async function () {
392 await command.update({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
395 it('Should fail with save replay and permanent live set to true', async function () {
396 const fields = { saveReplay: true, permanentLive: true }
398 await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
401 it('Should succeed with the correct params', async function () {
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 } })
407 it('Should fail to update replay status if replay is not allowed on the instance', async function () {
408 await server.configCommand.updateCustomSubConfig({
417 await command.update({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
420 it('Should fail to update a live if it has already started', async function () {
423 const live = await command.get({ videoId: video.id })
425 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
427 await command.waitUntilPublished({ videoId: video.id })
428 await command.update({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
430 await stopFfmpeg(ffmpegCommand)
433 it('Should fail to stream twice in the save live', async function () {
436 const live = await command.get({ videoId: video.id })
438 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
440 await command.waitUntilPublished({ videoId: video.id })
442 await command.runAndTestStreamError({ videoId: video.id, shouldHaveError: true })
444 await stopFfmpeg(ffmpegCommand)
448 after(async function () {
449 await cleanupTests([ server ])