aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/users.ts44
-rw-r--r--server/tests/api/check-params/video-imports.ts50
2 files changed, 89 insertions, 5 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 () {