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,
19 setAccessTokensToServers,
23 } from '../../../../shared/extra-utils'
25 describe('Test video lives API validator', function () {
26 const path = '/api/v1/videos/live'
27 let server: ServerInfo
28 let userAccessToken = ''
30 let video: VideoCreateResult
31 let videoIdNotLive: number
32 let command: LiveCommand
34 // ---------------------------------------------------------------
36 before(async function () {
39 server = await flushAndRunServer(1)
41 await setAccessTokensToServers([ server ])
43 await server.configCommand.updateCustomSubConfig({
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
68 command = server.liveCommand
71 describe('When creating a live', function () {
76 name: 'my super name',
81 commentsEnabled: true,
82 downloadEnabled: true,
83 waitTranscoding: true,
84 description: 'my super description',
85 support: 'my super support text',
86 tags: [ 'tag1', 'tag2' ],
87 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: buildAbsoluteFixturePath('video_short.mp4')
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: buildAbsoluteFixturePath('preview-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: buildAbsoluteFixturePath('video_short.mp4')
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: buildAbsoluteFixturePath('preview-big.png')
214 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
217 it('Should fail with save replay and permanent live set to true', async function () {
218 const fields = immutableAssign(baseCorrectParams, { saveReplay: true, permanentLive: true })
220 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 it('Should succeed with the correct parameters', async function () {
226 const res = await makePostBodyRequest({
229 token: server.accessToken,
230 fields: baseCorrectParams,
231 statusCodeExpected: HttpStatusCode.OK_200
234 video = res.body.video
237 it('Should forbid if live is disabled', async function () {
238 await server.configCommand.updateCustomSubConfig({
246 await makePostBodyRequest({
249 token: server.accessToken,
250 fields: baseCorrectParams,
251 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
255 it('Should forbid to save replay if not enabled by the admin', async function () {
256 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
258 await server.configCommand.updateCustomSubConfig({
267 await makePostBodyRequest({
270 token: server.accessToken,
272 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
276 it('Should allow to save replay if enabled by the admin', async function () {
277 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
279 await server.configCommand.updateCustomSubConfig({
288 await makePostBodyRequest({
291 token: server.accessToken,
293 statusCodeExpected: HttpStatusCode.OK_200
297 it('Should not allow live if max instance lives is reached', async function () {
298 await server.configCommand.updateCustomSubConfig({
307 await makePostBodyRequest({
310 token: server.accessToken,
311 fields: baseCorrectParams,
312 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
316 it('Should not allow live if max user lives is reached', async function () {
317 await server.configCommand.updateCustomSubConfig({
321 maxInstanceLives: 20,
327 await makePostBodyRequest({
330 token: server.accessToken,
331 fields: baseCorrectParams,
332 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
337 describe('When getting live information', function () {
339 it('Should fail without access token', async function () {
340 await command.get({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
343 it('Should fail with a bad access token', async function () {
344 await command.get({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
347 it('Should fail with access token of another user', async function () {
348 await command.get({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
351 it('Should fail with a bad video id', async function () {
352 await command.get({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
355 it('Should fail with an unknown video id', async function () {
356 await command.get({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
359 it('Should fail with a non live video', async function () {
360 await command.get({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
363 it('Should succeed with the correct params', async function () {
364 await command.get({ videoId: video.id })
365 await command.get({ videoId: video.uuid })
366 await command.get({ videoId: video.shortUUID })
370 describe('When updating live information', async function () {
372 it('Should fail without access token', async function () {
373 await command.update({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
376 it('Should fail with a bad access token', async function () {
377 await command.update({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
380 it('Should fail with access token of another user', async function () {
381 await command.update({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
384 it('Should fail with a bad video id', async function () {
385 await command.update({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
388 it('Should fail with an unknown video id', async function () {
389 await command.update({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
392 it('Should fail with a non live video', async function () {
393 await command.update({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
396 it('Should fail with save replay and permanent live set to true', async function () {
397 const fields = { saveReplay: true, permanentLive: true }
399 await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
402 it('Should succeed with the correct params', async function () {
403 await command.update({ videoId: video.id, fields: { saveReplay: false } })
404 await command.update({ videoId: video.uuid, fields: { saveReplay: false } })
405 await command.update({ videoId: video.shortUUID, fields: { saveReplay: false } })
408 it('Should fail to update replay status if replay is not allowed on the instance', async function () {
409 await server.configCommand.updateCustomSubConfig({
418 await command.update({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
421 it('Should fail to update a live if it has already started', async function () {
424 const live = await command.get({ videoId: video.id })
426 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
428 await command.waitUntilPublished({ videoId: video.id })
429 await command.update({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
431 await stopFfmpeg(ffmpegCommand)
434 it('Should fail to stream twice in the save live', async function () {
437 const live = await command.get({ videoId: video.id })
439 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
441 await command.waitUntilPublished({ videoId: video.id })
443 await command.runAndTestStreamError({ videoId: video.id, shouldHaveError: true })
445 await stopFfmpeg(ffmpegCommand)
449 after(async function () {
450 await cleanupTests([ server ])