Fix getting live by anonymous user

pull/4977/head
Chocobozzz 2022-04-22 09:50:20 +02:00
parent c74cd9feab
commit 98ebfa3950
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 79 additions and 107 deletions

View File

@ -50,6 +50,50 @@ describe('Save replay setting', function () {
return uuid
}
async function publishLive (options: { permanent: boolean, replay: boolean }) {
liveVideoUUID = await createLiveWrapper(options)
const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
return { ffmpegCommand, liveDetails }
}
async function publishLiveAndDelete (options: { permanent: boolean, replay: boolean }) {
const { ffmpegCommand, liveDetails } = await publishLive(options)
await Promise.all([
servers[0].videos.remove({ id: liveVideoUUID }),
testFfmpegStreamError(ffmpegCommand, true)
])
await waitJobs(servers)
await wait(5000)
await waitJobs(servers)
return { liveDetails }
}
async function publishLiveAndBlacklist (options: { permanent: boolean, replay: boolean }) {
const { ffmpegCommand, liveDetails } = await publishLive(options)
await Promise.all([
servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
testFfmpegStreamError(ffmpegCommand, true)
])
await waitJobs(servers)
await wait(5000)
await waitJobs(servers)
return { liveDetails }
}
async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) {
for (const server of servers) {
const length = existsInList ? 1 : 0
@ -100,10 +144,6 @@ describe('Save replay setting', function () {
describe('With save replay disabled', function () {
before(async function () {
this.timeout(10000)
})
it('Should correctly create and federate the "waiting for stream" live', async function () {
this.timeout(20000)
@ -149,21 +189,7 @@ describe('Save replay setting', function () {
it('Should correctly terminate the stream on blacklist and delete the live', async function () {
this.timeout(40000)
liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false })
ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([
servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
testFfmpegStreamError(ffmpegCommand, true)
])
await waitJobs(servers)
await publishLiveAndBlacklist({ permanent: false, replay: false })
await checkVideosExist(liveVideoUUID, false)
@ -178,22 +204,7 @@ describe('Save replay setting', function () {
it('Should correctly terminate the stream on delete and delete the video', async function () {
this.timeout(40000)
liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false })
ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([
testFfmpegStreamError(ffmpegCommand, true),
servers[0].videos.remove({ id: liveVideoUUID })
])
await wait(5000)
await waitJobs(servers)
await publishLiveAndDelete({ permanent: false, replay: false })
await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
await checkLiveCleanup(servers[0], liveVideoUUID, [])
@ -258,20 +269,7 @@ describe('Save replay setting', function () {
it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
this.timeout(40000)
liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true })
ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([
servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
testFfmpegStreamError(ffmpegCommand, true)
])
await waitJobs(servers)
await publishLiveAndBlacklist({ permanent: false, replay: true })
await checkVideosExist(liveVideoUUID, false)
@ -286,21 +284,7 @@ describe('Save replay setting', function () {
it('Should correctly terminate the stream on delete and delete the video', async function () {
this.timeout(40000)
liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true })
ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([
servers[0].videos.remove({ id: liveVideoUUID }),
testFfmpegStreamError(ffmpegCommand, true)
])
await wait(5000)
await waitJobs(servers)
await publishLiveAndDelete({ permanent: false, replay: true })
await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
await checkLiveCleanup(servers[0], liveVideoUUID, [])
@ -361,25 +345,7 @@ describe('Save replay setting', function () {
this.timeout(60000)
await servers[0].videos.remove({ id: lastReplayUUID })
liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true })
ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([
servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
testFfmpegStreamError(ffmpegCommand, true)
])
await waitJobs(servers)
await wait(5000)
await waitJobs(servers)
const { liveDetails } = await publishLiveAndBlacklist({ permanent: true, replay: true })
const replay = await findExternalSavedVideo(servers[0], liveDetails)
expect(replay).to.exist
@ -397,23 +363,7 @@ describe('Save replay setting', function () {
it('Should correctly terminate the stream on delete and not save the video', async function () {
this.timeout(40000)
liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true })
ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
await waitJobs(servers)
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([
servers[0].videos.remove({ id: liveVideoUUID }),
testFfmpegStreamError(ffmpegCommand, true)
])
await wait(5000)
await waitJobs(servers)
const { liveDetails } = await publishLiveAndDelete({ permanent: true, replay: true })
const replay = await findExternalSavedVideo(servers[0], liveDetails)
expect(replay).to.not.exist

View File

@ -590,13 +590,17 @@ describe('Test live', function () {
describe('After a server restart', function () {
let liveVideoId: string
let liveVideoReplayId: string
let permanentLiveVideoReplayId: string
async function createLiveWrapper (saveReplay: boolean) {
const liveAttributes = {
let permanentLiveReplayName: string
async function createLiveWrapper (options: { saveReplay: boolean, permanent: boolean }) {
const liveAttributes: LiveVideoCreate = {
name: 'live video',
channelId: servers[0].store.channel.id,
privacy: VideoPrivacy.PUBLIC,
saveReplay
saveReplay: options.saveReplay,
permanentLive: options.permanent
}
const { uuid } = await commands[0].create({ fields: liveAttributes })
@ -604,41 +608,59 @@ describe('Test live', function () {
}
before(async function () {
this.timeout(120000)
this.timeout(160000)
liveVideoId = await createLiveWrapper(false)
liveVideoReplayId = await createLiveWrapper(true)
liveVideoId = await createLiveWrapper({ saveReplay: false, permanent: false })
liveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: false })
permanentLiveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: true })
await Promise.all([
commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }),
commands[0].sendRTMPStreamInVideo({ videoId: permanentLiveVideoReplayId }),
commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId })
])
await Promise.all([
commands[0].waitUntilPublished({ videoId: liveVideoId }),
commands[0].waitUntilPublished({ videoId: permanentLiveVideoReplayId }),
commands[0].waitUntilPublished({ videoId: liveVideoReplayId })
])
await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 })
await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 })
await commands[0].waitUntilSegmentGeneration({ videoUUID: permanentLiveVideoReplayId, resolution: 0, segment: 2 })
{
const video = await servers[0].videos.get({ id: permanentLiveVideoReplayId })
permanentLiveReplayName = video.name + ' - ' + new Date(video.publishedAt).toLocaleString()
}
await killallServers([ servers[0] ])
await servers[0].run()
await wait(5000)
await waitJobs(servers)
})
it('Should cleanup lives', async function () {
this.timeout(60000)
await commands[0].waitUntilEnded({ videoId: liveVideoId })
await commands[0].waitUntilWaiting({ videoId: permanentLiveVideoReplayId })
})
it('Should save a live replay', async function () {
it('Should save a non permanent live replay', async function () {
this.timeout(120000)
await commands[0].waitUntilPublished({ videoId: liveVideoReplayId })
})
it('Should have saved a permanent live replay', async function () {
this.timeout(120000)
const { data } = await servers[0].videos.listMyVideos({ sort: '-publishedAt' })
expect(data.find(v => v.name === permanentLiveReplayName)).to.exist
})
})
after(async function () {