aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/shared')
-rw-r--r--server/tests/shared/checks.ts7
-rw-r--r--server/tests/shared/index.ts2
-rw-r--r--server/tests/shared/streaming-playlists.ts50
-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
26function expectEndWith (str: string, end: string) {
27 expect(str.endsWith(end), `${str} does not end with ${end}`).to.be.true
28}
29
30// ---------------------------------------------------------------------------
31
26async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { 32async 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'
6export * from './generate' 6export * from './generate'
7export * from './live' 7export * from './live'
8export * from './notifications' 8export * from './notifications'
9export * from './playlists' 9export * from './video-playlists'
10export * from './plugins' 10export * from './plugins'
11export * from './requests' 11export * from './requests'
12export * from './streaming-playlists' 12export * 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
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}
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