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