1
0
Fork 0

Blocked users must not be able to live stream

This commit is contained in:
Chocobozzz 2024-02-15 14:27:52 +01:00
parent 5f09fde24e
commit ba3820965f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 34 additions and 12 deletions

View File

@ -286,15 +286,16 @@ describe('Test live', function () {
rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + '' rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + ''
}) })
async function createLiveWrapper () { async function createLiveWrapper (token?: string, channelId?: number) {
const liveAttributes = { const { uuid } = await commands[0].create({
name: 'user live', token,
channelId: servers[0].store.channel.id, fields: {
privacy: VideoPrivacy.PUBLIC, name: 'user live',
saveReplay: false channelId: channelId ?? servers[0].store.channel.id,
} privacy: VideoPrivacy.PUBLIC,
saveReplay: false
const { uuid } = await commands[0].create({ fields: liveAttributes }) }
})
const live = await commands[0].get({ videoId: uuid }) const live = await commands[0].get({ videoId: uuid })
const video = await servers[0].videos.get({ id: uuid }) const video = await servers[0].videos.get({ id: uuid })
@ -349,6 +350,18 @@ describe('Test live', function () {
await testFfmpegStreamError(command, true) 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 () { it('Should not allow a stream on a live that was deleted', async function () {
this.timeout(60000) this.timeout(60000)

View File

@ -18,7 +18,7 @@ import { VideoLiveSessionModel } from '@server/models/video/video-live-session.j
import { VideoLiveModel } from '@server/models/video/video-live.js' import { VideoLiveModel } from '@server/models/video/video-live.js'
import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js'
import { VideoModel } from '@server/models/video/video.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 { import {
ffprobePromise, ffprobePromise,
getVideoStreamBitrate, getVideoStreamBitrate,
@ -250,6 +250,12 @@ class LiveManager {
return this.abortSession(sessionId) 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)) { 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)) logger.warn('Video %s has already a live session. Refusing stream %s.', video.uuid, streamKey, lTags(sessionId, video.uuid))
return this.abortSession(sessionId) return this.abortSession(sessionId)
@ -295,6 +301,8 @@ class LiveManager {
sessionId, sessionId,
videoLive, videoLive,
user,
inputLocalUrl, inputLocalUrl,
inputPublicUrl, inputPublicUrl,
fps, fps,
@ -309,6 +317,8 @@ class LiveManager {
sessionId: string sessionId: string
videoLive: MVideoLiveVideoWithSetting videoLive: MVideoLiveVideoWithSetting
user: MUser
inputLocalUrl: string inputLocalUrl: string
inputPublicUrl: string inputPublicUrl: string
@ -318,13 +328,12 @@ class LiveManager {
allResolutions: number[] allResolutions: number[]
hasAudio: boolean hasAudio: boolean
}) { }) {
const { sessionId, videoLive } = options const { sessionId, videoLive, user } = options
const videoUUID = videoLive.Video.uuid const videoUUID = videoLive.Video.uuid
const localLTags = lTags(sessionId, videoUUID) const localLTags = lTags(sessionId, videoUUID)
const liveSession = await this.saveStartingSession(videoLive) const liveSession = await this.saveStartingSession(videoLive)
const user = await UserModel.loadByLiveId(videoLive.id)
LiveQuotaStore.Instance.addNewLive(user.id, sessionId) LiveQuotaStore.Instance.addNewLive(user.id, sessionId)
const muxingSession = new MuxingSession({ const muxingSession = new MuxingSession({