2022-06-21 08:31:25 -05:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2023-07-19 09:02:49 -05:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createSingleServer,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
setDefaultVideoChannel,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/server-commands'
|
2022-06-21 08:31:25 -05:00
|
|
|
|
|
|
|
describe('Test video sources API validator', function () {
|
|
|
|
let server: PeerTubeServer = null
|
|
|
|
let uuid: string
|
|
|
|
let userToken: string
|
|
|
|
|
|
|
|
before(async function () {
|
2023-07-19 09:02:49 -05:00
|
|
|
this.timeout(120000)
|
2022-06-21 08:31:25 -05:00
|
|
|
|
|
|
|
server = await createSingleServer(1)
|
|
|
|
await setAccessTokensToServers([ server ])
|
2023-07-19 09:02:49 -05:00
|
|
|
await setDefaultVideoChannel([ server ])
|
2022-06-21 08:31:25 -05:00
|
|
|
|
2023-07-19 09:02:49 -05:00
|
|
|
userToken = await server.users.generateUserAndToken('user1')
|
2022-06-21 08:31:25 -05:00
|
|
|
})
|
|
|
|
|
2023-07-19 09:02:49 -05:00
|
|
|
describe('When getting latest source', function () {
|
2022-06-21 08:31:25 -05:00
|
|
|
|
2023-07-19 09:02:49 -05:00
|
|
|
before(async function () {
|
|
|
|
const created = await server.videos.quickUpload({ name: 'video' })
|
|
|
|
uuid = created.uuid
|
|
|
|
})
|
2022-06-21 08:31:25 -05:00
|
|
|
|
2023-07-19 09:02:49 -05:00
|
|
|
it('Should fail without a valid uuid', async function () {
|
|
|
|
await server.videos.getSource({ id: '4da6fde3-88f7-4d16-b119-108df563d0b0', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should receive 404 when passing a non existing video id', async function () {
|
|
|
|
await server.videos.getSource({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not get the source as unauthenticated', async function () {
|
|
|
|
await server.videos.getSource({ id: uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401, token: null })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not get the source with another user', async function () {
|
|
|
|
await server.videos.getSource({ id: uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403, token: userToken })
|
|
|
|
})
|
2022-06-21 08:31:25 -05:00
|
|
|
|
2023-07-19 09:02:49 -05:00
|
|
|
it('Should succeed with the correct parameters get the source as another user', async function () {
|
|
|
|
await server.videos.getSource({ id: uuid })
|
|
|
|
})
|
2022-06-21 08:31:25 -05:00
|
|
|
})
|
|
|
|
|
2023-07-19 09:02:49 -05:00
|
|
|
describe('When updating source video file', function () {
|
|
|
|
let userAccessToken: string
|
|
|
|
let userId: number
|
|
|
|
|
|
|
|
let videoId: string
|
|
|
|
let userVideoId: string
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
const res = await server.users.generate('user2')
|
|
|
|
userAccessToken = res.token
|
|
|
|
userId = res.userId
|
|
|
|
|
|
|
|
const { uuid } = await server.videos.quickUpload({ name: 'video' })
|
|
|
|
videoId = uuid
|
|
|
|
|
|
|
|
await waitJobs([ server ])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if not enabled on the instance', async function () {
|
|
|
|
await server.config.disableFileUpdate()
|
|
|
|
|
|
|
|
await server.videos.replaceSourceFile({ videoId, fixture: 'video_short.mp4', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail on an unknown video', async function () {
|
|
|
|
await server.config.enableFileUpdate()
|
|
|
|
|
|
|
|
await server.videos.replaceSourceFile({ videoId: 404, fixture: 'video_short.mp4', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an invalid video', async function () {
|
|
|
|
await server.config.enableLive({ allowReplay: false })
|
|
|
|
|
|
|
|
const { video } = await server.live.quickCreate({ saveReplay: false, permanentLive: true })
|
|
|
|
await server.videos.replaceSourceFile({
|
|
|
|
videoId: video.uuid,
|
|
|
|
fixture: 'video_short.mp4',
|
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail without token', async function () {
|
|
|
|
await server.videos.replaceSourceFile({
|
|
|
|
token: null,
|
|
|
|
videoId,
|
|
|
|
fixture: 'video_short.mp4',
|
|
|
|
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with another user', async function () {
|
|
|
|
await server.videos.replaceSourceFile({
|
|
|
|
token: userAccessToken,
|
|
|
|
videoId,
|
|
|
|
fixture: 'video_short.mp4',
|
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect input file', async function () {
|
|
|
|
await server.videos.replaceSourceFile({
|
|
|
|
fixture: 'video_short_fake.webm',
|
|
|
|
videoId,
|
2023-07-25 08:18:10 -05:00
|
|
|
completedExpectedStatus: HttpStatusCode.UNPROCESSABLE_ENTITY_422
|
2023-07-19 09:02:49 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
await server.videos.replaceSourceFile({
|
|
|
|
fixture: 'video_short.mkv',
|
|
|
|
videoId,
|
|
|
|
expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if quota is exceeded', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
const { uuid } = await server.videos.quickUpload({ name: 'user video' })
|
|
|
|
userVideoId = uuid
|
|
|
|
await waitJobs([ server ])
|
|
|
|
|
|
|
|
await server.users.update({ userId, videoQuota: 1 })
|
|
|
|
await server.videos.replaceSourceFile({
|
|
|
|
token: userAccessToken,
|
|
|
|
videoId: uuid,
|
|
|
|
fixture: 'video_short.mp4',
|
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct params', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
await server.users.update({ userId, videoQuota: 1000 * 1000 * 1000 })
|
|
|
|
await server.videos.replaceSourceFile({ videoId: userVideoId, fixture: 'video_short.mp4' })
|
|
|
|
})
|
2022-06-21 08:31:25 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|