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,
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/'
let server: ServerInfo
let serverWithRegistrationDisabled: ServerInfo
let userAccessToken = ''
+ let channelId: number
const user = {
username: 'user1',
password: 'my super password'
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 () {
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 () {
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'
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)
}
})
- 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
}
}
}
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 () {
--- /dev/null
+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:Ä\96\85+çéCFm7çc0\17ÏÅT-\15@2Ç6©0\bá\12Mür|R\19v\9b$\98h%e8:url-listl84:https://peertube2.cpy.re/static/webseed/2b8dbe74-9548-4f6f-a8da-986aed9e5e45-240.mp4ee
\ No newline at end of file
import { VideoImportCreate } from '../../../../shared/models/videos'
-import { makeGetRequest, makePostBodyRequest } from '..'
+import { makeGetRequest, makePostBodyRequest, makeUploadRequest } from '..'
function getYoutubeVideoUrl () {
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) {
const path = '/api/v1/videos/imports'
- return makePostBodyRequest({
+ let attaches: any = {}
+ if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
+
+ return makeUploadRequest({
url,
path,
token,
+ attaches,
fields: attributes,
statusCodeExpected: 200
})
export {
getYoutubeVideoUrl,
importVideo,
+ getMagnetURI,
getMyVideoImports
}