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 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 = ''
32 let accountName: string
34 let channelName: string
36 let videoIdNotLive: number
38 // ---------------------------------------------------------------
40 before(async function () {
43 server = await flushAndRunServer(1)
45 await setAccessTokensToServers([ server ])
47 await updateCustomSubConfig(server.url, server.accessToken, {
56 const username = 'user1'
57 const password = 'my super password'
58 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
59 userAccessToken = await userLogin(server, { username, password })
62 const res = await getMyUserInformation(server.url, server.accessToken)
63 channelId = res.body.videoChannels[0].id
67 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id
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,
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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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: join(__dirname, '..', '..', 'fixtures', 'avatar-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: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
213 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
216 it('Should succeed with the correct parameters', async function () {
219 const res = await makePostBodyRequest({
222 token: server.accessToken,
223 fields: baseCorrectParams,
224 statusCodeExpected: 200
227 videoId = res.body.video.id
230 it('Should forbid if live is disabled', async function () {
231 await updateCustomSubConfig(server.url, server.accessToken, {
237 await makePostBodyRequest({
240 token: server.accessToken,
241 fields: baseCorrectParams,
242 statusCodeExpected: 403
246 it('Should forbid to save replay if not enabled by the admin', async function () {
247 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
249 await updateCustomSubConfig(server.url, server.accessToken, {
256 await makePostBodyRequest({
259 token: server.accessToken,
261 statusCodeExpected: 403
265 it('Should allow to save replay if enabled by the admin', async function () {
266 const fields = immutableAssign(baseCorrectParams, { saveReplay: true })
268 await updateCustomSubConfig(server.url, server.accessToken, {
275 await makePostBodyRequest({
278 token: server.accessToken,
280 statusCodeExpected: 200
284 it('Should not allow live if max instance lives is reached', async function () {
285 await updateCustomSubConfig(server.url, server.accessToken, {
292 await makePostBodyRequest({
295 token: server.accessToken,
296 fields: baseCorrectParams,
297 statusCodeExpected: 403
301 it('Should not allow live if max user lives is reached', async function () {
302 await updateCustomSubConfig(server.url, server.accessToken, {
305 maxInstanceLives: 20,
310 await makePostBodyRequest({
313 token: server.accessToken,
314 fields: baseCorrectParams,
315 statusCodeExpected: 403
320 describe('When getting live information', function () {
322 it('Should fail without access token', async function () {
323 await getLive(server.url, '', videoId, 401)
326 it('Should fail with a bad access token', async function () {
327 await getLive(server.url, 'toto', videoId, 401)
330 it('Should fail with access token of another user', async function () {
331 await getLive(server.url, userAccessToken, videoId, 403)
334 it('Should fail with a bad video id', async function () {
335 await getLive(server.url, server.accessToken, 'toto', 400)
338 it('Should fail with an unknown video id', async function () {
339 await getLive(server.url, server.accessToken, 454555, 404)
342 it('Should fail with a non live video', async function () {
343 await getLive(server.url, server.accessToken, videoIdNotLive, 404)
346 it('Should succeed with the correct params', async function () {
347 await getLive(server.url, server.accessToken, videoId)
351 describe('When updating live information', async function () {
353 it('Should fail without access token', async function () {
354 await updateLive(server.url, '', videoId, {}, 401)
357 it('Should fail with a bad access token', async function () {
358 await updateLive(server.url, 'toto', videoId, {}, 401)
361 it('Should fail with access token of another user', async function () {
362 await updateLive(server.url, userAccessToken, videoId, {}, 403)
365 it('Should fail with a bad video id', async function () {
366 await updateLive(server.url, server.accessToken, 'toto', {}, 400)
369 it('Should fail with an unknown video id', async function () {
370 await updateLive(server.url, server.accessToken, 454555, {}, 404)
373 it('Should fail with a non live video', async function () {
374 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, 404)
377 it('Should succeed with the correct params', async function () {
378 await updateLive(server.url, server.accessToken, videoId, { saveReplay: false })
381 it('Should fail to update replay status if replay is not allowed on the instance', async function () {
382 await updateCustomSubConfig(server.url, server.accessToken, {
389 await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, 403)
392 it('Should fail to update a live if it has already started', async function () {
395 const resLive = await getLive(server.url, server.accessToken, videoId)
396 const live: LiveVideo = resLive.body
398 const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
400 await waitUntilLiveStarts(server.url, server.accessToken, videoId)
401 await updateLive(server.url, server.accessToken, videoId, {}, 400)
403 await stopFfmpeg(command)
407 after(async function () {
408 await cleanupTests([ server ])