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