diff options
author | Chocobozzz <me@florianbigard.com> | 2022-12-02 14:47:21 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-12-02 15:25:20 +0100 |
commit | 71e3e879c0616882ee82a0e44f8c2e5ee9698a3e (patch) | |
tree | 14452d26d240eb6d44178b76fc2dabda4cfc9428 /server/tests/shared/streaming-playlists.ts | |
parent | 04509c43254dc232c61681ac4bb98e09fd126115 (diff) | |
download | PeerTube-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.ts | 50 |
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 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { basename } from 'path' | 4 | import { basename, dirname, join } from 'path' |
5 | import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils' | 5 | import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils' |
6 | import { sha256 } from '@shared/extra-utils' | 6 | import { sha256 } from '@shared/extra-utils' |
7 | import { HttpStatusCode, VideoStreamingPlaylist, VideoStreamingPlaylistType } from '@shared/models' | 7 | import { HttpStatusCode, VideoStreamingPlaylist, VideoStreamingPlaylistType } from '@shared/models' |
@@ -188,9 +188,55 @@ async function completeCheckHlsPlaylist (options: { | |||
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | async 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 | |||
230 | function extractResolutionPlaylistUrls (masterPath: string, masterContent: string) { | ||
231 | return masterContent.match(/^([^.]+\.m3u8.*)/mg) | ||
232 | .map(filename => join(dirname(masterPath), filename)) | ||
233 | } | ||
234 | |||
191 | export { | 235 | export { |
192 | checkSegmentHash, | 236 | checkSegmentHash, |
193 | checkLiveSegmentHash, | 237 | checkLiveSegmentHash, |
194 | checkResolutionsInMasterPlaylist, | 238 | checkResolutionsInMasterPlaylist, |
195 | completeCheckHlsPlaylist | 239 | completeCheckHlsPlaylist, |
240 | extractResolutionPlaylistUrls, | ||
241 | checkVideoFileTokenReinjection | ||
196 | } | 242 | } |