2021-11-17 09:04:53 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
import { getAllFiles } from '@shared/core-utils'
|
|
|
|
import { HttpStatusCode, UserRole, VideoDetails, VideoPrivacy } from '@shared/models'
|
2021-12-17 04:58:15 -06:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
2022-10-12 09:09:02 -05:00
|
|
|
makeRawRequest,
|
2021-12-17 04:58:15 -06:00
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/server-commands'
|
2021-11-17 09:04:53 -06:00
|
|
|
|
|
|
|
describe('Test videos files', function () {
|
|
|
|
let servers: PeerTubeServer[]
|
2021-11-18 07:35:08 -06:00
|
|
|
|
2021-11-17 09:04:53 -06:00
|
|
|
let userToken: string
|
|
|
|
let moderatorToken: string
|
2021-11-18 07:35:08 -06:00
|
|
|
|
2021-11-17 09:04:53 -06:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
2021-11-19 01:25:07 -06:00
|
|
|
this.timeout(300_000)
|
2021-11-17 09:04:53 -06:00
|
|
|
|
|
|
|
servers = await createMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
2021-11-18 07:35:08 -06:00
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
2021-11-17 09:04:53 -06:00
|
|
|
userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
|
|
|
|
moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
describe('Getting metadata', function () {
|
|
|
|
let video: VideoDetails
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'video', privacy: VideoPrivacy.PRIVATE })
|
|
|
|
video = await servers[0].videos.getWithToken({ id: uuid })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not get metadata of private video without token', async function () {
|
|
|
|
for (const file of getAllFiles(video)) {
|
|
|
|
await makeRawRequest({ url: file.metadataUrl, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not get metadata of private video without the appropriate token', async function () {
|
|
|
|
for (const file of getAllFiles(video)) {
|
|
|
|
await makeRawRequest({ url: file.metadataUrl, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get metadata of private video with the appropriate token', async function () {
|
|
|
|
for (const file of getAllFiles(video)) {
|
|
|
|
await makeRawRequest({ url: file.metadataUrl, token: servers[0].accessToken, expectedStatus: HttpStatusCode.OK_200 })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Deleting files', function () {
|
2023-07-11 02:21:13 -05:00
|
|
|
let webVideoId: string
|
2022-10-12 09:09:02 -05:00
|
|
|
let hlsId: string
|
|
|
|
let remoteId: string
|
|
|
|
|
|
|
|
let validId1: string
|
|
|
|
let validId2: string
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
let hlsFileId: number
|
2023-07-11 02:21:13 -05:00
|
|
|
let webVideoFileId: number
|
2021-11-18 07:35:08 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
let remoteHLSFileId: number
|
2023-07-11 02:21:13 -05:00
|
|
|
let remoteWebVideoFileId: number
|
2022-10-12 09:09:02 -05:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(300_000)
|
2021-11-17 09:04:53 -06:00
|
|
|
|
|
|
|
{
|
2022-10-12 09:09:02 -05:00
|
|
|
const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
|
2022-07-29 07:50:41 -05:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
const video = await servers[1].videos.get({ id: uuid })
|
|
|
|
remoteId = video.uuid
|
|
|
|
remoteHLSFileId = video.streamingPlaylists[0].files[0].id
|
2023-07-11 02:21:13 -05:00
|
|
|
remoteWebVideoFileId = video.files[0].id
|
2021-11-17 09:04:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].config.enableTranscoding(true, true)
|
|
|
|
|
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
const video = await servers[0].videos.get({ id: uuid })
|
|
|
|
validId1 = video.uuid
|
|
|
|
hlsFileId = video.streamingPlaylists[0].files[0].id
|
2023-07-11 02:21:13 -05:00
|
|
|
webVideoFileId = video.files[0].id
|
2022-10-12 09:09:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'both 2' })
|
|
|
|
validId2 = uuid
|
|
|
|
}
|
2021-11-17 09:04:53 -06:00
|
|
|
}
|
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await waitJobs(servers)
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
{
|
|
|
|
await servers[0].config.enableTranscoding(false, true)
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'hls' })
|
|
|
|
hlsId = uuid
|
|
|
|
}
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await waitJobs(servers)
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
{
|
|
|
|
await servers[0].config.enableTranscoding(false, true)
|
2023-07-11 02:21:13 -05:00
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'web-video' })
|
|
|
|
webVideoId = uuid
|
2022-10-12 09:09:02 -05:00
|
|
|
}
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should not delete files of a unknown video', async function () {
|
|
|
|
const expectedStatus = HttpStatusCode.NOT_FOUND_404
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: 404, expectedStatus })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeAllWebVideoFiles({ videoId: 404, expectedStatus })
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSFile({ videoId: 404, fileId: hlsFileId, expectedStatus })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeWebVideoFile({ videoId: 404, fileId: webVideoFileId, expectedStatus })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should not delete unknown files', async function () {
|
|
|
|
const expectedStatus = HttpStatusCode.NOT_FOUND_404
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: webVideoFileId, expectedStatus })
|
|
|
|
await servers[0].videos.removeWebVideoFile({ videoId: validId1, fileId: hlsFileId, expectedStatus })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2021-11-18 07:35:08 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should not delete files of a remote video', async function () {
|
|
|
|
const expectedStatus = HttpStatusCode.BAD_REQUEST_400
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: remoteId, expectedStatus })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeAllWebVideoFiles({ videoId: remoteId, expectedStatus })
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSFile({ videoId: remoteId, fileId: remoteHLSFileId, expectedStatus })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeWebVideoFile({ videoId: remoteId, fileId: remoteWebVideoFileId, expectedStatus })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should not delete files by a non admin user', async function () {
|
|
|
|
const expectedStatus = HttpStatusCode.FORBIDDEN_403
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: validId1, token: userToken, expectedStatus })
|
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: validId1, token: moderatorToken, expectedStatus })
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeAllWebVideoFiles({ videoId: validId1, token: userToken, expectedStatus })
|
|
|
|
await servers[0].videos.removeAllWebVideoFiles({ videoId: validId1, token: moderatorToken, expectedStatus })
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId, token: userToken, expectedStatus })
|
|
|
|
await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId, token: moderatorToken, expectedStatus })
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeWebVideoFile({ videoId: validId1, fileId: webVideoFileId, token: userToken, expectedStatus })
|
|
|
|
await servers[0].videos.removeWebVideoFile({ videoId: validId1, fileId: webVideoFileId, token: moderatorToken, expectedStatus })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should not delete files if the files are not available', async function () {
|
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeAllWebVideoFiles({ videoId: webVideoId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeWebVideoFile({ videoId: webVideoId, fileId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should not delete files if no both versions are available', async function () {
|
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeAllWebVideoFiles({ videoId: webVideoId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2021-11-17 09:04:53 -06:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should delete files if both versions are available', async function () {
|
|
|
|
await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeWebVideoFile({ videoId: validId1, fileId: webVideoFileId })
|
2022-07-29 07:50:41 -05:00
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: validId1 })
|
2023-07-11 02:21:13 -05:00
|
|
|
await servers[0].videos.removeAllWebVideoFiles({ videoId: validId2 })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
2021-11-17 09:04:53 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|