1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, FIXTURE_URLS } from '@server/tests/shared'
6 import { buildAbsoluteFixturePath } from '@shared/core-utils'
7 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
15 setAccessTokensToServers
16 } from '@shared/server-commands'
18 describe('Test video imports API validator', function () {
19 const path = '/api/v1/videos/imports'
20 let server: PeerTubeServer
21 let userAccessToken = ''
24 // ---------------------------------------------------------------
26 before(async function () {
29 server = await createSingleServer(1)
31 await setAccessTokensToServers([ server ])
33 const username = 'user1'
34 const password = 'my super password'
35 await server.users.create({ username: username, password: password })
36 userAccessToken = await server.login.getAccessToken({ username, password })
39 const { videoChannels } = await server.users.getMyInfo()
40 channelId = videoChannels[0].id
44 describe('When listing my video imports', function () {
45 const myPath = '/api/v1/users/me/videos/imports'
47 it('Should fail with a bad start pagination', async function () {
48 await checkBadStartPagination(server.url, myPath, server.accessToken)
51 it('Should fail with a bad count pagination', async function () {
52 await checkBadCountPagination(server.url, myPath, server.accessToken)
55 it('Should fail with an incorrect sort', async function () {
56 await checkBadSortPagination(server.url, myPath, server.accessToken)
59 it('Should success with the correct parameters', async function () {
60 await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken })
64 describe('When adding a video import', function () {
69 targetUrl: FIXTURE_URLS.goodVideo,
70 name: 'my super name',
75 commentsEnabled: true,
76 downloadEnabled: true,
77 waitTranscoding: true,
78 description: 'my super description',
79 support: 'my super support text',
80 tags: [ 'tag1', 'tag2' ],
81 privacy: VideoPrivacy.PUBLIC,
86 it('Should fail with nothing', async function () {
88 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
91 it('Should fail without a target url', async function () {
92 const fields = omit(baseCorrectParams, 'targetUrl')
93 await makePostBodyRequest({
96 token: server.accessToken,
98 expectedStatus: HttpStatusCode.BAD_REQUEST_400
102 it('Should fail with a bad target url', async function () {
103 const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' }
105 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
108 it('Should fail with localhost', async function () {
109 const fields = { ...baseCorrectParams, targetUrl: 'http://localhost:8000' }
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 it('Should fail with a private IP target urls', async function () {
116 'http://127.0.0.1:8000',
118 'http://127.0.0.1/hello',
119 'https://192.168.1.42',
120 'http://192.168.1.42'
123 for (const targetUrl of targetUrls) {
124 const fields = { ...baseCorrectParams, targetUrl }
126 await makePostBodyRequest({
129 token: server.accessToken,
131 expectedStatus: HttpStatusCode.FORBIDDEN_403
136 it('Should fail with a long name', async function () {
137 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
139 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
142 it('Should fail with a bad category', async function () {
143 const fields = { ...baseCorrectParams, category: 125 }
145 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
148 it('Should fail with a bad licence', async function () {
149 const fields = { ...baseCorrectParams, licence: 125 }
151 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
154 it('Should fail with a bad language', async function () {
155 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
157 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
160 it('Should fail with a long description', async function () {
161 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
163 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
166 it('Should fail with a long support text', async function () {
167 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
169 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
172 it('Should fail without a channel', async function () {
173 const fields = omit(baseCorrectParams, 'channelId')
175 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
178 it('Should fail with a bad channel', async function () {
179 const fields = { ...baseCorrectParams, channelId: 545454 }
181 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
184 it('Should fail with another user channel', async function () {
187 password: 'fake_password'
189 await server.users.create({ username: user.username, password: user.password })
191 const accessTokenUser = await server.login.getAccessToken(user)
192 const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser })
193 const customChannelId = videoChannels[0].id
195 const fields = { ...baseCorrectParams, channelId: customChannelId }
197 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
200 it('Should fail with too many tags', async function () {
201 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
203 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
206 it('Should fail with a tag length too low', async function () {
207 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
209 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
212 it('Should fail with a tag length too big', async function () {
213 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
215 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
218 it('Should fail with an incorrect thumbnail file', async function () {
219 const fields = baseCorrectParams
221 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
224 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
227 it('Should fail with a big thumbnail file', async function () {
228 const fields = baseCorrectParams
230 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
233 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
236 it('Should fail with an incorrect preview file', async function () {
237 const fields = baseCorrectParams
239 previewfile: buildAbsoluteFixturePath('video_short.mp4')
242 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
245 it('Should fail with a big preview file', async function () {
246 const fields = baseCorrectParams
248 previewfile: buildAbsoluteFixturePath('preview-big.png')
251 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
254 it('Should fail with an invalid torrent file', async function () {
255 const fields = omit(baseCorrectParams, 'targetUrl')
257 torrentfile: buildAbsoluteFixturePath('avatar-big.png')
260 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
263 it('Should fail with an invalid magnet URI', async function () {
264 let fields = omit(baseCorrectParams, 'targetUrl')
265 fields = { ...fields, magnetUri: 'blabla' }
267 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
270 it('Should succeed with the correct parameters', async function () {
273 await makePostBodyRequest({
276 token: server.accessToken,
277 fields: baseCorrectParams,
278 expectedStatus: HttpStatusCode.OK_200
282 it('Should forbid to import http videos', async function () {
283 await server.config.updateCustomSubConfig({
298 await makePostBodyRequest({
301 token: server.accessToken,
302 fields: baseCorrectParams,
303 expectedStatus: HttpStatusCode.CONFLICT_409
307 it('Should forbid to import torrent videos', async function () {
308 await server.config.updateCustomSubConfig({
323 let fields = omit(baseCorrectParams, 'targetUrl')
324 fields = { ...fields, magnetUri: FIXTURE_URLS.magnet }
326 await makePostBodyRequest({
329 token: server.accessToken,
331 expectedStatus: HttpStatusCode.CONFLICT_409
334 fields = omit(fields, 'magnetUri')
336 torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
339 await makeUploadRequest({
342 token: server.accessToken,
345 expectedStatus: HttpStatusCode.CONFLICT_409
350 after(async function () {
351 await cleanupTests([ server ])