aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/check-params/users.ts44
-rw-r--r--server/tests/api/check-params/video-imports.ts50
-rw-r--r--server/tests/fixtures/60fps_small-240p.torrent1
-rw-r--r--server/tests/utils/videos/video-imports.ts14
4 files changed, 102 insertions, 7 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index e1954c64f..e1655e85b 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -3,7 +3,7 @@
3import { omit } from 'lodash' 3import { omit } from 'lodash'
4import 'mocha' 4import 'mocha'
5import { join } from 'path' 5import { join } from 'path'
6import { UserRole } from '../../../../shared' 6import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
7 7
8import { 8import {
9 createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, 9 createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
@@ -11,6 +11,10 @@ import {
11 updateUser, uploadVideo, userLogin 11 updateUser, uploadVideo, userLogin
12} from '../../utils' 12} from '../../utils'
13import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 13import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
14import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports'
15import { VideoPrivacy } from '../../../../shared/models/videos'
16import { waitJobs } from '../../utils/server/jobs'
17import { expect } from 'chai'
14 18
15describe('Test users API validators', function () { 19describe('Test users API validators', function () {
16 const path = '/api/v1/users/' 20 const path = '/api/v1/users/'
@@ -20,6 +24,7 @@ describe('Test users API validators', function () {
20 let server: ServerInfo 24 let server: ServerInfo
21 let serverWithRegistrationDisabled: ServerInfo 25 let serverWithRegistrationDisabled: ServerInfo
22 let userAccessToken = '' 26 let userAccessToken = ''
27 let channelId: number
23 const user = { 28 const user = {
24 username: 'user1', 29 username: 'user1',
25 password: 'my super password' 30 password: 'my super password'
@@ -41,8 +46,15 @@ describe('Test users API validators', function () {
41 await createUser(server.url, server.accessToken, user.username, user.password, videoQuota) 46 await createUser(server.url, server.accessToken, user.username, user.password, videoQuota)
42 userAccessToken = await userLogin(server, user) 47 userAccessToken = await userLogin(server, user)
43 48
44 const res = await uploadVideo(server.url, server.accessToken, {}) 49 {
45 videoId = res.body.video.id 50 const res = await getMyUserInformation(server.url, server.accessToken)
51 channelId = res.body.videoChannels[ 0 ].id
52 }
53
54 {
55 const res = await uploadVideo(server.url, server.accessToken, {})
56 videoId = res.body.video.id
57 }
46 }) 58 })
47 59
48 describe('When listing users', function () { 60 describe('When listing users', function () {
@@ -605,6 +617,32 @@ describe('Test users API validators', function () {
605 await uploadVideo(server.url, userAccessToken, videoAttributes) 617 await uploadVideo(server.url, userAccessToken, videoAttributes)
606 await uploadVideo(server.url, userAccessToken, videoAttributes, 403) 618 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
607 }) 619 })
620
621 it('Should fail to import with HTTP/Torrent/magnet', async function () {
622 this.timeout(30000)
623
624 const baseAttributes = {
625 channelId: 1,
626 privacy: VideoPrivacy.PUBLIC
627 }
628 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
629 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
630 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: '60fps_small-240p.torrent' }))
631
632 await waitJobs([ server ])
633
634 const res = await getMyVideoImports(server.url, server.accessToken)
635
636 expect(res.body.total).to.equal(3)
637 const videoImports: VideoImport[] = res.body.data
638 expect(videoImports).to.have.lengthOf(3)
639
640 for (const videoImport of videoImports) {
641 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
642 expect(videoImport.error).not.to.be.undefined
643 expect(videoImport.error).to.contain('user video quota is exceeded')
644 }
645 })
608 }) 646 })
609 647
610 describe('When asking a password reset', function () { 648 describe('When asking a password reset', function () {
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 0ead34a47..e62f0918e 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -20,7 +20,7 @@ import {
20 userLogin 20 userLogin
21} from '../../utils' 21} from '../../utils'
22import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 22import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
23import { getYoutubeVideoUrl } from '../../utils/videos/video-imports' 23import { getMagnetURI, getYoutubeVideoUrl } from '../../utils/videos/video-imports'
24 24
25describe('Test video imports API validator', function () { 25describe('Test video imports API validator', function () {
26 const path = '/api/v1/videos/imports' 26 const path = '/api/v1/videos/imports'
@@ -229,6 +229,22 @@ describe('Test video imports API validator', function () {
229 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) 229 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
230 }) 230 })
231 231
232 it('Should fail with an invalid torrent file', async function () {
233 const fields = omit(baseCorrectParams, 'targetUrl')
234 const attaches = {
235 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
236 }
237
238 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
239 })
240
241 it('Should fail with an invalid magnet URI', async function () {
242 let fields = omit(baseCorrectParams, 'targetUrl')
243 fields = immutableAssign(fields, { magnetUri: 'blabla' })
244
245 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
246 })
247
232 it('Should succeed with the correct parameters', async function () { 248 it('Should succeed with the correct parameters', async function () {
233 this.timeout(10000) 249 this.timeout(10000)
234 250
@@ -243,12 +259,15 @@ describe('Test video imports API validator', function () {
243 } 259 }
244 }) 260 })
245 261
246 it('Should forbid to import videos', async function () { 262 it('Should forbid to import http videos', async function () {
247 await updateCustomSubConfig(server.url, server.accessToken, { 263 await updateCustomSubConfig(server.url, server.accessToken, {
248 import: { 264 import: {
249 videos: { 265 videos: {
250 http: { 266 http: {
251 enabled: false 267 enabled: false
268 },
269 torrent: {
270 enabled: true
252 } 271 }
253 } 272 }
254 } 273 }
@@ -262,6 +281,33 @@ describe('Test video imports API validator', function () {
262 statusCodeExpected: 409 281 statusCodeExpected: 409
263 }) 282 })
264 }) 283 })
284
285 it('Should forbid to import torrent videos', async function () {
286 await updateCustomSubConfig(server.url, server.accessToken, {
287 import: {
288 videos: {
289 http: {
290 enabled: true
291 },
292 torrent: {
293 enabled: false
294 }
295 }
296 }
297 })
298
299 let fields = omit(baseCorrectParams, 'targetUrl')
300 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
301
302 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
303
304 fields = omit(fields, 'magnetUri')
305 const attaches = {
306 'torrentfile': join(__dirname, '..', '..', 'fixtures', '60fps_small-240p.torrent')
307 }
308
309 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
310 })
265 }) 311 })
266 312
267 after(async function () { 313 after(async function () {
diff --git a/server/tests/fixtures/60fps_small-240p.torrent b/server/tests/fixtures/60fps_small-240p.torrent
new file mode 100644
index 000000000..ec4c0babe
--- /dev/null
+++ b/server/tests/fixtures/60fps_small-240p.torrent
@@ -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 \ No newline at end of file
diff --git a/server/tests/utils/videos/video-imports.ts b/server/tests/utils/videos/video-imports.ts
index e0f916990..fa2f13b5e 100644
--- a/server/tests/utils/videos/video-imports.ts
+++ b/server/tests/utils/videos/video-imports.ts
@@ -1,17 +1,26 @@
1import { VideoImportCreate } from '../../../../shared/models/videos' 1import { VideoImportCreate } from '../../../../shared/models/videos'
2import { makeGetRequest, makePostBodyRequest } from '..' 2import { makeGetRequest, makePostBodyRequest, makeUploadRequest } from '..'
3 3
4function getYoutubeVideoUrl () { 4function getYoutubeVideoUrl () {
5 return 'https://youtu.be/msX3jv1XdvM' 5 return 'https://youtu.be/msX3jv1XdvM'
6} 6}
7 7
8function getMagnetURI () {
9 // tslint:disable:max-line-length
10 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'
11}
12
8function importVideo (url: string, token: string, attributes: VideoImportCreate) { 13function importVideo (url: string, token: string, attributes: VideoImportCreate) {
9 const path = '/api/v1/videos/imports' 14 const path = '/api/v1/videos/imports'
10 15
11 return makePostBodyRequest({ 16 let attaches: any = {}
17 if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
18
19 return makeUploadRequest({
12 url, 20 url,
13 path, 21 path,
14 token, 22 token,
23 attaches,
15 fields: attributes, 24 fields: attributes,
16 statusCodeExpected: 200 25 statusCodeExpected: 200
17 }) 26 })
@@ -33,5 +42,6 @@ function getMyVideoImports (url: string, token: string) {
33export { 42export {
34 getYoutubeVideoUrl, 43 getYoutubeVideoUrl,
35 importVideo, 44 importVideo,
45 getMagnetURI,
36 getMyVideoImports 46 getMyVideoImports
37} 47}