From ba3820965fd185b6314f137f91c55a68048e13e9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Feb 2024 14:27:52 +0100 Subject: [PATCH] Blocked users must not be able to live stream --- packages/tests/src/api/live/live.ts | 31 ++++++++++++++++++++-------- server/core/lib/live/live-manager.ts | 15 +++++++++++--- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/packages/tests/src/api/live/live.ts b/packages/tests/src/api/live/live.ts index c12311c4c..ac839c872 100644 --- a/packages/tests/src/api/live/live.ts +++ b/packages/tests/src/api/live/live.ts @@ -286,15 +286,16 @@ describe('Test live', function () { rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + '' }) - async function createLiveWrapper () { - const liveAttributes = { - name: 'user live', - channelId: servers[0].store.channel.id, - privacy: VideoPrivacy.PUBLIC, - saveReplay: false - } - - const { uuid } = await commands[0].create({ fields: liveAttributes }) + async function createLiveWrapper (token?: string, channelId?: number) { + const { uuid } = await commands[0].create({ + token, + fields: { + name: 'user live', + channelId: channelId ?? servers[0].store.channel.id, + privacy: VideoPrivacy.PUBLIC, + saveReplay: false + } + }) const live = await commands[0].get({ videoId: uuid }) const video = await servers[0].videos.get({ id: uuid }) @@ -349,6 +350,18 @@ describe('Test live', function () { await testFfmpegStreamError(command, true) }) + it('Should not allow a stream on if the owner has been blocked', async function () { + this.timeout(60000) + + const { token, userId, userChannelId } = await servers[0].users.generate('user1') + liveVideo = await createLiveWrapper(token, userChannelId) + + await servers[0].users.banUser({ userId }) + + const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) + await testFfmpegStreamError(command, true) + }) + it('Should not allow a stream on a live that was deleted', async function () { this.timeout(60000) diff --git a/server/core/lib/live/live-manager.ts b/server/core/lib/live/live-manager.ts index a5b382e33..bfe13066d 100644 --- a/server/core/lib/live/live-manager.ts +++ b/server/core/lib/live/live-manager.ts @@ -18,7 +18,7 @@ import { VideoLiveSessionModel } from '@server/models/video/video-live-session.j import { VideoLiveModel } from '@server/models/video/video-live.js' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js' import { VideoModel } from '@server/models/video/video.js' -import { MVideo, MVideoLiveSession, MVideoLiveVideo, MVideoLiveVideoWithSetting } from '@server/types/models/index.js' +import { MUser, MVideo, MVideoLiveSession, MVideoLiveVideo, MVideoLiveVideoWithSetting } from '@server/types/models/index.js' import { ffprobePromise, getVideoStreamBitrate, @@ -250,6 +250,12 @@ class LiveManager { return this.abortSession(sessionId) } + const user = await UserModel.loadByLiveId(videoLive.id) + if (user.blocked) { + logger.warn('User is blocked. Refusing stream %s.', streamKey, lTags(sessionId, video.uuid)) + return this.abortSession(sessionId) + } + if (this.videoSessions.has(video.uuid)) { logger.warn('Video %s has already a live session. Refusing stream %s.', video.uuid, streamKey, lTags(sessionId, video.uuid)) return this.abortSession(sessionId) @@ -295,6 +301,8 @@ class LiveManager { sessionId, videoLive, + user, + inputLocalUrl, inputPublicUrl, fps, @@ -309,6 +317,8 @@ class LiveManager { sessionId: string videoLive: MVideoLiveVideoWithSetting + user: MUser + inputLocalUrl: string inputPublicUrl: string @@ -318,13 +328,12 @@ class LiveManager { allResolutions: number[] hasAudio: boolean }) { - const { sessionId, videoLive } = options + const { sessionId, videoLive, user } = options const videoUUID = videoLive.Video.uuid const localLTags = lTags(sessionId, videoUUID) const liveSession = await this.saveStartingSession(videoLive) - const user = await UserModel.loadByLiveId(videoLive.id) LiveQuotaStore.Instance.addNewLive(user.id, sessionId) const muxingSession = new MuxingSession({