Add check param tests regarding video imports

pull/918/head
Chocobozzz 2018-08-07 11:56:18 +02:00
parent a84b8fa5cf
commit 187501f8b8
4 changed files with 102 additions and 7 deletions

View File

@ -3,7 +3,7 @@
import { omit } from 'lodash' import { omit } from 'lodash'
import 'mocha' import 'mocha'
import { join } from 'path' import { join } from 'path'
import { UserRole } from '../../../../shared' import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
import { import {
createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
@ -11,6 +11,10 @@ import {
updateUser, uploadVideo, userLogin updateUser, uploadVideo, userLogin
} from '../../utils' } from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 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 () { describe('Test users API validators', function () {
const path = '/api/v1/users/' const path = '/api/v1/users/'
@ -20,6 +24,7 @@ describe('Test users API validators', function () {
let server: ServerInfo let server: ServerInfo
let serverWithRegistrationDisabled: ServerInfo let serverWithRegistrationDisabled: ServerInfo
let userAccessToken = '' let userAccessToken = ''
let channelId: number
const user = { const user = {
username: 'user1', username: 'user1',
password: 'my super password' 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) await createUser(server.url, server.accessToken, user.username, user.password, videoQuota)
userAccessToken = await userLogin(server, user) 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 () { 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)
await uploadVideo(server.url, userAccessToken, videoAttributes, 403) 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 () { describe('When asking a password reset', function () {

View File

@ -20,7 +20,7 @@ import {
userLogin userLogin
} from '../../utils' } from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 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 () { describe('Test video imports API validator', function () {
const path = '/api/v1/videos/imports' 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 }) 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 () { it('Should succeed with the correct parameters', async function () {
this.timeout(10000) 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, { await updateCustomSubConfig(server.url, server.accessToken, {
import: { import: {
videos: { videos: {
http: { http: {
enabled: false enabled: false
},
torrent: {
enabled: true
} }
} }
} }
@ -262,6 +281,33 @@ describe('Test video imports API validator', function () {
statusCodeExpected: 409 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 () { after(async function () {

View File

@ -0,0 +1 @@
d8:announce41:wss://peertube2.cpy.re:443/tracker/socket13:announce-listll41:wss://peertube2.cpy.re:443/tracker/socketel41:https://peertube2.cpy.re/tracker/announceee10:created by8:PeerTube13:creation datei1529593069e8:encoding5:UTF-84:infod6:lengthi30921e4:name20:60fps_small 240p.mp412:piece lengthi16384e6:pieces40:Ä–…+çéCFm7çc0ÏÅT-@2Ç6©0áMür|Rv$˜h%e8:url-listl84:https://peertube2.cpy.re/static/webseed/2b8dbe74-9548-4f6f-a8da-986aed9e5e45-240.mp4ee

View File

@ -1,17 +1,26 @@
import { VideoImportCreate } from '../../../../shared/models/videos' import { VideoImportCreate } from '../../../../shared/models/videos'
import { makeGetRequest, makePostBodyRequest } from '..' import { makeGetRequest, makePostBodyRequest, makeUploadRequest } from '..'
function getYoutubeVideoUrl () { function getYoutubeVideoUrl () {
return 'https://youtu.be/msX3jv1XdvM' return 'https://youtu.be/msX3jv1XdvM'
} }
function getMagnetURI () {
// tslint:disable:max-line-length
return 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2F2b8dbe74-9548-4f6f-a8da-986aed9e5e45-240.torrent&xt=urn:btih:52bf3729e5859390a8751495196b5674a55c99f3&dn=60fps_small&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2F2b8dbe74-9548-4f6f-a8da-986aed9e5e45-240.mp4'
}
function importVideo (url: string, token: string, attributes: VideoImportCreate) { function importVideo (url: string, token: string, attributes: VideoImportCreate) {
const path = '/api/v1/videos/imports' const path = '/api/v1/videos/imports'
return makePostBodyRequest({ let attaches: any = {}
if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
return makeUploadRequest({
url, url,
path, path,
token, token,
attaches,
fields: attributes, fields: attributes,
statusCodeExpected: 200 statusCodeExpected: 200
}) })
@ -33,5 +42,6 @@ function getMyVideoImports (url: string, token: string) {
export { export {
getYoutubeVideoUrl, getYoutubeVideoUrl,
importVideo, importVideo,
getMagnetURI,
getMyVideoImports getMyVideoImports
} }