2021-11-17 10:04:53 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { HttpStatusCode, UserRole } from '@shared/models'
|
2021-12-17 05:58:15 -05:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/server-commands'
|
2021-11-17 10:04:53 -05:00
|
|
|
|
|
|
|
describe('Test videos files', function () {
|
|
|
|
let servers: PeerTubeServer[]
|
2021-11-18 08:35:08 -05:00
|
|
|
|
2021-11-17 10:04:53 -05:00
|
|
|
let webtorrentId: string
|
|
|
|
let hlsId: string
|
|
|
|
let remoteId: string
|
2021-11-18 08:35:08 -05:00
|
|
|
|
2021-11-17 10:04:53 -05:00
|
|
|
let userToken: string
|
|
|
|
let moderatorToken: string
|
2021-11-18 08:35:08 -05:00
|
|
|
|
2021-11-17 10:04:53 -05:00
|
|
|
let validId1: string
|
|
|
|
let validId2: string
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
2021-11-19 02:25:07 -05:00
|
|
|
this.timeout(300_000)
|
2021-11-17 10:04:53 -05:00
|
|
|
|
|
|
|
servers = await createMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
2021-11-18 08:35:08 -05:00
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
2021-11-17 10:04:53 -05:00
|
|
|
userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
|
|
|
|
moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
|
|
|
|
|
2021-11-18 08:35:08 -05:00
|
|
|
{
|
|
|
|
const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
|
|
|
|
remoteId = uuid
|
|
|
|
}
|
|
|
|
|
2021-11-17 10:04:53 -05:00
|
|
|
{
|
|
|
|
await servers[0].config.enableTranscoding(true, true)
|
|
|
|
|
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
|
|
|
|
validId1 = uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'both 2' })
|
|
|
|
validId2 = uuid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
{
|
|
|
|
await servers[0].config.enableTranscoding(false, true)
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'hls' })
|
|
|
|
hlsId = uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
{
|
|
|
|
await servers[0].config.enableTranscoding(false, true)
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'webtorrent' })
|
|
|
|
webtorrentId = uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
2021-11-18 08:35:08 -05:00
|
|
|
it('Should not delete files of a unknown video', async function () {
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
|
|
|
})
|
|
|
|
|
2021-11-17 10:04:53 -05:00
|
|
|
it('Should not delete files of a remote video', async function () {
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not delete files by a non admin user', async function () {
|
|
|
|
const expectedStatus = HttpStatusCode.FORBIDDEN_403
|
|
|
|
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: validId1, token: userToken, expectedStatus })
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: validId1, token: moderatorToken, expectedStatus })
|
|
|
|
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: userToken, expectedStatus })
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: moderatorToken, expectedStatus })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not delete files if the files are not available', async function () {
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not delete files if no both versions are available', async function () {
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not delete files if no both versions are available', async function () {
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should delete files if both versions are available', async function () {
|
|
|
|
await servers[0].videos.removeHLSFiles({ videoId: validId1 })
|
|
|
|
await servers[0].videos.removeWebTorrentFiles({ videoId: validId2 })
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|