]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0e1dc3e7 | 2 | |
0e1dc3e7 | 3 | import 'mocha' |
b488ba1e C |
4 | import { expect } from 'chai' |
5 | import { omit } from 'lodash' | |
47564bbe | 6 | import { join } from 'path' |
a95a4cc8 | 7 | import { User, UserRole, VideoImport, VideoImportState } from '../../../../shared' |
0e1dc3e7 | 8 | import { |
e590b4a5 | 9 | addVideoChannel, |
42e1ec25 | 10 | blockUser, |
7c3b7976 | 11 | cleanupTests, |
42e1ec25 C |
12 | createUser, |
13 | deleteMe, | |
14 | flushAndRunServer, | |
15 | getMyUserInformation, | |
16 | getMyUserVideoRating, | |
17 | getUsersList, | |
18 | immutableAssign, | |
45f1bd72 | 19 | killallServers, |
42e1ec25 C |
20 | makeGetRequest, |
21 | makePostBodyRequest, | |
22 | makePutBodyRequest, | |
23 | makeUploadRequest, | |
24 | registerUser, | |
25 | removeUser, | |
45f1bd72 | 26 | reRunServer, |
42e1ec25 C |
27 | ServerInfo, |
28 | setAccessTokensToServers, | |
29 | unblockUser, | |
30 | updateUser, | |
31 | uploadVideo, | |
32 | userLogin | |
94565d52 | 33 | } from '../../../../shared/extra-utils' |
b488ba1e | 34 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' |
9639bd17 | 35 | import { |
36 | checkBadCountPagination, | |
37 | checkBadSortPagination, | |
38 | checkBadStartPagination | |
94565d52 | 39 | } from '../../../../shared/extra-utils/requests/check-api-params' |
94565d52 | 40 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
b488ba1e | 41 | import { getMagnetURI, getMyVideoImports, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' |
1eddc9a7 | 42 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
b488ba1e | 43 | import { VideoPrivacy } from '../../../../shared/models/videos' |
0e1dc3e7 C |
44 | |
45 | describe('Test users API validators', function () { | |
46 | const path = '/api/v1/users/' | |
47 | let userId: number | |
48 | let rootId: number | |
a95a4cc8 | 49 | let moderatorId: number |
0e1dc3e7 C |
50 | let videoId: number |
51 | let server: ServerInfo | |
52 | let serverWithRegistrationDisabled: ServerInfo | |
53 | let userAccessToken = '' | |
a95a4cc8 | 54 | let moderatorAccessToken = '' |
45f1bd72 JL |
55 | let emailPort: number |
56 | let overrideConfig: Object | |
0e1dc3e7 C |
57 | |
58 | // --------------------------------------------------------------- | |
59 | ||
60 | before(async function () { | |
e212f887 | 61 | this.timeout(30000) |
0e1dc3e7 | 62 | |
45f1bd72 JL |
63 | const emails: object[] = [] |
64 | emailPort = await MockSmtpServer.Instance.collectEmails(emails) | |
65 | ||
66 | overrideConfig = { signup: { limit: 8 } } | |
67 | ||
a95a4cc8 C |
68 | { |
69 | const res = await Promise.all([ | |
45f1bd72 | 70 | flushAndRunServer(1, overrideConfig), |
a95a4cc8 C |
71 | flushAndRunServer(2) |
72 | ]) | |
0e1dc3e7 | 73 | |
a95a4cc8 C |
74 | server = res[0] |
75 | serverWithRegistrationDisabled = res[1] | |
0e1dc3e7 | 76 | |
a95a4cc8 C |
77 | await setAccessTokensToServers([ server ]) |
78 | } | |
79 | ||
80 | { | |
81 | const user = { | |
82 | username: 'user1', | |
83 | password: 'my super password' | |
84 | } | |
85 | ||
86 | const videoQuota = 42000000 | |
87 | await createUser({ | |
88 | url: server.url, | |
89 | accessToken: server.accessToken, | |
90 | username: user.username, | |
91 | password: user.password, | |
92 | videoQuota: videoQuota | |
93 | }) | |
94 | userAccessToken = await userLogin(server, user) | |
95 | } | |
96 | ||
97 | { | |
98 | const moderator = { | |
99 | username: 'moderator1', | |
100 | password: 'super password' | |
101 | } | |
102 | ||
103 | await createUser({ | |
104 | url: server.url, | |
105 | accessToken: server.accessToken, | |
106 | username: moderator.username, | |
107 | password: moderator.password, | |
108 | role: UserRole.MODERATOR | |
109 | }) | |
110 | ||
111 | moderatorAccessToken = await userLogin(server, moderator) | |
112 | } | |
113 | ||
114 | { | |
115 | const moderator = { | |
116 | username: 'moderator2', | |
117 | password: 'super password' | |
118 | } | |
119 | ||
120 | await createUser({ | |
121 | url: server.url, | |
122 | accessToken: server.accessToken, | |
123 | username: moderator.username, | |
124 | password: moderator.password, | |
125 | role: UserRole.MODERATOR | |
126 | }) | |
127 | } | |
26d21b78 | 128 | |
187501f8 C |
129 | { |
130 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
131 | videoId = res.body.video.id | |
132 | } | |
a95a4cc8 C |
133 | |
134 | { | |
135 | const res = await getUsersList(server.url, server.accessToken) | |
136 | const users: User[] = res.body.data | |
137 | ||
138 | userId = users.find(u => u.username === 'user1').id | |
139 | rootId = users.find(u => u.username === 'root').id | |
140 | moderatorId = users.find(u => u.username === 'moderator2').id | |
141 | } | |
0e1dc3e7 C |
142 | }) |
143 | ||
144 | describe('When listing users', function () { | |
145 | it('Should fail with a bad start pagination', async function () { | |
26d21b78 | 146 | await checkBadStartPagination(server.url, path, server.accessToken) |
0e1dc3e7 C |
147 | }) |
148 | ||
149 | it('Should fail with a bad count pagination', async function () { | |
26d21b78 | 150 | await checkBadCountPagination(server.url, path, server.accessToken) |
0e1dc3e7 C |
151 | }) |
152 | ||
153 | it('Should fail with an incorrect sort', async function () { | |
26d21b78 | 154 | await checkBadSortPagination(server.url, path, server.accessToken) |
0e1dc3e7 | 155 | }) |
86d13ec2 | 156 | |
ea7337cf RK |
157 | it('Should fail with a bad blocked/banned user filter', async function () { |
158 | await makeGetRequest({ | |
159 | url: server.url, | |
160 | path, | |
161 | query: { | |
162 | blocked: 42 | |
163 | }, | |
164 | token: server.accessToken, | |
165 | statusCodeExpected: 400 | |
166 | }) | |
167 | }) | |
168 | ||
86d13ec2 | 169 | it('Should fail with a non authenticated user', async function () { |
26d21b78 C |
170 | await makeGetRequest({ |
171 | url: server.url, | |
172 | path, | |
173 | statusCodeExpected: 401 | |
174 | }) | |
86d13ec2 C |
175 | }) |
176 | ||
177 | it('Should fail with a non admin user', async function () { | |
26d21b78 C |
178 | await makeGetRequest({ |
179 | url: server.url, | |
180 | path, | |
181 | token: userAccessToken, | |
182 | statusCodeExpected: 403 | |
183 | }) | |
86d13ec2 | 184 | }) |
0e1dc3e7 C |
185 | }) |
186 | ||
187 | describe('When adding a new user', function () { | |
26d21b78 C |
188 | const baseCorrectParams = { |
189 | username: 'user2', | |
190 | email: 'test@example.com', | |
191 | password: 'my super password', | |
192 | videoQuota: -1, | |
bee0abff | 193 | videoQuotaDaily: -1, |
1eddc9a7 | 194 | role: UserRole.USER, |
3487330d | 195 | adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST |
26d21b78 C |
196 | } |
197 | ||
0e1dc3e7 | 198 | it('Should fail with a too small username', async function () { |
d0ce42c1 | 199 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
0e1dc3e7 C |
200 | |
201 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
202 | }) | |
203 | ||
204 | it('Should fail with a too long username', async function () { | |
9f7a1953 | 205 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) |
0e1dc3e7 C |
206 | |
207 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
208 | }) | |
209 | ||
563d032e | 210 | it('Should fail with a not lowercase username', async function () { |
26d21b78 | 211 | const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) |
563d032e C |
212 | |
213 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
214 | }) | |
215 | ||
0e1dc3e7 | 216 | it('Should fail with an incorrect username', async function () { |
26d21b78 | 217 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) |
0e1dc3e7 C |
218 | |
219 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
220 | }) | |
221 | ||
222 | it('Should fail with a missing email', async function () { | |
26d21b78 | 223 | const fields = omit(baseCorrectParams, 'email') |
0e1dc3e7 C |
224 | |
225 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
226 | }) | |
227 | ||
228 | it('Should fail with an invalid email', async function () { | |
26d21b78 | 229 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) |
0e1dc3e7 C |
230 | |
231 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
232 | }) | |
233 | ||
234 | it('Should fail with a too small password', async function () { | |
26d21b78 | 235 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) |
0e1dc3e7 C |
236 | |
237 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
238 | }) | |
239 | ||
240 | it('Should fail with a too long password', async function () { | |
26d21b78 | 241 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) |
0e1dc3e7 C |
242 | |
243 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
244 | }) | |
245 | ||
45f1bd72 JL |
246 | it('Should fail with empty password and no smtp configured', async function () { |
247 | const fields = immutableAssign(baseCorrectParams, { password: '' }) | |
248 | ||
249 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
250 | }) | |
251 | ||
252 | it('Should succeed with no password on a server with smtp enabled', async function () { | |
253 | this.timeout(10000) | |
254 | ||
255 | killallServers([ server ]) | |
256 | ||
257 | const config = immutableAssign(overrideConfig, { | |
258 | smtp: { | |
259 | hostname: 'localhost', | |
260 | port: emailPort | |
261 | } | |
262 | }) | |
263 | await reRunServer(server, config) | |
264 | ||
265 | const fields = immutableAssign(baseCorrectParams, { | |
266 | password: '', | |
267 | username: 'create_password', | |
268 | email: 'create_password@example.com' | |
269 | }) | |
270 | ||
271 | await makePostBodyRequest({ | |
272 | url: server.url, | |
273 | path: path, | |
274 | token: server.accessToken, | |
275 | fields, | |
276 | statusCodeExpected: 200 | |
277 | }) | |
278 | }) | |
279 | ||
1eddc9a7 C |
280 | it('Should fail with invalid admin flags', async function () { |
281 | const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) | |
282 | ||
283 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
284 | }) | |
285 | ||
0e1dc3e7 | 286 | it('Should fail with an non authenticated user', async function () { |
26d21b78 C |
287 | await makePostBodyRequest({ |
288 | url: server.url, | |
289 | path, | |
290 | token: 'super token', | |
291 | fields: baseCorrectParams, | |
292 | statusCodeExpected: 401 | |
293 | }) | |
0e1dc3e7 C |
294 | }) |
295 | ||
296 | it('Should fail if we add a user with the same username', async function () { | |
26d21b78 | 297 | const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) |
0e1dc3e7 C |
298 | |
299 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
300 | }) | |
301 | ||
302 | it('Should fail if we add a user with the same email', async function () { | |
26d21b78 | 303 | const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) |
0e1dc3e7 C |
304 | |
305 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
306 | }) | |
307 | ||
77a5501f | 308 | it('Should fail without a videoQuota', async function () { |
26d21b78 | 309 | const fields = omit(baseCorrectParams, 'videoQuota') |
77a5501f C |
310 | |
311 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
312 | }) | |
313 | ||
bee0abff FA |
314 | it('Should fail without a videoQuotaDaily', async function () { |
315 | const fields = omit(baseCorrectParams, 'videoQuotaDaily') | |
316 | ||
317 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
318 | }) | |
319 | ||
77a5501f | 320 | it('Should fail with an invalid videoQuota', async function () { |
26d21b78 | 321 | const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) |
757f0da3 C |
322 | |
323 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
324 | }) | |
325 | ||
bee0abff FA |
326 | it('Should fail with an invalid videoQuotaDaily', async function () { |
327 | const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) | |
328 | ||
329 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
330 | }) | |
331 | ||
757f0da3 | 332 | it('Should fail without a user role', async function () { |
26d21b78 | 333 | const fields = omit(baseCorrectParams, 'role') |
757f0da3 C |
334 | |
335 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
336 | }) | |
337 | ||
338 | it('Should fail with an invalid user role', async function () { | |
26d21b78 | 339 | const fields = immutableAssign(baseCorrectParams, { role: 88989 }) |
77a5501f C |
340 | |
341 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
342 | }) | |
343 | ||
2ef6a063 C |
344 | it('Should fail with a "peertube" username', async function () { |
345 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
346 | ||
347 | await makePostBodyRequest({ | |
348 | url: server.url, | |
349 | path, | |
350 | token: server.accessToken, | |
351 | fields, | |
352 | statusCodeExpected: 409 | |
353 | }) | |
354 | }) | |
355 | ||
a95a4cc8 C |
356 | it('Should fail to create a moderator or an admin with a moderator', async function () { |
357 | for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) { | |
358 | const fields = immutableAssign(baseCorrectParams, { role }) | |
359 | ||
360 | await makePostBodyRequest({ | |
361 | url: server.url, | |
362 | path, | |
363 | token: moderatorAccessToken, | |
364 | fields, | |
365 | statusCodeExpected: 403 | |
366 | }) | |
367 | } | |
368 | }) | |
369 | ||
370 | it('Should succeed to create a user with a moderator', async function () { | |
371 | const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }) | |
372 | ||
373 | await makePostBodyRequest({ | |
374 | url: server.url, | |
375 | path, | |
376 | token: moderatorAccessToken, | |
377 | fields, | |
378 | statusCodeExpected: 200 | |
379 | }) | |
380 | }) | |
381 | ||
0e1dc3e7 | 382 | it('Should succeed with the correct params', async function () { |
26d21b78 C |
383 | await makePostBodyRequest({ |
384 | url: server.url, | |
385 | path, | |
386 | token: server.accessToken, | |
387 | fields: baseCorrectParams, | |
f05a1c30 | 388 | statusCodeExpected: 200 |
26d21b78 | 389 | }) |
0e1dc3e7 C |
390 | }) |
391 | ||
392 | it('Should fail with a non admin user', async function () { | |
26d21b78 | 393 | const user = { |
0e1dc3e7 | 394 | username: 'user1', |
0e1dc3e7 C |
395 | password: 'my super password' |
396 | } | |
26d21b78 | 397 | userAccessToken = await userLogin(server, user) |
0e1dc3e7 | 398 | |
0e1dc3e7 C |
399 | const fields = { |
400 | username: 'user3', | |
401 | email: 'test@example.com', | |
77a5501f C |
402 | password: 'my super password', |
403 | videoQuota: 42000000 | |
0e1dc3e7 C |
404 | } |
405 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | |
406 | }) | |
407 | }) | |
408 | ||
77a5501f C |
409 | describe('When updating my account', function () { |
410 | it('Should fail with an invalid email attribute', async function () { | |
411 | const fields = { | |
412 | email: 'blabla' | |
413 | } | |
0e1dc3e7 | 414 | |
77a5501f | 415 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields }) |
0e1dc3e7 C |
416 | }) |
417 | ||
418 | it('Should fail with a too small password', async function () { | |
419 | const fields = { | |
a890d1e0 | 420 | currentPassword: 'my super password', |
0e1dc3e7 C |
421 | password: 'bla' |
422 | } | |
423 | ||
77a5501f | 424 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
425 | }) |
426 | ||
427 | it('Should fail with a too long password', async function () { | |
428 | const fields = { | |
a890d1e0 | 429 | currentPassword: 'my super password', |
26d21b78 | 430 | password: 'super'.repeat(61) |
0e1dc3e7 C |
431 | } |
432 | ||
77a5501f | 433 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
434 | }) |
435 | ||
a890d1e0 C |
436 | it('Should fail without the current password', async function () { |
437 | const fields = { | |
438 | currentPassword: 'my super password', | |
439 | password: 'super'.repeat(61) | |
440 | } | |
441 | ||
442 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
443 | }) | |
444 | ||
445 | it('Should fail with an invalid current password', async function () { | |
446 | const fields = { | |
447 | currentPassword: 'my super password fail', | |
448 | password: 'super'.repeat(61) | |
449 | } | |
450 | ||
451 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 }) | |
452 | }) | |
453 | ||
0883b324 | 454 | it('Should fail with an invalid NSFW policy attribute', async function () { |
0e1dc3e7 | 455 | const fields = { |
0883b324 | 456 | nsfwPolicy: 'hello' |
0e1dc3e7 C |
457 | } |
458 | ||
77a5501f | 459 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
460 | }) |
461 | ||
7efe153b AL |
462 | it('Should fail with an invalid autoPlayVideo attribute', async function () { |
463 | const fields = { | |
464 | autoPlayVideo: -1 | |
465 | } | |
466 | ||
467 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
468 | }) | |
469 | ||
6aa54148 L |
470 | it('Should fail with an invalid autoPlayNextVideo attribute', async function () { |
471 | const fields = { | |
472 | autoPlayNextVideo: -1 | |
473 | } | |
474 | ||
475 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
476 | }) | |
477 | ||
8b9a525a C |
478 | it('Should fail with an invalid videosHistoryEnabled attribute', async function () { |
479 | const fields = { | |
480 | videosHistoryEnabled: -1 | |
481 | } | |
482 | ||
483 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
484 | }) | |
485 | ||
0e1dc3e7 C |
486 | it('Should fail with an non authenticated user', async function () { |
487 | const fields = { | |
a890d1e0 | 488 | currentPassword: 'my super password', |
0e1dc3e7 C |
489 | password: 'my super password' |
490 | } | |
491 | ||
77a5501f | 492 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) |
0e1dc3e7 C |
493 | }) |
494 | ||
2422c46b C |
495 | it('Should fail with a too long description', async function () { |
496 | const fields = { | |
d23e6a1c | 497 | description: 'super'.repeat(201) |
2422c46b C |
498 | } |
499 | ||
500 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
501 | }) | |
502 | ||
3caf77d3 C |
503 | it('Should fail with an invalid videoLanguages attribute', async function () { |
504 | { | |
505 | const fields = { | |
506 | videoLanguages: 'toto' | |
507 | } | |
508 | ||
509 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
510 | } | |
511 | ||
512 | { | |
513 | const languages = [] | |
514 | for (let i = 0; i < 1000; i++) { | |
515 | languages.push('fr') | |
516 | } | |
517 | ||
518 | const fields = { | |
519 | videoLanguages: languages | |
520 | } | |
521 | ||
522 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
523 | } | |
524 | }) | |
525 | ||
9b474844 C |
526 | it('Should fail with an invalid theme', async function () { |
527 | const fields = { theme: 'invalid' } | |
528 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
529 | }) | |
530 | ||
531 | it('Should fail with an unknown theme', async function () { | |
532 | const fields = { theme: 'peertube-theme-unknown' } | |
533 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
534 | }) | |
535 | ||
43d0ea7f C |
536 | it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { |
537 | const fields = { | |
538 | noInstanceConfigWarningModal: -1 | |
539 | } | |
540 | ||
541 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
542 | }) | |
543 | ||
544 | it('Should fail with an invalid noWelcomeModal attribute', async function () { | |
545 | const fields = { | |
546 | noWelcomeModal: -1 | |
547 | } | |
548 | ||
549 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
550 | }) | |
551 | ||
a890d1e0 | 552 | it('Should succeed to change password with the correct params', async function () { |
0e1dc3e7 | 553 | const fields = { |
a890d1e0 | 554 | currentPassword: 'my super password', |
0e1dc3e7 | 555 | password: 'my super password', |
0883b324 | 556 | nsfwPolicy: 'blur', |
7efe153b | 557 | autoPlayVideo: false, |
9b474844 | 558 | email: 'super_email@example.com', |
43d0ea7f C |
559 | theme: 'default', |
560 | noInstanceConfigWarningModal: true, | |
561 | noWelcomeModal: true | |
0e1dc3e7 C |
562 | } |
563 | ||
77a5501f C |
564 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) |
565 | }) | |
a890d1e0 C |
566 | |
567 | it('Should succeed without password change with the correct params', async function () { | |
568 | const fields = { | |
569 | nsfwPolicy: 'blur', | |
5efab546 | 570 | autoPlayVideo: false |
a890d1e0 C |
571 | } |
572 | ||
573 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) | |
574 | }) | |
77a5501f C |
575 | }) |
576 | ||
c5911fd3 C |
577 | describe('When updating my avatar', function () { |
578 | it('Should fail without an incorrect input file', async function () { | |
579 | const fields = {} | |
580 | const attaches = { | |
a1587156 | 581 | avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
c5911fd3 | 582 | } |
ac81d1a0 | 583 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
c5911fd3 C |
584 | }) |
585 | ||
01de67b9 C |
586 | it('Should fail with a big file', async function () { |
587 | const fields = {} | |
588 | const attaches = { | |
a1587156 | 589 | avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
01de67b9 | 590 | } |
ac81d1a0 | 591 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
01de67b9 C |
592 | }) |
593 | ||
4bbfc6c6 C |
594 | it('Should fail with an unauthenticated user', async function () { |
595 | const fields = {} | |
596 | const attaches = { | |
a1587156 | 597 | avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
4bbfc6c6 C |
598 | } |
599 | await makeUploadRequest({ | |
600 | url: server.url, | |
601 | path: path + '/me/avatar/pick', | |
602 | fields, | |
603 | attaches, | |
604 | statusCodeExpected: 401 | |
605 | }) | |
606 | }) | |
607 | ||
c5911fd3 C |
608 | it('Should succeed with the correct params', async function () { |
609 | const fields = {} | |
610 | const attaches = { | |
a1587156 | 611 | avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
c5911fd3 | 612 | } |
ac81d1a0 | 613 | await makeUploadRequest({ |
47564bbe C |
614 | url: server.url, |
615 | path: path + '/me/avatar/pick', | |
616 | token: server.accessToken, | |
617 | fields, | |
618 | attaches, | |
619 | statusCodeExpected: 200 | |
620 | }) | |
c5911fd3 C |
621 | }) |
622 | }) | |
623 | ||
94ff4c23 | 624 | describe('When getting a user', function () { |
94ff4c23 C |
625 | |
626 | it('Should fail with an non authenticated user', async function () { | |
627 | await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 }) | |
628 | }) | |
629 | ||
630 | it('Should fail with a non admin user', async function () { | |
631 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 }) | |
632 | }) | |
633 | ||
634 | it('Should succeed with the correct params', async function () { | |
635 | await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 }) | |
636 | }) | |
637 | }) | |
638 | ||
77a5501f C |
639 | describe('When updating a user', function () { |
640 | ||
77a5501f C |
641 | it('Should fail with an invalid email attribute', async function () { |
642 | const fields = { | |
643 | email: 'blabla' | |
644 | } | |
645 | ||
646 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
647 | }) | |
648 | ||
fc2ec87a JM |
649 | it('Should fail with an invalid emailVerified attribute', async function () { |
650 | const fields = { | |
651 | emailVerified: 'yes' | |
652 | } | |
653 | ||
654 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
655 | }) | |
656 | ||
77a5501f C |
657 | it('Should fail with an invalid videoQuota attribute', async function () { |
658 | const fields = { | |
659 | videoQuota: -90 | |
660 | } | |
661 | ||
662 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
663 | }) | |
664 | ||
757f0da3 C |
665 | it('Should fail with an invalid user role attribute', async function () { |
666 | const fields = { | |
667 | role: 54878 | |
668 | } | |
669 | ||
670 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
671 | }) | |
672 | ||
b426edd4 C |
673 | it('Should fail with a too small password', async function () { |
674 | const fields = { | |
675 | currentPassword: 'my super password', | |
676 | password: 'bla' | |
677 | } | |
678 | ||
679 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
680 | }) | |
681 | ||
682 | it('Should fail with a too long password', async function () { | |
683 | const fields = { | |
684 | currentPassword: 'my super password', | |
685 | password: 'super'.repeat(61) | |
686 | } | |
687 | ||
688 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
689 | }) | |
690 | ||
77a5501f C |
691 | it('Should fail with an non authenticated user', async function () { |
692 | const fields = { | |
693 | videoQuota: 42 | |
694 | } | |
695 | ||
696 | await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) | |
697 | }) | |
698 | ||
f8b8c36b C |
699 | it('Should fail when updating root role', async function () { |
700 | const fields = { | |
701 | role: UserRole.MODERATOR | |
702 | } | |
703 | ||
704 | await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields }) | |
1eddc9a7 C |
705 | }) |
706 | ||
707 | it('Should fail with invalid admin flags', async function () { | |
708 | const fields = { adminFlags: 'toto' } | |
709 | ||
a95a4cc8 C |
710 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
711 | }) | |
712 | ||
713 | it('Should fail to update an admin with a moderator', async function () { | |
714 | const fields = { | |
715 | videoQuota: 42 | |
716 | } | |
717 | ||
718 | await makePutBodyRequest({ | |
719 | url: server.url, | |
720 | path: path + moderatorId, | |
721 | token: moderatorAccessToken, | |
722 | fields, | |
723 | statusCodeExpected: 403 | |
724 | }) | |
725 | }) | |
726 | ||
727 | it('Should succeed to update a user with a moderator', async function () { | |
728 | const fields = { | |
729 | videoQuota: 42 | |
730 | } | |
731 | ||
732 | await makePutBodyRequest({ | |
733 | url: server.url, | |
734 | path: path + userId, | |
735 | token: moderatorAccessToken, | |
736 | fields, | |
737 | statusCodeExpected: 204 | |
738 | }) | |
f8b8c36b C |
739 | }) |
740 | ||
77a5501f C |
741 | it('Should succeed with the correct params', async function () { |
742 | const fields = { | |
743 | email: 'email@example.com', | |
fc2ec87a | 744 | emailVerified: true, |
757f0da3 | 745 | videoQuota: 42, |
2f1548fd | 746 | role: UserRole.USER |
77a5501f C |
747 | } |
748 | ||
749 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
0e1dc3e7 C |
750 | }) |
751 | }) | |
752 | ||
753 | describe('When getting my information', function () { | |
754 | it('Should fail with a non authenticated user', async function () { | |
26d21b78 | 755 | await getMyUserInformation(server.url, 'fake_token', 401) |
0e1dc3e7 C |
756 | }) |
757 | ||
758 | it('Should success with the correct parameters', async function () { | |
26d21b78 | 759 | await getMyUserInformation(server.url, userAccessToken) |
0e1dc3e7 C |
760 | }) |
761 | }) | |
762 | ||
763 | describe('When getting my video rating', function () { | |
764 | it('Should fail with a non authenticated user', async function () { | |
26d21b78 | 765 | await getMyUserVideoRating(server.url, 'fake_token', videoId, 401) |
0e1dc3e7 C |
766 | }) |
767 | ||
768 | it('Should fail with an incorrect video uuid', async function () { | |
26d21b78 | 769 | await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400) |
0e1dc3e7 C |
770 | }) |
771 | ||
772 | it('Should fail with an unknown video', async function () { | |
26d21b78 | 773 | await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) |
0e1dc3e7 C |
774 | }) |
775 | ||
26d21b78 C |
776 | it('Should succeed with the correct parameters', async function () { |
777 | await getMyUserVideoRating(server.url, server.accessToken, videoId) | |
0e1dc3e7 C |
778 | }) |
779 | }) | |
780 | ||
22834691 C |
781 | describe('When retrieving my global ratings', function () { |
782 | const path = '/api/v1/accounts/user1/ratings' | |
783 | ||
784 | it('Should fail with a bad start pagination', async function () { | |
785 | await checkBadStartPagination(server.url, path, userAccessToken) | |
786 | }) | |
787 | ||
788 | it('Should fail with a bad count pagination', async function () { | |
789 | await checkBadCountPagination(server.url, path, userAccessToken) | |
790 | }) | |
791 | ||
792 | it('Should fail with an incorrect sort', async function () { | |
793 | await checkBadSortPagination(server.url, path, userAccessToken) | |
794 | }) | |
795 | ||
796 | it('Should fail with a unauthenticated user', async function () { | |
797 | await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) | |
798 | }) | |
799 | ||
800 | it('Should fail with a another user', async function () { | |
801 | await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) | |
802 | }) | |
803 | ||
804 | it('Should fail with a bad type', async function () { | |
805 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) | |
806 | }) | |
807 | ||
808 | it('Should succeed with the correct params', async function () { | |
809 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) | |
810 | }) | |
811 | }) | |
812 | ||
e6921918 | 813 | describe('When blocking/unblocking/removing user', function () { |
0e1dc3e7 | 814 | it('Should fail with an incorrect id', async function () { |
26d21b78 | 815 | await removeUser(server.url, 'blabla', server.accessToken, 400) |
e6921918 C |
816 | await blockUser(server.url, 'blabla', server.accessToken, 400) |
817 | await unblockUser(server.url, 'blabla', server.accessToken, 400) | |
0e1dc3e7 C |
818 | }) |
819 | ||
820 | it('Should fail with the root user', async function () { | |
26d21b78 | 821 | await removeUser(server.url, rootId, server.accessToken, 400) |
e6921918 C |
822 | await blockUser(server.url, rootId, server.accessToken, 400) |
823 | await unblockUser(server.url, rootId, server.accessToken, 400) | |
0e1dc3e7 C |
824 | }) |
825 | ||
826 | it('Should return 404 with a non existing id', async function () { | |
26d21b78 | 827 | await removeUser(server.url, 4545454, server.accessToken, 404) |
e6921918 C |
828 | await blockUser(server.url, 4545454, server.accessToken, 404) |
829 | await unblockUser(server.url, 4545454, server.accessToken, 404) | |
830 | }) | |
831 | ||
832 | it('Should fail with a non admin user', async function () { | |
833 | await removeUser(server.url, userId, userAccessToken, 403) | |
834 | await blockUser(server.url, userId, userAccessToken, 403) | |
835 | await unblockUser(server.url, userId, userAccessToken, 403) | |
0e1dc3e7 | 836 | }) |
a95a4cc8 C |
837 | |
838 | it('Should fail on a moderator with a moderator', async function () { | |
839 | await removeUser(server.url, moderatorId, moderatorAccessToken, 403) | |
840 | await blockUser(server.url, moderatorId, moderatorAccessToken, 403) | |
841 | await unblockUser(server.url, moderatorId, moderatorAccessToken, 403) | |
842 | }) | |
843 | ||
844 | it('Should succeed on a user with a moderator', async function () { | |
845 | await blockUser(server.url, userId, moderatorAccessToken) | |
846 | await unblockUser(server.url, userId, moderatorAccessToken) | |
847 | }) | |
0e1dc3e7 C |
848 | }) |
849 | ||
92b9d60c C |
850 | describe('When deleting our account', function () { |
851 | it('Should fail with with the root account', async function () { | |
852 | await deleteMe(server.url, server.accessToken, 400) | |
853 | }) | |
854 | }) | |
855 | ||
e590b4a5 | 856 | describe('When registering a new user', function () { |
0e1dc3e7 | 857 | const registrationPath = path + '/register' |
26d21b78 C |
858 | const baseCorrectParams = { |
859 | username: 'user3', | |
1f20622f | 860 | displayName: 'super user', |
26d21b78 C |
861 | email: 'test3@example.com', |
862 | password: 'my super password' | |
863 | } | |
0e1dc3e7 C |
864 | |
865 | it('Should fail with a too small username', async function () { | |
d0ce42c1 | 866 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
0e1dc3e7 C |
867 | |
868 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
869 | }) | |
870 | ||
871 | it('Should fail with a too long username', async function () { | |
9f7a1953 | 872 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) |
0e1dc3e7 C |
873 | |
874 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
875 | }) | |
876 | ||
877 | it('Should fail with an incorrect username', async function () { | |
26d21b78 | 878 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) |
0e1dc3e7 C |
879 | |
880 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
881 | }) | |
882 | ||
883 | it('Should fail with a missing email', async function () { | |
26d21b78 | 884 | const fields = omit(baseCorrectParams, 'email') |
0e1dc3e7 C |
885 | |
886 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
887 | }) | |
888 | ||
889 | it('Should fail with an invalid email', async function () { | |
26d21b78 | 890 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) |
0e1dc3e7 C |
891 | |
892 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
893 | }) | |
894 | ||
895 | it('Should fail with a too small password', async function () { | |
26d21b78 | 896 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) |
0e1dc3e7 C |
897 | |
898 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
899 | }) | |
900 | ||
901 | it('Should fail with a too long password', async function () { | |
26d21b78 | 902 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) |
0e1dc3e7 C |
903 | |
904 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
905 | }) | |
906 | ||
907 | it('Should fail if we register a user with the same username', async function () { | |
26d21b78 | 908 | const fields = immutableAssign(baseCorrectParams, { username: 'root' }) |
0e1dc3e7 | 909 | |
26d21b78 C |
910 | await makePostBodyRequest({ |
911 | url: server.url, | |
912 | path: registrationPath, | |
913 | token: server.accessToken, | |
914 | fields, | |
915 | statusCodeExpected: 409 | |
916 | }) | |
0e1dc3e7 C |
917 | }) |
918 | ||
2ef6a063 C |
919 | it('Should fail with a "peertube" username', async function () { |
920 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
921 | ||
922 | await makePostBodyRequest({ | |
923 | url: server.url, | |
924 | path: registrationPath, | |
925 | token: server.accessToken, | |
926 | fields, | |
927 | statusCodeExpected: 409 | |
928 | }) | |
929 | }) | |
930 | ||
0e1dc3e7 | 931 | it('Should fail if we register a user with the same email', async function () { |
7c3b7976 | 932 | const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) |
0e1dc3e7 | 933 | |
26d21b78 C |
934 | await makePostBodyRequest({ |
935 | url: server.url, | |
936 | path: registrationPath, | |
937 | token: server.accessToken, | |
938 | fields, | |
939 | statusCodeExpected: 409 | |
940 | }) | |
0e1dc3e7 C |
941 | }) |
942 | ||
1f20622f C |
943 | it('Should fail with a bad display name', async function () { |
944 | const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) }) | |
945 | ||
946 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
947 | }) | |
948 | ||
e590b4a5 C |
949 | it('Should fail with a bad channel name', async function () { |
950 | const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } }) | |
951 | ||
952 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
953 | }) | |
954 | ||
955 | it('Should fail with a bad channel display name', async function () { | |
956 | const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } }) | |
957 | ||
958 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
959 | }) | |
960 | ||
32d7f2b7 | 961 | it('Should fail with a channel name that is the same as username', async function () { |
1d5342ab C |
962 | const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } } |
963 | const fields = immutableAssign(baseCorrectParams, source) | |
964 | ||
965 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
966 | }) | |
967 | ||
e590b4a5 C |
968 | it('Should fail with an existing channel', async function () { |
969 | const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' } | |
970 | await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg) | |
971 | ||
972 | const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) | |
973 | ||
974 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
975 | }) | |
976 | ||
0e1dc3e7 | 977 | it('Should succeed with the correct params', async function () { |
e590b4a5 C |
978 | const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } }) |
979 | ||
26d21b78 C |
980 | await makePostBodyRequest({ |
981 | url: server.url, | |
982 | path: registrationPath, | |
983 | token: server.accessToken, | |
e590b4a5 | 984 | fields: fields, |
26d21b78 C |
985 | statusCodeExpected: 204 |
986 | }) | |
0e1dc3e7 C |
987 | }) |
988 | ||
989 | it('Should fail on a server with registration disabled', async function () { | |
990 | const fields = { | |
991 | username: 'user4', | |
992 | email: 'test4@example.com', | |
993 | password: 'my super password 4' | |
994 | } | |
995 | ||
996 | await makePostBodyRequest({ | |
997 | url: serverWithRegistrationDisabled.url, | |
998 | path: registrationPath, | |
999 | token: serverWithRegistrationDisabled.accessToken, | |
1000 | fields, | |
1001 | statusCodeExpected: 403 | |
1002 | }) | |
1003 | }) | |
1004 | }) | |
1005 | ||
1006 | describe('When registering multiple users on a server with users limit', function () { | |
1007 | it('Should fail when after 3 registrations', async function () { | |
1008 | await registerUser(server.url, 'user42', 'super password', 403) | |
1009 | }) | |
1010 | }) | |
1011 | ||
77a5501f | 1012 | describe('When having a video quota', function () { |
bee0abff | 1013 | it('Should fail with a user having too many videos', async function () { |
26d21b78 C |
1014 | await updateUser({ |
1015 | url: server.url, | |
1016 | userId: rootId, | |
1017 | accessToken: server.accessToken, | |
77a5501f | 1018 | videoQuota: 42 |
26d21b78 | 1019 | }) |
77a5501f | 1020 | |
26d21b78 | 1021 | await uploadVideo(server.url, server.accessToken, {}, 403) |
77a5501f C |
1022 | }) |
1023 | ||
bee0abff | 1024 | it('Should fail with a registered user having too many videos', async function () { |
adc236fe | 1025 | this.timeout(30000) |
77a5501f | 1026 | |
26d21b78 | 1027 | const user = { |
77a5501f | 1028 | username: 'user3', |
77a5501f C |
1029 | password: 'my super password' |
1030 | } | |
26d21b78 | 1031 | userAccessToken = await userLogin(server, user) |
77a5501f C |
1032 | |
1033 | const videoAttributes = { fixture: 'video_short2.webm' } | |
1034 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
1035 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
1036 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
1037 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
1038 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
1039 | await uploadVideo(server.url, userAccessToken, videoAttributes, 403) | |
1040 | }) | |
187501f8 C |
1041 | |
1042 | it('Should fail to import with HTTP/Torrent/magnet', async function () { | |
a031ab0b | 1043 | this.timeout(120000) |
187501f8 C |
1044 | |
1045 | const baseAttributes = { | |
1046 | channelId: 1, | |
1047 | privacy: VideoPrivacy.PUBLIC | |
1048 | } | |
b488ba1e | 1049 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) |
187501f8 | 1050 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) |
9a7fd960 | 1051 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) |
187501f8 C |
1052 | |
1053 | await waitJobs([ server ]) | |
1054 | ||
1055 | const res = await getMyVideoImports(server.url, server.accessToken) | |
1056 | ||
1057 | expect(res.body.total).to.equal(3) | |
1058 | const videoImports: VideoImport[] = res.body.data | |
1059 | expect(videoImports).to.have.lengthOf(3) | |
1060 | ||
1061 | for (const videoImport of videoImports) { | |
1062 | expect(videoImport.state.id).to.equal(VideoImportState.FAILED) | |
1063 | expect(videoImport.error).not.to.be.undefined | |
1064 | expect(videoImport.error).to.contain('user video quota is exceeded') | |
1065 | } | |
1066 | }) | |
77a5501f C |
1067 | }) |
1068 | ||
bee0abff FA |
1069 | describe('When having a daily video quota', function () { |
1070 | it('Should fail with a user having too many videos', async function () { | |
1071 | await updateUser({ | |
1072 | url: server.url, | |
1073 | userId: rootId, | |
1074 | accessToken: server.accessToken, | |
1075 | videoQuotaDaily: 42 | |
1076 | }) | |
1077 | ||
1078 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
1079 | }) | |
1080 | }) | |
1081 | ||
1082 | describe('When having an absolute and daily video quota', function () { | |
1083 | it('Should fail if exceeding total quota', async function () { | |
1084 | await updateUser({ | |
1085 | url: server.url, | |
1086 | userId: rootId, | |
1087 | accessToken: server.accessToken, | |
1088 | videoQuota: 42, | |
1089 | videoQuotaDaily: 1024 * 1024 * 1024 | |
1090 | }) | |
1091 | ||
1092 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
1093 | }) | |
1094 | ||
1095 | it('Should fail if exceeding daily quota', async function () { | |
1096 | await updateUser({ | |
1097 | url: server.url, | |
1098 | userId: rootId, | |
1099 | accessToken: server.accessToken, | |
1100 | videoQuota: 1024 * 1024 * 1024, | |
1101 | videoQuotaDaily: 42 | |
1102 | }) | |
1103 | ||
1104 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
1105 | }) | |
1106 | }) | |
1107 | ||
f076daa7 C |
1108 | describe('When asking a password reset', function () { |
1109 | const path = '/api/v1/users/ask-reset-password' | |
1110 | ||
1111 | it('Should fail with a missing email', async function () { | |
1112 | const fields = {} | |
1113 | ||
1114 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
1115 | }) | |
1116 | ||
1117 | it('Should fail with an invalid email', async function () { | |
1118 | const fields = { email: 'hello' } | |
1119 | ||
1120 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
1121 | }) | |
1122 | ||
1123 | it('Should success with the correct params', async function () { | |
1124 | const fields = { email: 'admin@example.com' } | |
1125 | ||
1126 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
1127 | }) | |
1128 | }) | |
1129 | ||
d9eaee39 JM |
1130 | describe('When asking for an account verification email', function () { |
1131 | const path = '/api/v1/users/ask-send-verify-email' | |
1132 | ||
1133 | it('Should fail with a missing email', async function () { | |
1134 | const fields = {} | |
1135 | ||
1136 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
1137 | }) | |
1138 | ||
1139 | it('Should fail with an invalid email', async function () { | |
1140 | const fields = { email: 'hello' } | |
1141 | ||
1142 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
1143 | }) | |
1144 | ||
1145 | it('Should succeed with the correct params', async function () { | |
1146 | const fields = { email: 'admin@example.com' } | |
1147 | ||
1148 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
1149 | }) | |
1150 | }) | |
1151 | ||
7c3b7976 | 1152 | after(async function () { |
45f1bd72 JL |
1153 | MockSmtpServer.Instance.kill() |
1154 | ||
7c3b7976 | 1155 | await cleanupTests([ server, serverWithRegistrationDisabled ]) |
0e1dc3e7 C |
1156 | }) |
1157 | }) |