]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/api/check-params/video-imports.ts
More robust actor image lazy load
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-imports.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { omit } from 'lodash'
5import { join } from 'path'
6import {
7 cleanupTests,
8 createUser,
9 flushAndRunServer,
10 getMyUserInformation,
11 immutableAssign,
12 makeGetRequest,
13 makePostBodyRequest,
14 makeUploadRequest,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateCustomSubConfig,
18 userLogin
19} from '../../../../shared/extra-utils'
20import {
21 checkBadCountPagination,
22 checkBadSortPagination,
23 checkBadStartPagination
24} from '../../../../shared/extra-utils/requests/check-api-params'
25import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
26import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28
29describe('Test video imports API validator', function () {
30 const path = '/api/v1/videos/imports'
31 let server: ServerInfo
32 let userAccessToken = ''
33 let channelId: number
34
35 // ---------------------------------------------------------------
36
37 before(async function () {
38 this.timeout(30000)
39
40 server = await flushAndRunServer(1)
41
42 await setAccessTokensToServers([ server ])
43
44 const username = 'user1'
45 const password = 'my super password'
46 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
47 userAccessToken = await userLogin(server, { username, password })
48
49 {
50 const res = await getMyUserInformation(server.url, server.accessToken)
51 channelId = res.body.videoChannels[0].id
52 }
53 })
54
55 describe('When listing my video imports', function () {
56 const myPath = '/api/v1/users/me/videos/imports'
57
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, myPath, server.accessToken)
60 })
61
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, myPath, server.accessToken)
64 })
65
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, myPath, server.accessToken)
68 })
69
70 it('Should success with the correct parameters', async function () {
71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
72 })
73 })
74
75 describe('When adding a video import', function () {
76 let baseCorrectParams
77
78 before(function () {
79 baseCorrectParams = {
80 targetUrl: getGoodVideoUrl(),
81 name: 'my super name',
82 category: 5,
83 licence: 1,
84 language: 'pt',
85 nsfw: false,
86 commentsEnabled: true,
87 downloadEnabled: true,
88 waitTranscoding: true,
89 description: 'my super description',
90 support: 'my super support text',
91 tags: [ 'tag1', 'tag2' ],
92 privacy: VideoPrivacy.PUBLIC,
93 channelId
94 }
95 })
96
97 it('Should fail with nothing', async function () {
98 const fields = {}
99 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
100 })
101
102 it('Should fail without a target url', async function () {
103 const fields = omit(baseCorrectParams, 'targetUrl')
104 await makePostBodyRequest({
105 url: server.url,
106 path,
107 token: server.accessToken,
108 fields,
109 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
110 })
111 })
112
113 it('Should fail with a bad target url', async function () {
114 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
115
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 })
118
119 it('Should fail with a long name', async function () {
120 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
121
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 })
124
125 it('Should fail with a bad category', async function () {
126 const fields = immutableAssign(baseCorrectParams, { category: 125 })
127
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 })
130
131 it('Should fail with a bad licence', async function () {
132 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
133
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 })
136
137 it('Should fail with a bad language', async function () {
138 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
139
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 })
142
143 it('Should fail with a long description', async function () {
144 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
145
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 })
148
149 it('Should fail with a long support text', async function () {
150 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
151
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
153 })
154
155 it('Should fail without a channel', async function () {
156 const fields = omit(baseCorrectParams, 'channelId')
157
158 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
159 })
160
161 it('Should fail with a bad channel', async function () {
162 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
163
164 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
165 })
166
167 it('Should fail with another user channel', async function () {
168 const user = {
169 username: 'fake',
170 password: 'fake_password'
171 }
172 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
173
174 const accessTokenUser = await userLogin(server, user)
175 const res = await getMyUserInformation(server.url, accessTokenUser)
176 const customChannelId = res.body.videoChannels[0].id
177
178 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
179
180 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
181 })
182
183 it('Should fail with too many tags', async function () {
184 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
185
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 })
188
189 it('Should fail with a tag length too low', async function () {
190 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
191
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 })
194
195 it('Should fail with a tag length too big', async function () {
196 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
197
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 })
200
201 it('Should fail with an incorrect thumbnail file', async function () {
202 const fields = baseCorrectParams
203 const attaches = {
204 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
205 }
206
207 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
208 })
209
210 it('Should fail with a big thumbnail file', async function () {
211 const fields = baseCorrectParams
212 const attaches = {
213 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
214 }
215
216 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
217 })
218
219 it('Should fail with an incorrect preview file', async function () {
220 const fields = baseCorrectParams
221 const attaches = {
222 previewfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
223 }
224
225 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
226 })
227
228 it('Should fail with a big preview file', async function () {
229 const fields = baseCorrectParams
230 const attaches = {
231 previewfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
232 }
233
234 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
235 })
236
237 it('Should fail with an invalid torrent file', async function () {
238 const fields = omit(baseCorrectParams, 'targetUrl')
239 const attaches = {
240 torrentfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
241 }
242
243 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
244 })
245
246 it('Should fail with an invalid magnet URI', async function () {
247 let fields = omit(baseCorrectParams, 'targetUrl')
248 fields = immutableAssign(fields, { magnetUri: 'blabla' })
249
250 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
251 })
252
253 it('Should succeed with the correct parameters', async function () {
254 this.timeout(30000)
255
256 await makePostBodyRequest({
257 url: server.url,
258 path,
259 token: server.accessToken,
260 fields: baseCorrectParams,
261 statusCodeExpected: HttpStatusCode.OK_200
262 })
263 })
264
265 it('Should forbid to import http videos', async function () {
266 await updateCustomSubConfig(server.url, server.accessToken, {
267 import: {
268 videos: {
269 http: {
270 enabled: false
271 },
272 torrent: {
273 enabled: true
274 }
275 }
276 }
277 })
278
279 await makePostBodyRequest({
280 url: server.url,
281 path,
282 token: server.accessToken,
283 fields: baseCorrectParams,
284 statusCodeExpected: HttpStatusCode.CONFLICT_409
285 })
286 })
287
288 it('Should forbid to import torrent videos', async function () {
289 await updateCustomSubConfig(server.url, server.accessToken, {
290 import: {
291 videos: {
292 http: {
293 enabled: true
294 },
295 torrent: {
296 enabled: false
297 }
298 }
299 }
300 })
301
302 let fields = omit(baseCorrectParams, 'targetUrl')
303 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
304
305 await makePostBodyRequest({
306 url: server.url,
307 path,
308 token: server.accessToken,
309 fields,
310 statusCodeExpected: HttpStatusCode.CONFLICT_409
311 })
312
313 fields = omit(fields, 'magnetUri')
314 const attaches = {
315 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
316 }
317
318 await makeUploadRequest({
319 url: server.url,
320 path,
321 token: server.accessToken,
322 fields,
323 attaches,
324 statusCodeExpected: HttpStatusCode.CONFLICT_409
325 })
326 })
327 })
328
329 after(async function () {
330 await cleanupTests([ server ])
331 })
332})