aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared/streaming-playlists.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-12-02 14:47:21 +0100
committerChocobozzz <me@florianbigard.com>2022-12-02 15:25:20 +0100
commit71e3e879c0616882ee82a0e44f8c2e5ee9698a3e (patch)
tree14452d26d240eb6d44178b76fc2dabda4cfc9428 /server/tests/shared/streaming-playlists.ts
parent04509c43254dc232c61681ac4bb98e09fd126115 (diff)
downloadPeerTube-71e3e879c0616882ee82a0e44f8c2e5ee9698a3e.tar.gz
PeerTube-71e3e879c0616882ee82a0e44f8c2e5ee9698a3e.tar.zst
PeerTube-71e3e879c0616882ee82a0e44f8c2e5ee9698a3e.zip
Support reinjecting token in private m3u8 playlist
Diffstat (limited to 'server/tests/shared/streaming-playlists.ts')
-rw-r--r--server/tests/shared/streaming-playlists.ts50
1 files changed, 48 insertions, 2 deletions
diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts
index 824c3dcef..5c62af812 100644
--- a/server/tests/shared/streaming-playlists.ts
+++ b/server/tests/shared/streaming-playlists.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { basename } from 'path' 4import { basename, dirname, join } from 'path'
5import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils' 5import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils'
6import { sha256 } from '@shared/extra-utils' 6import { sha256 } from '@shared/extra-utils'
7import { HttpStatusCode, VideoStreamingPlaylist, VideoStreamingPlaylistType } from '@shared/models' 7import { HttpStatusCode, VideoStreamingPlaylist, VideoStreamingPlaylistType } from '@shared/models'
@@ -188,9 +188,55 @@ async function completeCheckHlsPlaylist (options: {
188 } 188 }
189} 189}
190 190
191async function checkVideoFileTokenReinjection (options: {
192 server: PeerTubeServer
193 videoUUID: string
194 videoFileToken: string
195 resolutions: number[]
196 isLive: boolean
197}) {
198 const { server, resolutions, videoFileToken, videoUUID, isLive } = options
199
200 const video = await server.videos.getWithToken({ id: videoUUID })
201 const hls = video.streamingPlaylists[0]
202
203 const query = { videoFileToken, reinjectVideoFileToken: 'true' }
204 const { text } = await makeRawRequest({ url: hls.playlistUrl, query, expectedStatus: HttpStatusCode.OK_200 })
205
206 for (let i = 0; i < resolutions.length; i++) {
207 const resolution = resolutions[i]
208
209 const suffix = isLive
210 ? i
211 : `-${resolution}`
212
213 expect(text).to.contain(`${suffix}.m3u8?videoFileToken=${videoFileToken}`)
214 }
215
216 const resolutionPlaylists = extractResolutionPlaylistUrls(hls.playlistUrl, text)
217 expect(resolutionPlaylists).to.have.lengthOf(resolutions.length)
218
219 for (const url of resolutionPlaylists) {
220 const { text } = await makeRawRequest({ url, query, expectedStatus: HttpStatusCode.OK_200 })
221
222 const extension = isLive
223 ? '.ts'
224 : '.mp4'
225
226 expect(text).to.contain(`${extension}?videoFileToken=${videoFileToken}`)
227 }
228}
229
230function extractResolutionPlaylistUrls (masterPath: string, masterContent: string) {
231 return masterContent.match(/^([^.]+\.m3u8.*)/mg)
232 .map(filename => join(dirname(masterPath), filename))
233}
234
191export { 235export {
192 checkSegmentHash, 236 checkSegmentHash,
193 checkLiveSegmentHash, 237 checkLiveSegmentHash,
194 checkResolutionsInMasterPlaylist, 238 checkResolutionsInMasterPlaylist,
195 completeCheckHlsPlaylist 239 completeCheckHlsPlaylist,
240 extractResolutionPlaylistUrls,
241 checkVideoFileTokenReinjection
196} 242}