]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { omit } from 'lodash' | |
5 | import { | |
6 | buildAbsoluteFixturePath, | |
7 | checkBadCountPagination, | |
8 | checkBadSortPagination, | |
9 | checkBadStartPagination, | |
10 | cleanupTests, | |
11 | createSingleServer, | |
12 | FIXTURE_URLS, | |
13 | makeGetRequest, | |
14 | makePostBodyRequest, | |
15 | makeUploadRequest, | |
16 | PeerTubeServer, | |
17 | setAccessTokensToServers | |
18 | } from '@shared/extra-utils' | |
19 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | |
20 | ||
21 | describe('Test video imports API validator', function () { | |
22 | const path = '/api/v1/videos/imports' | |
23 | let server: PeerTubeServer | |
24 | let userAccessToken = '' | |
25 | let channelId: number | |
26 | ||
27 | // --------------------------------------------------------------- | |
28 | ||
29 | before(async function () { | |
30 | this.timeout(30000) | |
31 | ||
32 | server = await createSingleServer(1) | |
33 | ||
34 | await setAccessTokensToServers([ server ]) | |
35 | ||
36 | const username = 'user1' | |
37 | const password = 'my super password' | |
38 | await server.users.create({ username: username, password: password }) | |
39 | userAccessToken = await server.login.getAccessToken({ username, password }) | |
40 | ||
41 | { | |
42 | const { videoChannels } = await server.users.getMyInfo() | |
43 | channelId = videoChannels[0].id | |
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 () { | |
63 | await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) | |
64 | }) | |
65 | }) | |
66 | ||
67 | describe('When adding a video import', function () { | |
68 | let baseCorrectParams | |
69 | ||
70 | before(function () { | |
71 | baseCorrectParams = { | |
72 | targetUrl: FIXTURE_URLS.goodVideo, | |
73 | name: 'my super name', | |
74 | category: 5, | |
75 | licence: 1, | |
76 | language: 'pt', | |
77 | nsfw: false, | |
78 | commentsEnabled: true, | |
79 | downloadEnabled: true, | |
80 | waitTranscoding: true, | |
81 | description: 'my super description', | |
82 | support: 'my super support text', | |
83 | tags: [ 'tag1', 'tag2' ], | |
84 | privacy: VideoPrivacy.PUBLIC, | |
85 | channelId | |
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 | ||
94 | it('Should fail without a target url', async function () { | |
95 | const fields = omit(baseCorrectParams, 'targetUrl') | |
96 | await makePostBodyRequest({ | |
97 | url: server.url, | |
98 | path, | |
99 | token: server.accessToken, | |
100 | fields, | |
101 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
102 | }) | |
103 | }) | |
104 | ||
105 | it('Should fail with a bad target url', async function () { | |
106 | const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' } | |
107 | ||
108 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
109 | }) | |
110 | ||
111 | it('Should fail with a long name', async function () { | |
112 | const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } | |
113 | ||
114 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
115 | }) | |
116 | ||
117 | it('Should fail with a bad category', async function () { | |
118 | const fields = { ...baseCorrectParams, category: 125 } | |
119 | ||
120 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
121 | }) | |
122 | ||
123 | it('Should fail with a bad licence', async function () { | |
124 | const fields = { ...baseCorrectParams, licence: 125 } | |
125 | ||
126 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
127 | }) | |
128 | ||
129 | it('Should fail with a bad language', async function () { | |
130 | const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } | |
131 | ||
132 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
133 | }) | |
134 | ||
135 | it('Should fail with a long description', async function () { | |
136 | const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } | |
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 () { | |
142 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } | |
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 () { | |
154 | const fields = { ...baseCorrectParams, channelId: 545454 } | |
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 | } | |
164 | await server.users.create({ username: user.username, password: user.password }) | |
165 | ||
166 | const accessTokenUser = await server.login.getAccessToken(user) | |
167 | const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser }) | |
168 | const customChannelId = videoChannels[0].id | |
169 | ||
170 | const fields = { ...baseCorrectParams, channelId: customChannelId } | |
171 | ||
172 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | |
173 | }) | |
174 | ||
175 | it('Should fail with too many tags', async function () { | |
176 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } | |
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 () { | |
182 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } | |
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 () { | |
188 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } | |
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 = { | |
196 | thumbnailfile: buildAbsoluteFixturePath('video_short.mp4') | |
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 = { | |
205 | thumbnailfile: buildAbsoluteFixturePath('preview-big.png') | |
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 = { | |
214 | previewfile: buildAbsoluteFixturePath('video_short.mp4') | |
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 = { | |
223 | previewfile: buildAbsoluteFixturePath('preview-big.png') | |
224 | } | |
225 | ||
226 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
227 | }) | |
228 | ||
229 | it('Should fail with an invalid torrent file', async function () { | |
230 | const fields = omit(baseCorrectParams, 'targetUrl') | |
231 | const attaches = { | |
232 | torrentfile: buildAbsoluteFixturePath('avatar-big.png') | |
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') | |
240 | fields = { ...fields, magnetUri: 'blabla' } | |
241 | ||
242 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
243 | }) | |
244 | ||
245 | it('Should succeed with the correct parameters', async function () { | |
246 | this.timeout(30000) | |
247 | ||
248 | await makePostBodyRequest({ | |
249 | url: server.url, | |
250 | path, | |
251 | token: server.accessToken, | |
252 | fields: baseCorrectParams, | |
253 | expectedStatus: HttpStatusCode.OK_200 | |
254 | }) | |
255 | }) | |
256 | ||
257 | it('Should forbid to import http videos', async function () { | |
258 | await server.config.updateCustomSubConfig({ | |
259 | newConfig: { | |
260 | import: { | |
261 | videos: { | |
262 | http: { | |
263 | enabled: false | |
264 | }, | |
265 | torrent: { | |
266 | enabled: true | |
267 | } | |
268 | } | |
269 | } | |
270 | } | |
271 | }) | |
272 | ||
273 | await makePostBodyRequest({ | |
274 | url: server.url, | |
275 | path, | |
276 | token: server.accessToken, | |
277 | fields: baseCorrectParams, | |
278 | expectedStatus: HttpStatusCode.CONFLICT_409 | |
279 | }) | |
280 | }) | |
281 | ||
282 | it('Should forbid to import torrent videos', async function () { | |
283 | await server.config.updateCustomSubConfig({ | |
284 | newConfig: { | |
285 | import: { | |
286 | videos: { | |
287 | http: { | |
288 | enabled: true | |
289 | }, | |
290 | torrent: { | |
291 | enabled: false | |
292 | } | |
293 | } | |
294 | } | |
295 | } | |
296 | }) | |
297 | ||
298 | let fields = omit(baseCorrectParams, 'targetUrl') | |
299 | fields = { ...fields, magnetUri: FIXTURE_URLS.magnet } | |
300 | ||
301 | await makePostBodyRequest({ | |
302 | url: server.url, | |
303 | path, | |
304 | token: server.accessToken, | |
305 | fields, | |
306 | expectedStatus: HttpStatusCode.CONFLICT_409 | |
307 | }) | |
308 | ||
309 | fields = omit(fields, 'magnetUri') | |
310 | const attaches = { | |
311 | torrentfile: buildAbsoluteFixturePath('video-720p.torrent') | |
312 | } | |
313 | ||
314 | await makeUploadRequest({ | |
315 | url: server.url, | |
316 | path, | |
317 | token: server.accessToken, | |
318 | fields, | |
319 | attaches, | |
320 | expectedStatus: HttpStatusCode.CONFLICT_409 | |
321 | }) | |
322 | }) | |
323 | }) | |
324 | ||
325 | after(async function () { | |
326 | await cleanupTests([ server ]) | |
327 | }) | |
328 | }) |