X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fshared%2Fstreaming-playlists.ts;h=1c38cb512ef99695add6b746f8a8dbcc54ee2898;hb=73fb3dc53571a6e94750a9d6cb5c2e949e1adcb9;hp=824c3dcefd40095777b5f8f9ab751f153ad94aa0;hpb=2f061e065ab43cc0b73595b619639a92952aeeba;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts index 824c3dcef..1c38cb512 100644 --- a/server/tests/shared/streaming-playlists.ts +++ b/server/tests/shared/streaming-playlists.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import { expect } from 'chai' -import { basename } from 'path' +import { basename, dirname, join } from 'path' import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils' import { sha256 } from '@shared/extra-utils' import { HttpStatusCode, VideoStreamingPlaylist, VideoStreamingPlaylistType } from '@shared/models' @@ -40,6 +40,8 @@ async function checkSegmentHash (options: { expect(sha256(segmentBody)).to.equal(shaBody[videoName][range]) } +// --------------------------------------------------------------------------- + async function checkLiveSegmentHash (options: { server: PeerTubeServer baseUrlSegment: string @@ -56,6 +58,8 @@ async function checkLiveSegmentHash (options: { expect(sha256(segmentBody)).to.equal(shaBody[segmentName]) } +// --------------------------------------------------------------------------- + async function checkResolutionsInMasterPlaylist (options: { server: PeerTubeServer playlistUrl: string @@ -188,9 +192,56 @@ async function completeCheckHlsPlaylist (options: { } } +async function checkVideoFileTokenReinjection (options: { + server: PeerTubeServer + videoUUID: string + videoFileToken: string + resolutions: number[] + isLive: boolean +}) { + const { server, resolutions, videoFileToken, videoUUID, isLive } = options + + const video = await server.videos.getWithToken({ id: videoUUID }) + const hls = video.streamingPlaylists[0] + + const query = { videoFileToken, reinjectVideoFileToken: 'true' } + const { text } = await makeRawRequest({ url: hls.playlistUrl, query, expectedStatus: HttpStatusCode.OK_200 }) + + for (let i = 0; i < resolutions.length; i++) { + const resolution = resolutions[i] + + const suffix = isLive + ? i + : `-${resolution}` + + expect(text).to.contain(`${suffix}.m3u8?videoFileToken=${videoFileToken}&reinjectVideoFileToken=true`) + } + + const resolutionPlaylists = extractResolutionPlaylistUrls(hls.playlistUrl, text) + expect(resolutionPlaylists).to.have.lengthOf(resolutions.length) + + for (const url of resolutionPlaylists) { + const { text } = await makeRawRequest({ url, query, expectedStatus: HttpStatusCode.OK_200 }) + + const extension = isLive + ? '.ts' + : '.mp4' + + expect(text).to.contain(`${extension}?videoFileToken=${videoFileToken}`) + expect(text).not.to.contain(`reinjectVideoFileToken=true`) + } +} + +function extractResolutionPlaylistUrls (masterPath: string, masterContent: string) { + return masterContent.match(/^([^.]+\.m3u8.*)/mg) + .map(filename => join(dirname(masterPath), filename)) +} + export { checkSegmentHash, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, - completeCheckHlsPlaylist + completeCheckHlsPlaylist, + extractResolutionPlaylistUrls, + checkVideoFileTokenReinjection }