aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-04-22 09:50:20 +0200
committerChocobozzz <me@florianbigard.com>2022-05-03 08:32:20 +0200
commit98ebfa39500ce9dfbb782e43c4d269f9a2989698 (patch)
tree8ef016f780601ddfca8f907d2a18efb2d91d3ec9 /server
parentc74cd9feaba583fc40c61d1c3a7c036267a56ea1 (diff)
downloadPeerTube-98ebfa39500ce9dfbb782e43c4d269f9a2989698.tar.gz
PeerTube-98ebfa39500ce9dfbb782e43c4d269f9a2989698.tar.zst
PeerTube-98ebfa39500ce9dfbb782e43c4d269f9a2989698.zip
Fix getting live by anonymous user
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/live/live-save-replay.ts150
-rw-r--r--server/tests/api/live/live.ts36
2 files changed, 79 insertions, 107 deletions
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts
index ba68a4287..fc6acc624 100644
--- a/server/tests/api/live/live-save-replay.ts
+++ b/server/tests/api/live/live-save-replay.ts
@@ -50,6 +50,50 @@ describe('Save replay setting', function () {
50 return uuid 50 return uuid
51 } 51 }
52 52
53 async function publishLive (options: { permanent: boolean, replay: boolean }) {
54 liveVideoUUID = await createLiveWrapper(options)
55
56 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
57 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
58
59 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
60
61 await waitJobs(servers)
62 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
63
64 return { ffmpegCommand, liveDetails }
65 }
66
67 async function publishLiveAndDelete (options: { permanent: boolean, replay: boolean }) {
68 const { ffmpegCommand, liveDetails } = await publishLive(options)
69
70 await Promise.all([
71 servers[0].videos.remove({ id: liveVideoUUID }),
72 testFfmpegStreamError(ffmpegCommand, true)
73 ])
74
75 await waitJobs(servers)
76 await wait(5000)
77 await waitJobs(servers)
78
79 return { liveDetails }
80 }
81
82 async function publishLiveAndBlacklist (options: { permanent: boolean, replay: boolean }) {
83 const { ffmpegCommand, liveDetails } = await publishLive(options)
84
85 await Promise.all([
86 servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
87 testFfmpegStreamError(ffmpegCommand, true)
88 ])
89
90 await waitJobs(servers)
91 await wait(5000)
92 await waitJobs(servers)
93
94 return { liveDetails }
95 }
96
53 async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) { 97 async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) {
54 for (const server of servers) { 98 for (const server of servers) {
55 const length = existsInList ? 1 : 0 99 const length = existsInList ? 1 : 0
@@ -100,10 +144,6 @@ describe('Save replay setting', function () {
100 144
101 describe('With save replay disabled', function () { 145 describe('With save replay disabled', function () {
102 146
103 before(async function () {
104 this.timeout(10000)
105 })
106
107 it('Should correctly create and federate the "waiting for stream" live', async function () { 147 it('Should correctly create and federate the "waiting for stream" live', async function () {
108 this.timeout(20000) 148 this.timeout(20000)
109 149
@@ -149,21 +189,7 @@ describe('Save replay setting', function () {
149 it('Should correctly terminate the stream on blacklist and delete the live', async function () { 189 it('Should correctly terminate the stream on blacklist and delete the live', async function () {
150 this.timeout(40000) 190 this.timeout(40000)
151 191
152 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false }) 192 await publishLiveAndBlacklist({ permanent: false, replay: false })
153
154 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
155
156 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
157
158 await waitJobs(servers)
159 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
160
161 await Promise.all([
162 servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
163 testFfmpegStreamError(ffmpegCommand, true)
164 ])
165
166 await waitJobs(servers)
167 193
168 await checkVideosExist(liveVideoUUID, false) 194 await checkVideosExist(liveVideoUUID, false)
169 195
@@ -178,22 +204,7 @@ describe('Save replay setting', function () {
178 it('Should correctly terminate the stream on delete and delete the video', async function () { 204 it('Should correctly terminate the stream on delete and delete the video', async function () {
179 this.timeout(40000) 205 this.timeout(40000)
180 206
181 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: false }) 207 await publishLiveAndDelete({ permanent: false, replay: false })
182
183 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
184
185 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
186
187 await waitJobs(servers)
188 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
189
190 await Promise.all([
191 testFfmpegStreamError(ffmpegCommand, true),
192 servers[0].videos.remove({ id: liveVideoUUID })
193 ])
194
195 await wait(5000)
196 await waitJobs(servers)
197 208
198 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 209 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
199 await checkLiveCleanup(servers[0], liveVideoUUID, []) 210 await checkLiveCleanup(servers[0], liveVideoUUID, [])
@@ -258,20 +269,7 @@ describe('Save replay setting', function () {
258 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { 269 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
259 this.timeout(40000) 270 this.timeout(40000)
260 271
261 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true }) 272 await publishLiveAndBlacklist({ permanent: false, replay: true })
262
263 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
264 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
265
266 await waitJobs(servers)
267 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
268
269 await Promise.all([
270 servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
271 testFfmpegStreamError(ffmpegCommand, true)
272 ])
273
274 await waitJobs(servers)
275 273
276 await checkVideosExist(liveVideoUUID, false) 274 await checkVideosExist(liveVideoUUID, false)
277 275
@@ -286,21 +284,7 @@ describe('Save replay setting', function () {
286 it('Should correctly terminate the stream on delete and delete the video', async function () { 284 it('Should correctly terminate the stream on delete and delete the video', async function () {
287 this.timeout(40000) 285 this.timeout(40000)
288 286
289 liveVideoUUID = await createLiveWrapper({ permanent: false, replay: true }) 287 await publishLiveAndDelete({ permanent: false, replay: true })
290
291 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
292 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
293
294 await waitJobs(servers)
295 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
296
297 await Promise.all([
298 servers[0].videos.remove({ id: liveVideoUUID }),
299 testFfmpegStreamError(ffmpegCommand, true)
300 ])
301
302 await wait(5000)
303 await waitJobs(servers)
304 288
305 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) 289 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
306 await checkLiveCleanup(servers[0], liveVideoUUID, []) 290 await checkLiveCleanup(servers[0], liveVideoUUID, [])
@@ -361,25 +345,7 @@ describe('Save replay setting', function () {
361 this.timeout(60000) 345 this.timeout(60000)
362 346
363 await servers[0].videos.remove({ id: lastReplayUUID }) 347 await servers[0].videos.remove({ id: lastReplayUUID })
364 348 const { liveDetails } = await publishLiveAndBlacklist({ permanent: true, replay: true })
365 liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true })
366
367 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
368 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
369
370 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
371
372 await waitJobs(servers)
373 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
374
375 await Promise.all([
376 servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
377 testFfmpegStreamError(ffmpegCommand, true)
378 ])
379
380 await waitJobs(servers)
381 await wait(5000)
382 await waitJobs(servers)
383 349
384 const replay = await findExternalSavedVideo(servers[0], liveDetails) 350 const replay = await findExternalSavedVideo(servers[0], liveDetails)
385 expect(replay).to.exist 351 expect(replay).to.exist
@@ -397,23 +363,7 @@ describe('Save replay setting', function () {
397 it('Should correctly terminate the stream on delete and not save the video', async function () { 363 it('Should correctly terminate the stream on delete and not save the video', async function () {
398 this.timeout(40000) 364 this.timeout(40000)
399 365
400 liveVideoUUID = await createLiveWrapper({ permanent: true, replay: true }) 366 const { liveDetails } = await publishLiveAndDelete({ permanent: true, replay: true })
401
402 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
403 await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
404
405 const liveDetails = await servers[0].videos.get({ id: liveVideoUUID })
406
407 await waitJobs(servers)
408 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
409
410 await Promise.all([
411 servers[0].videos.remove({ id: liveVideoUUID }),
412 testFfmpegStreamError(ffmpegCommand, true)
413 ])
414
415 await wait(5000)
416 await waitJobs(servers)
417 367
418 const replay = await findExternalSavedVideo(servers[0], liveDetails) 368 const replay = await findExternalSavedVideo(servers[0], liveDetails)
419 expect(replay).to.not.exist 369 expect(replay).to.not.exist
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts
index b8c4c1e29..ab7251e31 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -590,13 +590,17 @@ describe('Test live', function () {
590 describe('After a server restart', function () { 590 describe('After a server restart', function () {
591 let liveVideoId: string 591 let liveVideoId: string
592 let liveVideoReplayId: string 592 let liveVideoReplayId: string
593 let permanentLiveVideoReplayId: string
593 594
594 async function createLiveWrapper (saveReplay: boolean) { 595 let permanentLiveReplayName: string
595 const liveAttributes = { 596
597 async function createLiveWrapper (options: { saveReplay: boolean, permanent: boolean }) {
598 const liveAttributes: LiveVideoCreate = {
596 name: 'live video', 599 name: 'live video',
597 channelId: servers[0].store.channel.id, 600 channelId: servers[0].store.channel.id,
598 privacy: VideoPrivacy.PUBLIC, 601 privacy: VideoPrivacy.PUBLIC,
599 saveReplay 602 saveReplay: options.saveReplay,
603 permanentLive: options.permanent
600 } 604 }
601 605
602 const { uuid } = await commands[0].create({ fields: liveAttributes }) 606 const { uuid } = await commands[0].create({ fields: liveAttributes })
@@ -604,41 +608,59 @@ describe('Test live', function () {
604 } 608 }
605 609
606 before(async function () { 610 before(async function () {
607 this.timeout(120000) 611 this.timeout(160000)
608 612
609 liveVideoId = await createLiveWrapper(false) 613 liveVideoId = await createLiveWrapper({ saveReplay: false, permanent: false })
610 liveVideoReplayId = await createLiveWrapper(true) 614 liveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: false })
615 permanentLiveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: true })
611 616
612 await Promise.all([ 617 await Promise.all([
613 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }), 618 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }),
619 commands[0].sendRTMPStreamInVideo({ videoId: permanentLiveVideoReplayId }),
614 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId }) 620 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId })
615 ]) 621 ])
616 622
617 await Promise.all([ 623 await Promise.all([
618 commands[0].waitUntilPublished({ videoId: liveVideoId }), 624 commands[0].waitUntilPublished({ videoId: liveVideoId }),
625 commands[0].waitUntilPublished({ videoId: permanentLiveVideoReplayId }),
619 commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) 626 commands[0].waitUntilPublished({ videoId: liveVideoReplayId })
620 ]) 627 ])
621 628
622 await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) 629 await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 })
623 await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) 630 await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 })
631 await commands[0].waitUntilSegmentGeneration({ videoUUID: permanentLiveVideoReplayId, resolution: 0, segment: 2 })
632
633 {
634 const video = await servers[0].videos.get({ id: permanentLiveVideoReplayId })
635 permanentLiveReplayName = video.name + ' - ' + new Date(video.publishedAt).toLocaleString()
636 }
624 637
625 await killallServers([ servers[0] ]) 638 await killallServers([ servers[0] ])
626 await servers[0].run() 639 await servers[0].run()
627 640
628 await wait(5000) 641 await wait(5000)
642 await waitJobs(servers)
629 }) 643 })
630 644
631 it('Should cleanup lives', async function () { 645 it('Should cleanup lives', async function () {
632 this.timeout(60000) 646 this.timeout(60000)
633 647
634 await commands[0].waitUntilEnded({ videoId: liveVideoId }) 648 await commands[0].waitUntilEnded({ videoId: liveVideoId })
649 await commands[0].waitUntilWaiting({ videoId: permanentLiveVideoReplayId })
635 }) 650 })
636 651
637 it('Should save a live replay', async function () { 652 it('Should save a non permanent live replay', async function () {
638 this.timeout(120000) 653 this.timeout(120000)
639 654
640 await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) 655 await commands[0].waitUntilPublished({ videoId: liveVideoReplayId })
641 }) 656 })
657
658 it('Should have saved a permanent live replay', async function () {
659 this.timeout(120000)
660
661 const { data } = await servers[0].videos.listMyVideos({ sort: '-publishedAt' })
662 expect(data.find(v => v.name === permanentLiveReplayName)).to.exist
663 })
642 }) 664 })
643 665
644 after(async function () { 666 after(async function () {