]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
5d08a6a7 | 2 | |
5d08a6a7 | 3 | import 'mocha' |
b488ba1e | 4 | import { omit } from 'lodash' |
c55e3d72 C |
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' | |
5d08a6a7 | 8 | import { |
7c3b7976 | 9 | cleanupTests, |
254d3579 | 10 | createSingleServer, |
5d08a6a7 C |
11 | makeGetRequest, |
12 | makePostBodyRequest, | |
13 | makeUploadRequest, | |
254d3579 | 14 | PeerTubeServer, |
41d1d075 | 15 | setAccessTokensToServers |
bf54587a | 16 | } from '@shared/server-commands' |
5d08a6a7 C |
17 | |
18 | describe('Test video imports API validator', function () { | |
19 | const path = '/api/v1/videos/imports' | |
254d3579 | 20 | let server: PeerTubeServer |
5d08a6a7 | 21 | let userAccessToken = '' |
5d08a6a7 | 22 | let channelId: number |
5d08a6a7 C |
23 | |
24 | // --------------------------------------------------------------- | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(30000) | |
28 | ||
254d3579 | 29 | server = await createSingleServer(1) |
5d08a6a7 C |
30 | |
31 | await setAccessTokensToServers([ server ]) | |
32 | ||
33 | const username = 'user1' | |
34 | const password = 'my super password' | |
89d241a7 C |
35 | await server.users.create({ username: username, password: password }) |
36 | userAccessToken = await server.login.getAccessToken({ username, password }) | |
5d08a6a7 C |
37 | |
38 | { | |
89d241a7 | 39 | const { videoChannels } = await server.users.getMyInfo() |
7926c5f9 | 40 | channelId = videoChannels[0].id |
5d08a6a7 C |
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 () { | |
c0e8b12e | 60 | await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) |
5d08a6a7 C |
61 | }) |
62 | }) | |
63 | ||
64 | describe('When adding a video import', function () { | |
65 | let baseCorrectParams | |
66 | ||
67 | before(function () { | |
68 | baseCorrectParams = { | |
59bbcced | 69 | targetUrl: FIXTURE_URLS.goodVideo, |
5d08a6a7 C |
70 | name: 'my super name', |
71 | category: 5, | |
72 | licence: 1, | |
73 | language: 'pt', | |
74 | nsfw: false, | |
75 | commentsEnabled: true, | |
7f2cfe3a | 76 | downloadEnabled: true, |
5d08a6a7 C |
77 | waitTranscoding: true, |
78 | description: 'my super description', | |
79 | support: 'my super support text', | |
80 | tags: [ 'tag1', 'tag2' ], | |
81 | privacy: VideoPrivacy.PUBLIC, | |
c8861d5d | 82 | channelId |
5d08a6a7 C |
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 | ||
590fb506 C |
91 | it('Should fail without a target url', async function () { |
92 | const fields = omit(baseCorrectParams, 'targetUrl') | |
2d53be02 RK |
93 | await makePostBodyRequest({ |
94 | url: server.url, | |
95 | path, | |
96 | token: server.accessToken, | |
97 | fields, | |
c0e8b12e | 98 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
2d53be02 | 99 | }) |
590fb506 C |
100 | }) |
101 | ||
102 | it('Should fail with a bad target url', async function () { | |
6c5065a0 | 103 | const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' } |
590fb506 C |
104 | |
105 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
106 | }) | |
7b54a81c C |
107 | |
108 | it('Should fail with localhost', async function () { | |
109 | const fields = { ...baseCorrectParams, targetUrl: 'http://localhost:8000' } | |
110 | ||
111 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
112 | }) | |
113 | ||
114 | it('Should fail with a private IP target urls', async function () { | |
115 | const targetUrls = [ | |
116 | 'http://127.0.0.1:8000', | |
117 | 'http://127.0.0.1', | |
118 | 'http://127.0.0.1/hello', | |
119 | 'https://192.168.1.42', | |
120 | 'http://192.168.1.42' | |
121 | ] | |
122 | ||
123 | for (const targetUrl of targetUrls) { | |
124 | const fields = { ...baseCorrectParams, targetUrl } | |
125 | ||
126 | await makePostBodyRequest({ | |
127 | url: server.url, | |
128 | path, | |
129 | token: server.accessToken, | |
130 | fields, | |
131 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
132 | }) | |
133 | } | |
134 | }) | |
590fb506 | 135 | |
5d08a6a7 | 136 | it('Should fail with a long name', async function () { |
6c5065a0 | 137 | const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } |
5d08a6a7 C |
138 | |
139 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
140 | }) | |
141 | ||
142 | it('Should fail with a bad category', async function () { | |
6c5065a0 | 143 | const fields = { ...baseCorrectParams, category: 125 } |
5d08a6a7 C |
144 | |
145 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
146 | }) | |
147 | ||
148 | it('Should fail with a bad licence', async function () { | |
6c5065a0 | 149 | const fields = { ...baseCorrectParams, licence: 125 } |
5d08a6a7 C |
150 | |
151 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
152 | }) | |
153 | ||
154 | it('Should fail with a bad language', async function () { | |
6c5065a0 | 155 | const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } |
5d08a6a7 C |
156 | |
157 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
158 | }) | |
159 | ||
160 | it('Should fail with a long description', async function () { | |
6c5065a0 | 161 | const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } |
5d08a6a7 C |
162 | |
163 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
164 | }) | |
165 | ||
166 | it('Should fail with a long support text', async function () { | |
6c5065a0 | 167 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } |
5d08a6a7 C |
168 | |
169 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
170 | }) | |
171 | ||
172 | it('Should fail without a channel', async function () { | |
173 | const fields = omit(baseCorrectParams, 'channelId') | |
174 | ||
175 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
176 | }) | |
177 | ||
178 | it('Should fail with a bad channel', async function () { | |
6c5065a0 | 179 | const fields = { ...baseCorrectParams, channelId: 545454 } |
5d08a6a7 C |
180 | |
181 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
182 | }) | |
183 | ||
184 | it('Should fail with another user channel', async function () { | |
185 | const user = { | |
186 | username: 'fake', | |
187 | password: 'fake_password' | |
188 | } | |
89d241a7 | 189 | await server.users.create({ username: user.username, password: user.password }) |
5d08a6a7 | 190 | |
89d241a7 C |
191 | const accessTokenUser = await server.login.getAccessToken(user) |
192 | const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser }) | |
7926c5f9 | 193 | const customChannelId = videoChannels[0].id |
5d08a6a7 | 194 | |
6c5065a0 | 195 | const fields = { ...baseCorrectParams, channelId: customChannelId } |
5d08a6a7 C |
196 | |
197 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | |
198 | }) | |
199 | ||
200 | it('Should fail with too many tags', async function () { | |
6c5065a0 | 201 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } |
5d08a6a7 C |
202 | |
203 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
204 | }) | |
205 | ||
206 | it('Should fail with a tag length too low', async function () { | |
6c5065a0 | 207 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } |
5d08a6a7 C |
208 | |
209 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
210 | }) | |
211 | ||
212 | it('Should fail with a tag length too big', async function () { | |
6c5065a0 | 213 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } |
5d08a6a7 C |
214 | |
215 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
216 | }) | |
217 | ||
218 | it('Should fail with an incorrect thumbnail file', async function () { | |
219 | const fields = baseCorrectParams | |
220 | const attaches = { | |
3d470a53 | 221 | thumbnailfile: buildAbsoluteFixturePath('video_short.mp4') |
5d08a6a7 C |
222 | } |
223 | ||
224 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
225 | }) | |
226 | ||
227 | it('Should fail with a big thumbnail file', async function () { | |
228 | const fields = baseCorrectParams | |
229 | const attaches = { | |
3d470a53 | 230 | thumbnailfile: buildAbsoluteFixturePath('preview-big.png') |
5d08a6a7 C |
231 | } |
232 | ||
233 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
234 | }) | |
235 | ||
236 | it('Should fail with an incorrect preview file', async function () { | |
237 | const fields = baseCorrectParams | |
238 | const attaches = { | |
3d470a53 | 239 | previewfile: buildAbsoluteFixturePath('video_short.mp4') |
5d08a6a7 C |
240 | } |
241 | ||
242 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
243 | }) | |
244 | ||
245 | it('Should fail with a big preview file', async function () { | |
246 | const fields = baseCorrectParams | |
247 | const attaches = { | |
3d470a53 | 248 | previewfile: buildAbsoluteFixturePath('preview-big.png') |
5d08a6a7 C |
249 | } |
250 | ||
251 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
252 | }) | |
253 | ||
187501f8 C |
254 | it('Should fail with an invalid torrent file', async function () { |
255 | const fields = omit(baseCorrectParams, 'targetUrl') | |
256 | const attaches = { | |
3d470a53 | 257 | torrentfile: buildAbsoluteFixturePath('avatar-big.png') |
187501f8 C |
258 | } |
259 | ||
260 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
261 | }) | |
262 | ||
263 | it('Should fail with an invalid magnet URI', async function () { | |
264 | let fields = omit(baseCorrectParams, 'targetUrl') | |
6c5065a0 | 265 | fields = { ...fields, magnetUri: 'blabla' } |
187501f8 C |
266 | |
267 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
268 | }) | |
269 | ||
5d08a6a7 | 270 | it('Should succeed with the correct parameters', async function () { |
13b6dc1f | 271 | this.timeout(30000) |
5d08a6a7 | 272 | |
b488ba1e C |
273 | await makePostBodyRequest({ |
274 | url: server.url, | |
275 | path, | |
276 | token: server.accessToken, | |
277 | fields: baseCorrectParams, | |
c0e8b12e | 278 | expectedStatus: HttpStatusCode.OK_200 |
b488ba1e | 279 | }) |
5d08a6a7 C |
280 | }) |
281 | ||
187501f8 | 282 | it('Should forbid to import http videos', async function () { |
89d241a7 | 283 | await server.config.updateCustomSubConfig({ |
65e6e260 C |
284 | newConfig: { |
285 | import: { | |
286 | videos: { | |
287 | http: { | |
288 | enabled: false | |
289 | }, | |
290 | torrent: { | |
291 | enabled: true | |
292 | } | |
590fb506 C |
293 | } |
294 | } | |
295 | } | |
296 | }) | |
297 | ||
298 | await makePostBodyRequest({ | |
299 | url: server.url, | |
300 | path, | |
301 | token: server.accessToken, | |
302 | fields: baseCorrectParams, | |
c0e8b12e | 303 | expectedStatus: HttpStatusCode.CONFLICT_409 |
590fb506 C |
304 | }) |
305 | }) | |
187501f8 C |
306 | |
307 | it('Should forbid to import torrent videos', async function () { | |
89d241a7 | 308 | await server.config.updateCustomSubConfig({ |
65e6e260 C |
309 | newConfig: { |
310 | import: { | |
311 | videos: { | |
312 | http: { | |
313 | enabled: true | |
314 | }, | |
315 | torrent: { | |
316 | enabled: false | |
317 | } | |
187501f8 C |
318 | } |
319 | } | |
320 | } | |
321 | }) | |
322 | ||
323 | let fields = omit(baseCorrectParams, 'targetUrl') | |
59bbcced | 324 | fields = { ...fields, magnetUri: FIXTURE_URLS.magnet } |
187501f8 | 325 | |
2d53be02 RK |
326 | await makePostBodyRequest({ |
327 | url: server.url, | |
328 | path, | |
329 | token: server.accessToken, | |
330 | fields, | |
c0e8b12e | 331 | expectedStatus: HttpStatusCode.CONFLICT_409 |
2d53be02 | 332 | }) |
187501f8 C |
333 | |
334 | fields = omit(fields, 'magnetUri') | |
335 | const attaches = { | |
3d470a53 | 336 | torrentfile: buildAbsoluteFixturePath('video-720p.torrent') |
187501f8 C |
337 | } |
338 | ||
2d53be02 RK |
339 | await makeUploadRequest({ |
340 | url: server.url, | |
341 | path, | |
342 | token: server.accessToken, | |
343 | fields, | |
344 | attaches, | |
c0e8b12e | 345 | expectedStatus: HttpStatusCode.CONFLICT_409 |
2d53be02 | 346 | }) |
187501f8 | 347 | }) |
5d08a6a7 C |
348 | }) |
349 | ||
7c3b7976 C |
350 | after(async function () { |
351 | await cleanupTests([ server ]) | |
5d08a6a7 C |
352 | }) |
353 | }) |