]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/users.ts
Cleanup tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / users.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
26d21b78 3import { omit } from 'lodash'
0e1dc3e7 4import 'mocha'
47564bbe 5import { join } from 'path'
187501f8 6import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
0e1dc3e7
C
7
8import {
26d21b78 9 createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
210feb6c 10 makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, flushAndRunServer, ServerInfo, setAccessTokensToServers,
e6921918 11 updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser
94565d52 12} from '../../../../shared/extra-utils'
9639bd17 13import {
14 checkBadCountPagination,
15 checkBadSortPagination,
16 checkBadStartPagination
94565d52
C
17} from '../../../../shared/extra-utils/requests/check-api-params'
18import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
187501f8 19import { VideoPrivacy } from '../../../../shared/models/videos'
94565d52 20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
187501f8 21import { expect } from 'chai'
1eddc9a7 22import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
0e1dc3e7
C
23
24describe('Test users API validators', function () {
25 const path = '/api/v1/users/'
26 let userId: number
27 let rootId: number
28 let videoId: number
29 let server: ServerInfo
30 let serverWithRegistrationDisabled: ServerInfo
31 let userAccessToken = ''
187501f8 32 let channelId: number
f8b8c36b
C
33 const user = {
34 username: 'user1',
35 password: 'my super password'
36 }
0e1dc3e7
C
37
38 // ---------------------------------------------------------------
39
40 before(async function () {
e212f887 41 this.timeout(30000)
0e1dc3e7 42
210feb6c
C
43 server = await flushAndRunServer(1)
44 serverWithRegistrationDisabled = await flushAndRunServer(2)
0e1dc3e7
C
45
46 await setAccessTokensToServers([ server ])
47
26d21b78 48 const videoQuota = 42000000
1eddc9a7
C
49 await createUser({
50 url: server.url,
51 accessToken: server.accessToken,
52 username: user.username,
53 password: user.password,
54 videoQuota: videoQuota
55 })
eec63bbc 56 userAccessToken = await userLogin(server, user)
26d21b78 57
187501f8
C
58 {
59 const res = await getMyUserInformation(server.url, server.accessToken)
60 channelId = res.body.videoChannels[ 0 ].id
61 }
62
63 {
64 const res = await uploadVideo(server.url, server.accessToken, {})
65 videoId = res.body.video.id
66 }
0e1dc3e7
C
67 })
68
69 describe('When listing users', function () {
70 it('Should fail with a bad start pagination', async function () {
26d21b78 71 await checkBadStartPagination(server.url, path, server.accessToken)
0e1dc3e7
C
72 })
73
74 it('Should fail with a bad count pagination', async function () {
26d21b78 75 await checkBadCountPagination(server.url, path, server.accessToken)
0e1dc3e7
C
76 })
77
78 it('Should fail with an incorrect sort', async function () {
26d21b78 79 await checkBadSortPagination(server.url, path, server.accessToken)
0e1dc3e7 80 })
86d13ec2
C
81
82 it('Should fail with a non authenticated user', async function () {
26d21b78
C
83 await makeGetRequest({
84 url: server.url,
85 path,
86 statusCodeExpected: 401
87 })
86d13ec2
C
88 })
89
90 it('Should fail with a non admin user', async function () {
26d21b78
C
91 await makeGetRequest({
92 url: server.url,
93 path,
94 token: userAccessToken,
95 statusCodeExpected: 403
96 })
86d13ec2 97 })
0e1dc3e7
C
98 })
99
100 describe('When adding a new user', function () {
26d21b78
C
101 const baseCorrectParams = {
102 username: 'user2',
103 email: 'test@example.com',
104 password: 'my super password',
105 videoQuota: -1,
bee0abff 106 videoQuotaDaily: -1,
1eddc9a7
C
107 role: UserRole.USER,
108 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
26d21b78
C
109 }
110
0e1dc3e7 111 it('Should fail with a too small username', async function () {
d0ce42c1 112 const fields = immutableAssign(baseCorrectParams, { username: '' })
0e1dc3e7
C
113
114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
115 })
116
117 it('Should fail with a too long username', async function () {
9f7a1953 118 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
0e1dc3e7
C
119
120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
121 })
122
563d032e 123 it('Should fail with a not lowercase username', async function () {
26d21b78 124 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
563d032e
C
125
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 })
128
0e1dc3e7 129 it('Should fail with an incorrect username', async function () {
26d21b78 130 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
0e1dc3e7
C
131
132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
133 })
134
135 it('Should fail with a missing email', async function () {
26d21b78 136 const fields = omit(baseCorrectParams, 'email')
0e1dc3e7
C
137
138 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
139 })
140
141 it('Should fail with an invalid email', async function () {
26d21b78 142 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
0e1dc3e7
C
143
144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
145 })
146
147 it('Should fail with a too small password', async function () {
26d21b78 148 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
0e1dc3e7
C
149
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
151 })
152
153 it('Should fail with a too long password', async function () {
26d21b78 154 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
0e1dc3e7
C
155
156 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
157 })
158
1eddc9a7
C
159 it('Should fail with invalid admin flags', async function () {
160 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
161
162 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
163 })
164
0e1dc3e7 165 it('Should fail with an non authenticated user', async function () {
26d21b78
C
166 await makePostBodyRequest({
167 url: server.url,
168 path,
169 token: 'super token',
170 fields: baseCorrectParams,
171 statusCodeExpected: 401
172 })
0e1dc3e7
C
173 })
174
175 it('Should fail if we add a user with the same username', async function () {
26d21b78 176 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
0e1dc3e7
C
177
178 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
179 })
180
181 it('Should fail if we add a user with the same email', async function () {
26d21b78 182 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
0e1dc3e7
C
183
184 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
185 })
186
77a5501f 187 it('Should fail without a videoQuota', async function () {
26d21b78 188 const fields = omit(baseCorrectParams, 'videoQuota')
77a5501f
C
189
190 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
191 })
192
bee0abff
FA
193 it('Should fail without a videoQuotaDaily', async function () {
194 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
195
196 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
197 })
198
77a5501f 199 it('Should fail with an invalid videoQuota', async function () {
26d21b78 200 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
757f0da3
C
201
202 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
203 })
204
bee0abff
FA
205 it('Should fail with an invalid videoQuotaDaily', async function () {
206 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
207
208 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
209 })
210
757f0da3 211 it('Should fail without a user role', async function () {
26d21b78 212 const fields = omit(baseCorrectParams, 'role')
757f0da3
C
213
214 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
215 })
216
217 it('Should fail with an invalid user role', async function () {
26d21b78 218 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
77a5501f
C
219
220 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
221 })
222
2ef6a063
C
223 it('Should fail with a "peertube" username', async function () {
224 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
225
226 await makePostBodyRequest({
227 url: server.url,
228 path,
229 token: server.accessToken,
230 fields,
231 statusCodeExpected: 409
232 })
233 })
234
0e1dc3e7 235 it('Should succeed with the correct params', async function () {
26d21b78
C
236 await makePostBodyRequest({
237 url: server.url,
238 path,
239 token: server.accessToken,
240 fields: baseCorrectParams,
f05a1c30 241 statusCodeExpected: 200
26d21b78 242 })
0e1dc3e7
C
243 })
244
245 it('Should fail with a non admin user', async function () {
26d21b78 246 const user = {
0e1dc3e7 247 username: 'user1',
0e1dc3e7
C
248 password: 'my super password'
249 }
26d21b78 250 userAccessToken = await userLogin(server, user)
0e1dc3e7 251
0e1dc3e7
C
252 const fields = {
253 username: 'user3',
254 email: 'test@example.com',
77a5501f
C
255 password: 'my super password',
256 videoQuota: 42000000
0e1dc3e7
C
257 }
258 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
259 })
260 })
261
77a5501f
C
262 describe('When updating my account', function () {
263 it('Should fail with an invalid email attribute', async function () {
264 const fields = {
265 email: 'blabla'
266 }
0e1dc3e7 267
77a5501f 268 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
0e1dc3e7
C
269 })
270
271 it('Should fail with a too small password', async function () {
272 const fields = {
a890d1e0 273 currentPassword: 'my super password',
0e1dc3e7
C
274 password: 'bla'
275 }
276
77a5501f 277 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
0e1dc3e7
C
278 })
279
280 it('Should fail with a too long password', async function () {
281 const fields = {
a890d1e0 282 currentPassword: 'my super password',
26d21b78 283 password: 'super'.repeat(61)
0e1dc3e7
C
284 }
285
77a5501f 286 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
0e1dc3e7
C
287 })
288
a890d1e0
C
289 it('Should fail without the current password', async function () {
290 const fields = {
291 currentPassword: 'my super password',
292 password: 'super'.repeat(61)
293 }
294
295 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
296 })
297
298 it('Should fail with an invalid current password', async function () {
299 const fields = {
300 currentPassword: 'my super password fail',
301 password: 'super'.repeat(61)
302 }
303
304 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
305 })
306
0883b324 307 it('Should fail with an invalid NSFW policy attribute', async function () {
0e1dc3e7 308 const fields = {
0883b324 309 nsfwPolicy: 'hello'
0e1dc3e7
C
310 }
311
77a5501f 312 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
0e1dc3e7
C
313 })
314
7efe153b
AL
315 it('Should fail with an invalid autoPlayVideo attribute', async function () {
316 const fields = {
317 autoPlayVideo: -1
318 }
319
320 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
321 })
322
8b9a525a
C
323 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
324 const fields = {
325 videosHistoryEnabled: -1
326 }
327
328 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
329 })
330
0e1dc3e7
C
331 it('Should fail with an non authenticated user', async function () {
332 const fields = {
a890d1e0 333 currentPassword: 'my super password',
0e1dc3e7
C
334 password: 'my super password'
335 }
336
77a5501f 337 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
0e1dc3e7
C
338 })
339
2422c46b
C
340 it('Should fail with a too long description', async function () {
341 const fields = {
d23e6a1c 342 description: 'super'.repeat(201)
2422c46b
C
343 }
344
345 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
346 })
347
a890d1e0 348 it('Should succeed to change password with the correct params', async function () {
0e1dc3e7 349 const fields = {
a890d1e0 350 currentPassword: 'my super password',
0e1dc3e7 351 password: 'my super password',
0883b324 352 nsfwPolicy: 'blur',
7efe153b 353 autoPlayVideo: false,
77a5501f 354 email: 'super_email@example.com'
0e1dc3e7
C
355 }
356
77a5501f
C
357 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
358 })
a890d1e0
C
359
360 it('Should succeed without password change with the correct params', async function () {
361 const fields = {
362 nsfwPolicy: 'blur',
363 autoPlayVideo: false,
364 email: 'super_email@example.com'
365 }
366
367 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
368 })
77a5501f
C
369 })
370
c5911fd3
C
371 describe('When updating my avatar', function () {
372 it('Should fail without an incorrect input file', async function () {
373 const fields = {}
374 const attaches = {
99d10301 375 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
c5911fd3 376 }
ac81d1a0 377 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
c5911fd3
C
378 })
379
01de67b9
C
380 it('Should fail with a big file', async function () {
381 const fields = {}
382 const attaches = {
99d10301 383 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
01de67b9 384 }
ac81d1a0 385 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
01de67b9
C
386 })
387
4bbfc6c6
C
388 it('Should fail with an unauthenticated user', async function () {
389 const fields = {}
390 const attaches = {
391 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
392 }
393 await makeUploadRequest({
394 url: server.url,
395 path: path + '/me/avatar/pick',
396 fields,
397 attaches,
398 statusCodeExpected: 401
399 })
400 })
401
c5911fd3
C
402 it('Should succeed with the correct params', async function () {
403 const fields = {}
404 const attaches = {
99d10301 405 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
c5911fd3 406 }
ac81d1a0 407 await makeUploadRequest({
47564bbe
C
408 url: server.url,
409 path: path + '/me/avatar/pick',
410 token: server.accessToken,
411 fields,
412 attaches,
413 statusCodeExpected: 200
414 })
c5911fd3
C
415 })
416 })
417
94ff4c23
C
418 describe('When getting a user', function () {
419 before(async function () {
420 const res = await getUsersList(server.url, server.accessToken)
421
422 userId = res.body.data[1].id
423 })
424
425 it('Should fail with an non authenticated user', async function () {
426 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
427 })
428
429 it('Should fail with a non admin user', async function () {
430 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
431 })
432
433 it('Should succeed with the correct params', async function () {
434 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
435 })
436 })
437
77a5501f
C
438 describe('When updating a user', function () {
439
440 before(async function () {
86d13ec2 441 const res = await getUsersList(server.url, server.accessToken)
77a5501f
C
442
443 userId = res.body.data[1].id
444 rootId = res.body.data[2].id
445 })
446
447 it('Should fail with an invalid email attribute', async function () {
448 const fields = {
449 email: 'blabla'
450 }
451
452 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
453 })
454
fc2ec87a
JM
455 it('Should fail with an invalid emailVerified attribute', async function () {
456 const fields = {
457 emailVerified: 'yes'
458 }
459
460 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
461 })
462
77a5501f
C
463 it('Should fail with an invalid videoQuota attribute', async function () {
464 const fields = {
465 videoQuota: -90
466 }
467
468 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
469 })
470
757f0da3
C
471 it('Should fail with an invalid user role attribute', async function () {
472 const fields = {
473 role: 54878
474 }
475
476 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
477 })
478
b426edd4
C
479 it('Should fail with a too small password', async function () {
480 const fields = {
481 currentPassword: 'my super password',
482 password: 'bla'
483 }
484
485 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
486 })
487
488 it('Should fail with a too long password', async function () {
489 const fields = {
490 currentPassword: 'my super password',
491 password: 'super'.repeat(61)
492 }
493
494 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
495 })
496
77a5501f
C
497 it('Should fail with an non authenticated user', async function () {
498 const fields = {
499 videoQuota: 42
500 }
501
502 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
503 })
504
f8b8c36b
C
505 it('Should fail when updating root role', async function () {
506 const fields = {
507 role: UserRole.MODERATOR
508 }
509
510 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
1eddc9a7
C
511 })
512
513 it('Should fail with invalid admin flags', async function () {
514 const fields = { adminFlags: 'toto' }
515
516 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
f8b8c36b
C
517 })
518
77a5501f
C
519 it('Should succeed with the correct params', async function () {
520 const fields = {
521 email: 'email@example.com',
fc2ec87a 522 emailVerified: true,
757f0da3 523 videoQuota: 42,
2f1548fd 524 role: UserRole.USER
77a5501f
C
525 }
526
527 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
0e1dc3e7
C
528 })
529 })
530
531 describe('When getting my information', function () {
532 it('Should fail with a non authenticated user', async function () {
26d21b78 533 await getMyUserInformation(server.url, 'fake_token', 401)
0e1dc3e7
C
534 })
535
536 it('Should success with the correct parameters', async function () {
26d21b78 537 await getMyUserInformation(server.url, userAccessToken)
0e1dc3e7
C
538 })
539 })
540
541 describe('When getting my video rating', function () {
542 it('Should fail with a non authenticated user', async function () {
26d21b78 543 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
0e1dc3e7
C
544 })
545
546 it('Should fail with an incorrect video uuid', async function () {
26d21b78 547 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
0e1dc3e7
C
548 })
549
550 it('Should fail with an unknown video', async function () {
26d21b78 551 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
0e1dc3e7
C
552 })
553
26d21b78
C
554 it('Should succeed with the correct parameters', async function () {
555 await getMyUserVideoRating(server.url, server.accessToken, videoId)
0e1dc3e7
C
556 })
557 })
558
22834691
C
559 describe('When retrieving my global ratings', function () {
560 const path = '/api/v1/accounts/user1/ratings'
561
562 it('Should fail with a bad start pagination', async function () {
563 await checkBadStartPagination(server.url, path, userAccessToken)
564 })
565
566 it('Should fail with a bad count pagination', async function () {
567 await checkBadCountPagination(server.url, path, userAccessToken)
568 })
569
570 it('Should fail with an incorrect sort', async function () {
571 await checkBadSortPagination(server.url, path, userAccessToken)
572 })
573
574 it('Should fail with a unauthenticated user', async function () {
575 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
576 })
577
578 it('Should fail with a another user', async function () {
579 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
580 })
581
582 it('Should fail with a bad type', async function () {
583 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
584 })
585
586 it('Should succeed with the correct params', async function () {
587 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
588 })
589 })
590
e6921918 591 describe('When blocking/unblocking/removing user', function () {
0e1dc3e7 592 it('Should fail with an incorrect id', async function () {
26d21b78 593 await removeUser(server.url, 'blabla', server.accessToken, 400)
e6921918
C
594 await blockUser(server.url, 'blabla', server.accessToken, 400)
595 await unblockUser(server.url, 'blabla', server.accessToken, 400)
0e1dc3e7
C
596 })
597
598 it('Should fail with the root user', async function () {
26d21b78 599 await removeUser(server.url, rootId, server.accessToken, 400)
e6921918
C
600 await blockUser(server.url, rootId, server.accessToken, 400)
601 await unblockUser(server.url, rootId, server.accessToken, 400)
0e1dc3e7
C
602 })
603
604 it('Should return 404 with a non existing id', async function () {
26d21b78 605 await removeUser(server.url, 4545454, server.accessToken, 404)
e6921918
C
606 await blockUser(server.url, 4545454, server.accessToken, 404)
607 await unblockUser(server.url, 4545454, server.accessToken, 404)
608 })
609
610 it('Should fail with a non admin user', async function () {
611 await removeUser(server.url, userId, userAccessToken, 403)
612 await blockUser(server.url, userId, userAccessToken, 403)
613 await unblockUser(server.url, userId, userAccessToken, 403)
0e1dc3e7
C
614 })
615 })
616
92b9d60c
C
617 describe('When deleting our account', function () {
618 it('Should fail with with the root account', async function () {
619 await deleteMe(server.url, server.accessToken, 400)
620 })
621 })
622
0e1dc3e7
C
623 describe('When register a new user', function () {
624 const registrationPath = path + '/register'
26d21b78
C
625 const baseCorrectParams = {
626 username: 'user3',
627 email: 'test3@example.com',
628 password: 'my super password'
629 }
0e1dc3e7
C
630
631 it('Should fail with a too small username', async function () {
d0ce42c1 632 const fields = immutableAssign(baseCorrectParams, { username: '' })
0e1dc3e7
C
633
634 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
635 })
636
637 it('Should fail with a too long username', async function () {
9f7a1953 638 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
0e1dc3e7
C
639
640 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
641 })
642
643 it('Should fail with an incorrect username', async function () {
26d21b78 644 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
0e1dc3e7
C
645
646 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
647 })
648
649 it('Should fail with a missing email', async function () {
26d21b78 650 const fields = omit(baseCorrectParams, 'email')
0e1dc3e7
C
651
652 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
653 })
654
655 it('Should fail with an invalid email', async function () {
26d21b78 656 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
0e1dc3e7
C
657
658 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
659 })
660
661 it('Should fail with a too small password', async function () {
26d21b78 662 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
0e1dc3e7
C
663
664 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
665 })
666
667 it('Should fail with a too long password', async function () {
26d21b78 668 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
0e1dc3e7
C
669
670 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
671 })
672
673 it('Should fail if we register a user with the same username', async function () {
26d21b78 674 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
0e1dc3e7 675
26d21b78
C
676 await makePostBodyRequest({
677 url: server.url,
678 path: registrationPath,
679 token: server.accessToken,
680 fields,
681 statusCodeExpected: 409
682 })
0e1dc3e7
C
683 })
684
2ef6a063
C
685 it('Should fail with a "peertube" username', async function () {
686 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
687
688 await makePostBodyRequest({
689 url: server.url,
690 path: registrationPath,
691 token: server.accessToken,
692 fields,
693 statusCodeExpected: 409
694 })
695 })
696
0e1dc3e7 697 it('Should fail if we register a user with the same email', async function () {
26d21b78 698 const fields = immutableAssign(baseCorrectParams, { email: 'admin1@example.com' })
0e1dc3e7 699
26d21b78
C
700 await makePostBodyRequest({
701 url: server.url,
702 path: registrationPath,
703 token: server.accessToken,
704 fields,
705 statusCodeExpected: 409
706 })
0e1dc3e7
C
707 })
708
709 it('Should succeed with the correct params', async function () {
26d21b78
C
710 await makePostBodyRequest({
711 url: server.url,
712 path: registrationPath,
713 token: server.accessToken,
714 fields: baseCorrectParams,
715 statusCodeExpected: 204
716 })
0e1dc3e7
C
717 })
718
719 it('Should fail on a server with registration disabled', async function () {
720 const fields = {
721 username: 'user4',
722 email: 'test4@example.com',
723 password: 'my super password 4'
724 }
725
726 await makePostBodyRequest({
727 url: serverWithRegistrationDisabled.url,
728 path: registrationPath,
729 token: serverWithRegistrationDisabled.accessToken,
730 fields,
731 statusCodeExpected: 403
732 })
733 })
734 })
735
736 describe('When registering multiple users on a server with users limit', function () {
737 it('Should fail when after 3 registrations', async function () {
738 await registerUser(server.url, 'user42', 'super password', 403)
739 })
740 })
741
77a5501f 742 describe('When having a video quota', function () {
bee0abff 743 it('Should fail with a user having too many videos', async function () {
26d21b78
C
744 await updateUser({
745 url: server.url,
746 userId: rootId,
747 accessToken: server.accessToken,
77a5501f 748 videoQuota: 42
26d21b78 749 })
77a5501f 750
26d21b78 751 await uploadVideo(server.url, server.accessToken, {}, 403)
77a5501f
C
752 })
753
bee0abff 754 it('Should fail with a registered user having too many videos', async function () {
adc236fe 755 this.timeout(30000)
77a5501f 756
26d21b78 757 const user = {
77a5501f 758 username: 'user3',
77a5501f
C
759 password: 'my super password'
760 }
26d21b78 761 userAccessToken = await userLogin(server, user)
77a5501f
C
762
763 const videoAttributes = { fixture: 'video_short2.webm' }
764 await uploadVideo(server.url, userAccessToken, videoAttributes)
765 await uploadVideo(server.url, userAccessToken, videoAttributes)
766 await uploadVideo(server.url, userAccessToken, videoAttributes)
767 await uploadVideo(server.url, userAccessToken, videoAttributes)
768 await uploadVideo(server.url, userAccessToken, videoAttributes)
769 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
770 })
187501f8
C
771
772 it('Should fail to import with HTTP/Torrent/magnet', async function () {
a031ab0b 773 this.timeout(120000)
187501f8
C
774
775 const baseAttributes = {
776 channelId: 1,
777 privacy: VideoPrivacy.PUBLIC
778 }
779 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
780 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
3e17515e 781 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' }))
187501f8
C
782
783 await waitJobs([ server ])
784
785 const res = await getMyVideoImports(server.url, server.accessToken)
786
787 expect(res.body.total).to.equal(3)
788 const videoImports: VideoImport[] = res.body.data
789 expect(videoImports).to.have.lengthOf(3)
790
791 for (const videoImport of videoImports) {
792 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
793 expect(videoImport.error).not.to.be.undefined
794 expect(videoImport.error).to.contain('user video quota is exceeded')
795 }
796 })
77a5501f
C
797 })
798
bee0abff
FA
799 describe('When having a daily video quota', function () {
800 it('Should fail with a user having too many videos', async function () {
801 await updateUser({
802 url: server.url,
803 userId: rootId,
804 accessToken: server.accessToken,
805 videoQuotaDaily: 42
806 })
807
808 await uploadVideo(server.url, server.accessToken, {}, 403)
809 })
810 })
811
812 describe('When having an absolute and daily video quota', function () {
813 it('Should fail if exceeding total quota', async function () {
814 await updateUser({
815 url: server.url,
816 userId: rootId,
817 accessToken: server.accessToken,
818 videoQuota: 42,
819 videoQuotaDaily: 1024 * 1024 * 1024
820 })
821
822 await uploadVideo(server.url, server.accessToken, {}, 403)
823 })
824
825 it('Should fail if exceeding daily quota', async function () {
826 await updateUser({
827 url: server.url,
828 userId: rootId,
829 accessToken: server.accessToken,
830 videoQuota: 1024 * 1024 * 1024,
831 videoQuotaDaily: 42
832 })
833
834 await uploadVideo(server.url, server.accessToken, {}, 403)
835 })
836 })
837
f076daa7
C
838 describe('When asking a password reset', function () {
839 const path = '/api/v1/users/ask-reset-password'
840
841 it('Should fail with a missing email', async function () {
842 const fields = {}
843
844 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
845 })
846
847 it('Should fail with an invalid email', async function () {
848 const fields = { email: 'hello' }
849
850 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
851 })
852
853 it('Should success with the correct params', async function () {
854 const fields = { email: 'admin@example.com' }
855
856 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
857 })
858 })
859
d9eaee39
JM
860 describe('When asking for an account verification email', function () {
861 const path = '/api/v1/users/ask-send-verify-email'
862
863 it('Should fail with a missing email', async function () {
864 const fields = {}
865
866 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
867 })
868
869 it('Should fail with an invalid email', async function () {
870 const fields = { email: 'hello' }
871
872 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
873 })
874
875 it('Should succeed with the correct params', async function () {
876 const fields = { email: 'admin@example.com' }
877
878 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
879 })
880 })
881
210feb6c 882 after(function () {
0e1dc3e7 883 killallServers([ server, serverWithRegistrationDisabled ])
0e1dc3e7
C
884 })
885})