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 | |
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')
-rw-r--r-- | server/tests/shared/checks.ts | 7 | ||||
-rw-r--r-- | server/tests/shared/index.ts | 2 | ||||
-rw-r--r-- | server/tests/shared/streaming-playlists.ts | 50 | ||||
-rw-r--r-- | server/tests/shared/video-playlists.ts (renamed from server/tests/shared/playlists.ts) | 0 |
4 files changed, 56 insertions, 3 deletions
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts index 55ebc6c3e..523d37420 100644 --- a/server/tests/shared/checks.ts +++ b/server/tests/shared/checks.ts | |||
@@ -23,6 +23,12 @@ function expectNotStartWith (str: string, start: string) { | |||
23 | expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.false | 23 | expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.false |
24 | } | 24 | } |
25 | 25 | ||
26 | function expectEndWith (str: string, end: string) { | ||
27 | expect(str.endsWith(end), `${str} does not end with ${end}`).to.be.true | ||
28 | } | ||
29 | |||
30 | // --------------------------------------------------------------------------- | ||
31 | |||
26 | async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { | 32 | async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { |
27 | const content = await server.servers.getLogContent() | 33 | const content = await server.servers.getLogContent() |
28 | 34 | ||
@@ -103,6 +109,7 @@ export { | |||
103 | testFileExistsOrNot, | 109 | testFileExistsOrNot, |
104 | expectStartWith, | 110 | expectStartWith, |
105 | expectNotStartWith, | 111 | expectNotStartWith, |
112 | expectEndWith, | ||
106 | checkBadStartPagination, | 113 | checkBadStartPagination, |
107 | checkBadCountPagination, | 114 | checkBadCountPagination, |
108 | checkBadSortPagination, | 115 | checkBadSortPagination, |
diff --git a/server/tests/shared/index.ts b/server/tests/shared/index.ts index 9f7ade53d..963ef8fe6 100644 --- a/server/tests/shared/index.ts +++ b/server/tests/shared/index.ts | |||
@@ -6,7 +6,7 @@ export * from './directories' | |||
6 | export * from './generate' | 6 | export * from './generate' |
7 | export * from './live' | 7 | export * from './live' |
8 | export * from './notifications' | 8 | export * from './notifications' |
9 | export * from './playlists' | 9 | export * from './video-playlists' |
10 | export * from './plugins' | 10 | export * from './plugins' |
11 | export * from './requests' | 11 | export * from './requests' |
12 | export * from './streaming-playlists' | 12 | export * from './streaming-playlists' |
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 | } |
diff --git a/server/tests/shared/playlists.ts b/server/tests/shared/video-playlists.ts index 8db303fd8..8db303fd8 100644 --- a/server/tests/shared/playlists.ts +++ b/server/tests/shared/video-playlists.ts | |||