mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add check param tests regarding video imports
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { omit } from 'lodash'
|
||||
import 'mocha'
|
||||
import { join } from 'path'
|
||||
import { UserRole } from '../../../../shared'
|
||||
import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
|
||||
|
||||
import {
|
||||
createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
|
||||
@@ -11,6 +11,10 @@ import {
|
||||
updateUser, uploadVideo, userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports'
|
||||
import { VideoPrivacy } from '../../../../shared/models/videos'
|
||||
import { waitJobs } from '../../utils/server/jobs'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Test users API validators', function () {
|
||||
const path = '/api/v1/users/'
|
||||
@@ -20,6 +24,7 @@ describe('Test users API validators', function () {
|
||||
let server: ServerInfo
|
||||
let serverWithRegistrationDisabled: ServerInfo
|
||||
let userAccessToken = ''
|
||||
let channelId: number
|
||||
const user = {
|
||||
username: 'user1',
|
||||
password: 'my super password'
|
||||
@@ -41,8 +46,15 @@ describe('Test users API validators', function () {
|
||||
await createUser(server.url, server.accessToken, user.username, user.password, videoQuota)
|
||||
userAccessToken = await userLogin(server, user)
|
||||
|
||||
const res = await uploadVideo(server.url, server.accessToken, {})
|
||||
videoId = res.body.video.id
|
||||
{
|
||||
const res = await getMyUserInformation(server.url, server.accessToken)
|
||||
channelId = res.body.videoChannels[ 0 ].id
|
||||
}
|
||||
|
||||
{
|
||||
const res = await uploadVideo(server.url, server.accessToken, {})
|
||||
videoId = res.body.video.id
|
||||
}
|
||||
})
|
||||
|
||||
describe('When listing users', function () {
|
||||
@@ -605,6 +617,32 @@ describe('Test users API validators', function () {
|
||||
await uploadVideo(server.url, userAccessToken, videoAttributes)
|
||||
await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
|
||||
})
|
||||
|
||||
it('Should fail to import with HTTP/Torrent/magnet', async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
const baseAttributes = {
|
||||
channelId: 1,
|
||||
privacy: VideoPrivacy.PUBLIC
|
||||
}
|
||||
await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
|
||||
await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
|
||||
await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: '60fps_small-240p.torrent' }))
|
||||
|
||||
await waitJobs([ server ])
|
||||
|
||||
const res = await getMyVideoImports(server.url, server.accessToken)
|
||||
|
||||
expect(res.body.total).to.equal(3)
|
||||
const videoImports: VideoImport[] = res.body.data
|
||||
expect(videoImports).to.have.lengthOf(3)
|
||||
|
||||
for (const videoImport of videoImports) {
|
||||
expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
|
||||
expect(videoImport.error).not.to.be.undefined
|
||||
expect(videoImport.error).to.contain('user video quota is exceeded')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('When asking a password reset', function () {
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
userLogin
|
||||
} from '../../utils'
|
||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
|
||||
import { getYoutubeVideoUrl } from '../../utils/videos/video-imports'
|
||||
import { getMagnetURI, getYoutubeVideoUrl } from '../../utils/videos/video-imports'
|
||||
|
||||
describe('Test video imports API validator', function () {
|
||||
const path = '/api/v1/videos/imports'
|
||||
@@ -229,6 +229,22 @@ describe('Test video imports API validator', function () {
|
||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||
})
|
||||
|
||||
it('Should fail with an invalid torrent file', async function () {
|
||||
const fields = omit(baseCorrectParams, 'targetUrl')
|
||||
const attaches = {
|
||||
'torrentfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
|
||||
}
|
||||
|
||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
|
||||
})
|
||||
|
||||
it('Should fail with an invalid magnet URI', async function () {
|
||||
let fields = omit(baseCorrectParams, 'targetUrl')
|
||||
fields = immutableAssign(fields, { magnetUri: 'blabla' })
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||
})
|
||||
|
||||
it('Should succeed with the correct parameters', async function () {
|
||||
this.timeout(10000)
|
||||
|
||||
@@ -243,12 +259,15 @@ describe('Test video imports API validator', function () {
|
||||
}
|
||||
})
|
||||
|
||||
it('Should forbid to import videos', async function () {
|
||||
it('Should forbid to import http videos', async function () {
|
||||
await updateCustomSubConfig(server.url, server.accessToken, {
|
||||
import: {
|
||||
videos: {
|
||||
http: {
|
||||
enabled: false
|
||||
},
|
||||
torrent: {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,6 +281,33 @@ describe('Test video imports API validator', function () {
|
||||
statusCodeExpected: 409
|
||||
})
|
||||
})
|
||||
|
||||
it('Should forbid to import torrent videos', async function () {
|
||||
await updateCustomSubConfig(server.url, server.accessToken, {
|
||||
import: {
|
||||
videos: {
|
||||
http: {
|
||||
enabled: true
|
||||
},
|
||||
torrent: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let fields = omit(baseCorrectParams, 'targetUrl')
|
||||
fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
|
||||
|
||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
|
||||
|
||||
fields = omit(fields, 'magnetUri')
|
||||
const attaches = {
|
||||
'torrentfile': join(__dirname, '..', '..', 'fixtures', '60fps_small-240p.torrent')
|
||||
}
|
||||
|
||||
await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
|
||||
Reference in New Issue
Block a user