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,
21 } from '../../../../shared/extra-utils'
23 describe('Test video lives API validator', function () {
24 const path = '/api/v1/videos/live'
25 let server: ServerInfo
26 let userAccessToken = ''
28 let video: VideoCreateResult
29 let videoIdNotLive: number
30 let command: LiveCommand
32 // ---------------------------------------------------------------
34 before(async function () {
37 server = await flushAndRunServer(1)
39 await setAccessTokensToServers([ server ])
41 await server.configCommand.updateCustomSubConfig({
52 const username = 'user1'
53 const password = 'my super password'
54 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
55 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
58 const res = await getMyUserInformation(server.url, server.accessToken)
59 channelId = res.body.videoChannels[0].id
63 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
66 command = server.liveCommand
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,
92 it('Should fail with nothing', async function () {
94 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
97 it('Should fail with a long name', async function () {
98 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
103 it('Should fail with a bad category', async function () {
104 const fields = { ...baseCorrectParams, category: 125 }
106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
109 it('Should fail with a bad licence', async function () {
110 const fields = { ...baseCorrectParams, licence: 125 }
112 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
115 it('Should fail with a bad language', async function () {
116 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
118 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
121 it('Should fail with a long description', async function () {
122 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
124 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 it('Should fail with a long support text', async function () {
128 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
130 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
133 it('Should fail without a channel', async function () {
134 const fields = omit(baseCorrectParams, 'channelId')
136 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
139 it('Should fail with a bad channel', async function () {
140 const fields = { ...baseCorrectParams, channelId: 545454 }
142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
145 it('Should fail with another user channel', async function () {
148 password: 'fake_password'
150 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
152 const accessTokenUser = await server.loginCommand.getAccessToken(user)
153 const res = await getMyUserInformation(server.url, accessTokenUser)
154 const customChannelId = res.body.videoChannels[0].id
156 const fields = { ...baseCorrectParams, channelId: customChannelId }
158 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
161 it('Should fail with too many tags', async function () {
162 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
164 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
167 it('Should fail with a tag length too low', async function () {
168 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
170 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
173 it('Should fail with a tag length too big', async function () {
174 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
176 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
179 it('Should fail with an incorrect thumbnail file', async function () {
180 const fields = baseCorrectParams
182 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
185 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
188 it('Should fail with a big thumbnail file', async function () {
189 const fields = baseCorrectParams
191 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
194 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
197 it('Should fail with an incorrect preview file', async function () {
198 const fields = baseCorrectParams
200 previewfile: buildAbsoluteFixturePath('video_short.mp4')
203 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
206 it('Should fail with a big preview file', async function () {
207 const fields = baseCorrectParams
209 previewfile: buildAbsoluteFixturePath('preview-big.png')
212 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
215 it('Should fail with save replay and permanent live set to true', async function () {
216 const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true }
218 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
221 it('Should succeed with the correct parameters', async function () {
224 const res = await makePostBodyRequest({
227 token: server.accessToken,
228 fields: baseCorrectParams,
229 statusCodeExpected: HttpStatusCode.OK_200
232 video = res.body.video
235 it('Should forbid if live is disabled', async function () {
236 await server.configCommand.updateCustomSubConfig({
244 await makePostBodyRequest({
247 token: server.accessToken,
248 fields: baseCorrectParams,
249 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
253 it('Should forbid to save replay if not enabled by the admin', async function () {
254 const fields = { ...baseCorrectParams, saveReplay: true }
256 await server.configCommand.updateCustomSubConfig({
265 await makePostBodyRequest({
268 token: server.accessToken,
270 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
274 it('Should allow to save replay if enabled by the admin', async function () {
275 const fields = { ...baseCorrectParams, saveReplay: true }
277 await server.configCommand.updateCustomSubConfig({
286 await makePostBodyRequest({
289 token: server.accessToken,
291 statusCodeExpected: HttpStatusCode.OK_200
295 it('Should not allow live if max instance lives is reached', async function () {
296 await server.configCommand.updateCustomSubConfig({
305 await makePostBodyRequest({
308 token: server.accessToken,
309 fields: baseCorrectParams,
310 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
314 it('Should not allow live if max user lives is reached', async function () {
315 await server.configCommand.updateCustomSubConfig({
319 maxInstanceLives: 20,
325 await makePostBodyRequest({
328 token: server.accessToken,
329 fields: baseCorrectParams,
330 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
335 describe('When getting live information', function () {
337 it('Should fail without access token', async function () {
338 await command.get({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
341 it('Should fail with a bad access token', async function () {
342 await command.get({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
345 it('Should fail with access token of another user', async function () {
346 await command.get({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
349 it('Should fail with a bad video id', async function () {
350 await command.get({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
353 it('Should fail with an unknown video id', async function () {
354 await command.get({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
357 it('Should fail with a non live video', async function () {
358 await command.get({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
361 it('Should succeed with the correct params', async function () {
362 await command.get({ videoId: video.id })
363 await command.get({ videoId: video.uuid })
364 await command.get({ videoId: video.shortUUID })
368 describe('When updating live information', async function () {
370 it('Should fail without access token', async function () {
371 await command.update({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
374 it('Should fail with a bad access token', async function () {
375 await command.update({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
378 it('Should fail with access token of another user', async function () {
379 await command.update({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
382 it('Should fail with a bad video id', async function () {
383 await command.update({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
386 it('Should fail with an unknown video id', async function () {
387 await command.update({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
390 it('Should fail with a non live video', async function () {
391 await command.update({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
394 it('Should fail with save replay and permanent live set to true', async function () {
395 const fields = { saveReplay: true, permanentLive: true }
397 await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
400 it('Should succeed with the correct params', async function () {
401 await command.update({ videoId: video.id, fields: { saveReplay: false } })
402 await command.update({ videoId: video.uuid, fields: { saveReplay: false } })
403 await command.update({ videoId: video.shortUUID, fields: { saveReplay: false } })
406 it('Should fail to update replay status if replay is not allowed on the instance', async function () {
407 await server.configCommand.updateCustomSubConfig({
416 await command.update({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
419 it('Should fail to update a live if it has already started', async function () {
422 const live = await command.get({ videoId: video.id })
424 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
426 await command.waitUntilPublished({ videoId: video.id })
427 await command.update({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
429 await stopFfmpeg(ffmpegCommand)
432 it('Should fail to stream twice in the save live', async function () {
435 const live = await command.get({ videoId: video.id })
437 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
439 await command.waitUntilPublished({ videoId: video.id })
441 await command.runAndTestStreamError({ videoId: video.id, shouldHaveError: true })
443 await stopFfmpeg(ffmpegCommand)
447 after(async function () {
448 await cleanupTests([ server ])