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