X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fextra-utils%2Fvideos%2Fvideo-streaming-playlists.ts;h=99c2e1880d2e1a1ec47ba778a20a1aa889ab19bd;hb=bbb3be686ad960c5b1f34a7771dec09eb1783455;hp=8cf0e4930e9fecd0441dcd65f6996d3fc536a101;hpb=bd54ad1953ee0484ba90cf5f588f4c282048f368;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/extra-utils/videos/video-streaming-playlists.ts b/shared/extra-utils/videos/video-streaming-playlists.ts index 8cf0e4930..99c2e1880 100644 --- a/shared/extra-utils/videos/video-streaming-playlists.ts +++ b/shared/extra-utils/videos/video-streaming-playlists.ts @@ -2,16 +2,17 @@ import { makeRawRequest } from '../requests/requests' import { sha256 } from '../../../server/helpers/core-utils' import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' import { expect } from 'chai' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -function getPlaylist (url: string, statusCodeExpected = 200) { +function getPlaylist (url: string, statusCodeExpected = HttpStatusCode.OK_200) { return makeRawRequest(url, statusCodeExpected) } -function getSegment (url: string, statusCodeExpected = 200, range?: string) { +function getSegment (url: string, statusCodeExpected = HttpStatusCode.OK_200, range?: string) { return makeRawRequest(url, statusCodeExpected, range) } -function getSegmentSha256 (url: string, statusCodeExpected = 200) { +function getSegmentSha256 (url: string, statusCodeExpected = HttpStatusCode.OK_200) { return makeRawRequest(url, statusCodeExpected) } @@ -33,7 +34,7 @@ async function checkSegmentHash ( const offset = parseInt(matches[2], 10) const range = `${offset}-${offset + length - 1}` - const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`) + const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, HttpStatusCode.PARTIAL_CONTENT_206, `bytes=${range}`) const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) @@ -41,6 +42,20 @@ async function checkSegmentHash ( expect(sha256(res2.body)).to.equal(sha256Server) } +async function checkLiveSegmentHash ( + baseUrlSegment: string, + videoUUID: string, + segmentName: string, + hlsPlaylist: VideoStreamingPlaylist +) { + const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${segmentName}`) + + const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) + + const sha256Server = resSha.body[segmentName] + expect(sha256(res2.body)).to.equal(sha256Server) +} + async function checkResolutionsInMasterPlaylist (playlistUrl: string, resolutions: number[]) { const res = await getPlaylist(playlistUrl) @@ -62,5 +77,6 @@ export { getSegment, checkResolutionsInMasterPlaylist, getSegmentSha256, + checkLiveSegmentHash, checkSegmentHash }