diff options
Diffstat (limited to 'server/tests/api/check-params/users.ts')
-rw-r--r-- | server/tests/api/check-params/users.ts | 243 |
1 files changed, 108 insertions, 135 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 54baeebe1..801131918 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -2,32 +2,22 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { omit } from 'lodash' | 4 | import { omit } from 'lodash' |
5 | import { User, UserRole, VideoCreateResult } from '../../../../shared' | 5 | import { UserRole, VideoCreateResult } from '../../../../shared' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
7 | import { | 7 | import { |
8 | blockUser, | ||
9 | buildAbsoluteFixturePath, | 8 | buildAbsoluteFixturePath, |
10 | cleanupTests, | 9 | cleanupTests, |
11 | createUser, | ||
12 | deleteMe, | ||
13 | flushAndRunServer, | 10 | flushAndRunServer, |
14 | getMyUserInformation, | ||
15 | getMyUserVideoRating, | ||
16 | getUserScopedTokens, | ||
17 | getUsersList, | ||
18 | killallServers, | 11 | killallServers, |
19 | makeGetRequest, | 12 | makeGetRequest, |
20 | makePostBodyRequest, | 13 | makePostBodyRequest, |
21 | makePutBodyRequest, | 14 | makePutBodyRequest, |
22 | makeUploadRequest, | 15 | makeUploadRequest, |
23 | registerUser, | ||
24 | removeUser, | ||
25 | renewUserScopedTokens, | ||
26 | reRunServer, | 16 | reRunServer, |
27 | ServerInfo, | 17 | ServerInfo, |
28 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
29 | unblockUser, | 19 | uploadVideo, |
30 | uploadVideo | 20 | UsersCommand |
31 | } from '../../../../shared/extra-utils' | 21 | } from '../../../../shared/extra-utils' |
32 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' | 22 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' |
33 | import { | 23 | import { |
@@ -45,8 +35,8 @@ describe('Test users API validators', function () { | |||
45 | let video: VideoCreateResult | 35 | let video: VideoCreateResult |
46 | let server: ServerInfo | 36 | let server: ServerInfo |
47 | let serverWithRegistrationDisabled: ServerInfo | 37 | let serverWithRegistrationDisabled: ServerInfo |
48 | let userAccessToken = '' | 38 | let userToken = '' |
49 | let moderatorAccessToken = '' | 39 | let moderatorToken = '' |
50 | let emailPort: number | 40 | let emailPort: number |
51 | let overrideConfig: Object | 41 | let overrideConfig: Object |
52 | 42 | ||
@@ -73,52 +63,20 @@ describe('Test users API validators', function () { | |||
73 | } | 63 | } |
74 | 64 | ||
75 | { | 65 | { |
76 | const user = { | 66 | const user = { username: 'user1' } |
77 | username: 'user1', | 67 | await server.usersCommand.create({ ...user }) |
78 | password: 'my super password' | 68 | userToken = await server.loginCommand.getAccessToken(user) |
79 | } | ||
80 | |||
81 | const videoQuota = 42000000 | ||
82 | await createUser({ | ||
83 | url: server.url, | ||
84 | accessToken: server.accessToken, | ||
85 | username: user.username, | ||
86 | password: user.password, | ||
87 | videoQuota: videoQuota | ||
88 | }) | ||
89 | userAccessToken = await server.loginCommand.getAccessToken(user) | ||
90 | } | 69 | } |
91 | 70 | ||
92 | { | 71 | { |
93 | const moderator = { | 72 | const moderator = { username: 'moderator1' } |
94 | username: 'moderator1', | 73 | await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR }) |
95 | password: 'super password' | 74 | moderatorToken = await server.loginCommand.getAccessToken(moderator) |
96 | } | ||
97 | |||
98 | await createUser({ | ||
99 | url: server.url, | ||
100 | accessToken: server.accessToken, | ||
101 | username: moderator.username, | ||
102 | password: moderator.password, | ||
103 | role: UserRole.MODERATOR | ||
104 | }) | ||
105 | |||
106 | moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) | ||
107 | } | 75 | } |
108 | 76 | ||
109 | { | 77 | { |
110 | const moderator = { | 78 | const moderator = { username: 'moderator2' } |
111 | username: 'moderator2', | 79 | await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR }) |
112 | password: 'super password' | ||
113 | } | ||
114 | |||
115 | await createUser({ | ||
116 | url: server.url, | ||
117 | accessToken: server.accessToken, | ||
118 | username: moderator.username, | ||
119 | password: moderator.password, | ||
120 | role: UserRole.MODERATOR | ||
121 | }) | ||
122 | } | 80 | } |
123 | 81 | ||
124 | { | 82 | { |
@@ -127,12 +85,10 @@ describe('Test users API validators', function () { | |||
127 | } | 85 | } |
128 | 86 | ||
129 | { | 87 | { |
130 | const res = await getUsersList(server.url, server.accessToken) | 88 | const { data } = await server.usersCommand.list() |
131 | const users: User[] = res.body.data | 89 | userId = data.find(u => u.username === 'user1').id |
132 | 90 | rootId = data.find(u => u.username === 'root').id | |
133 | userId = users.find(u => u.username === 'user1').id | 91 | moderatorId = data.find(u => u.username === 'moderator2').id |
134 | rootId = users.find(u => u.username === 'root').id | ||
135 | moderatorId = users.find(u => u.username === 'moderator2').id | ||
136 | } | 92 | } |
137 | }) | 93 | }) |
138 | 94 | ||
@@ -161,7 +117,7 @@ describe('Test users API validators', function () { | |||
161 | await makeGetRequest({ | 117 | await makeGetRequest({ |
162 | url: server.url, | 118 | url: server.url, |
163 | path, | 119 | path, |
164 | token: userAccessToken, | 120 | token: userToken, |
165 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | 121 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
166 | }) | 122 | }) |
167 | }) | 123 | }) |
@@ -359,7 +315,7 @@ describe('Test users API validators', function () { | |||
359 | await makePostBodyRequest({ | 315 | await makePostBodyRequest({ |
360 | url: server.url, | 316 | url: server.url, |
361 | path, | 317 | path, |
362 | token: moderatorAccessToken, | 318 | token: moderatorToken, |
363 | fields, | 319 | fields, |
364 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | 320 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
365 | }) | 321 | }) |
@@ -372,7 +328,7 @@ describe('Test users API validators', function () { | |||
372 | await makePostBodyRequest({ | 328 | await makePostBodyRequest({ |
373 | url: server.url, | 329 | url: server.url, |
374 | path, | 330 | path, |
375 | token: moderatorAccessToken, | 331 | token: moderatorToken, |
376 | fields, | 332 | fields, |
377 | statusCodeExpected: HttpStatusCode.OK_200 | 333 | statusCodeExpected: HttpStatusCode.OK_200 |
378 | }) | 334 | }) |
@@ -389,11 +345,8 @@ describe('Test users API validators', function () { | |||
389 | }) | 345 | }) |
390 | 346 | ||
391 | it('Should fail with a non admin user', async function () { | 347 | it('Should fail with a non admin user', async function () { |
392 | const user = { | 348 | const user = { username: 'user1' } |
393 | username: 'user1', | 349 | userToken = await server.loginCommand.getAccessToken(user) |
394 | password: 'my super password' | ||
395 | } | ||
396 | userAccessToken = await server.loginCommand.getAccessToken(user) | ||
397 | 350 | ||
398 | const fields = { | 351 | const fields = { |
399 | username: 'user3', | 352 | username: 'user3', |
@@ -401,11 +354,12 @@ describe('Test users API validators', function () { | |||
401 | password: 'my super password', | 354 | password: 'my super password', |
402 | videoQuota: 42000000 | 355 | videoQuota: 42000000 |
403 | } | 356 | } |
404 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) | 357 | await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) |
405 | }) | 358 | }) |
406 | }) | 359 | }) |
407 | 360 | ||
408 | describe('When updating my account', function () { | 361 | describe('When updating my account', function () { |
362 | |||
409 | it('Should fail with an invalid email attribute', async function () { | 363 | it('Should fail with an invalid email attribute', async function () { |
410 | const fields = { | 364 | const fields = { |
411 | email: 'blabla' | 365 | email: 'blabla' |
@@ -416,29 +370,29 @@ describe('Test users API validators', function () { | |||
416 | 370 | ||
417 | it('Should fail with a too small password', async function () { | 371 | it('Should fail with a too small password', async function () { |
418 | const fields = { | 372 | const fields = { |
419 | currentPassword: 'my super password', | 373 | currentPassword: 'password', |
420 | password: 'bla' | 374 | password: 'bla' |
421 | } | 375 | } |
422 | 376 | ||
423 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 377 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
424 | }) | 378 | }) |
425 | 379 | ||
426 | it('Should fail with a too long password', async function () { | 380 | it('Should fail with a too long password', async function () { |
427 | const fields = { | 381 | const fields = { |
428 | currentPassword: 'my super password', | 382 | currentPassword: 'password', |
429 | password: 'super'.repeat(61) | 383 | password: 'super'.repeat(61) |
430 | } | 384 | } |
431 | 385 | ||
432 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 386 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
433 | }) | 387 | }) |
434 | 388 | ||
435 | it('Should fail without the current password', async function () { | 389 | it('Should fail without the current password', async function () { |
436 | const fields = { | 390 | const fields = { |
437 | currentPassword: 'my super password', | 391 | currentPassword: 'password', |
438 | password: 'super'.repeat(61) | 392 | password: 'super'.repeat(61) |
439 | } | 393 | } |
440 | 394 | ||
441 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 395 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
442 | }) | 396 | }) |
443 | 397 | ||
444 | it('Should fail with an invalid current password', async function () { | 398 | it('Should fail with an invalid current password', async function () { |
@@ -450,7 +404,7 @@ describe('Test users API validators', function () { | |||
450 | await makePutBodyRequest({ | 404 | await makePutBodyRequest({ |
451 | url: server.url, | 405 | url: server.url, |
452 | path: path + 'me', | 406 | path: path + 'me', |
453 | token: userAccessToken, | 407 | token: userToken, |
454 | fields, | 408 | fields, |
455 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | 409 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
456 | }) | 410 | }) |
@@ -461,7 +415,7 @@ describe('Test users API validators', function () { | |||
461 | nsfwPolicy: 'hello' | 415 | nsfwPolicy: 'hello' |
462 | } | 416 | } |
463 | 417 | ||
464 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 418 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
465 | }) | 419 | }) |
466 | 420 | ||
467 | it('Should fail with an invalid autoPlayVideo attribute', async function () { | 421 | it('Should fail with an invalid autoPlayVideo attribute', async function () { |
@@ -469,7 +423,7 @@ describe('Test users API validators', function () { | |||
469 | autoPlayVideo: -1 | 423 | autoPlayVideo: -1 |
470 | } | 424 | } |
471 | 425 | ||
472 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 426 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
473 | }) | 427 | }) |
474 | 428 | ||
475 | it('Should fail with an invalid autoPlayNextVideo attribute', async function () { | 429 | it('Should fail with an invalid autoPlayNextVideo attribute', async function () { |
@@ -477,7 +431,7 @@ describe('Test users API validators', function () { | |||
477 | autoPlayNextVideo: -1 | 431 | autoPlayNextVideo: -1 |
478 | } | 432 | } |
479 | 433 | ||
480 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 434 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
481 | }) | 435 | }) |
482 | 436 | ||
483 | it('Should fail with an invalid videosHistoryEnabled attribute', async function () { | 437 | it('Should fail with an invalid videosHistoryEnabled attribute', async function () { |
@@ -485,12 +439,12 @@ describe('Test users API validators', function () { | |||
485 | videosHistoryEnabled: -1 | 439 | videosHistoryEnabled: -1 |
486 | } | 440 | } |
487 | 441 | ||
488 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 442 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
489 | }) | 443 | }) |
490 | 444 | ||
491 | it('Should fail with an non authenticated user', async function () { | 445 | it('Should fail with an non authenticated user', async function () { |
492 | const fields = { | 446 | const fields = { |
493 | currentPassword: 'my super password', | 447 | currentPassword: 'password', |
494 | password: 'my super password' | 448 | password: 'my super password' |
495 | } | 449 | } |
496 | 450 | ||
@@ -508,7 +462,7 @@ describe('Test users API validators', function () { | |||
508 | description: 'super'.repeat(201) | 462 | description: 'super'.repeat(201) |
509 | } | 463 | } |
510 | 464 | ||
511 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 465 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
512 | }) | 466 | }) |
513 | 467 | ||
514 | it('Should fail with an invalid videoLanguages attribute', async function () { | 468 | it('Should fail with an invalid videoLanguages attribute', async function () { |
@@ -517,7 +471,7 @@ describe('Test users API validators', function () { | |||
517 | videoLanguages: 'toto' | 471 | videoLanguages: 'toto' |
518 | } | 472 | } |
519 | 473 | ||
520 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 474 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
521 | } | 475 | } |
522 | 476 | ||
523 | { | 477 | { |
@@ -530,18 +484,18 @@ describe('Test users API validators', function () { | |||
530 | videoLanguages: languages | 484 | videoLanguages: languages |
531 | } | 485 | } |
532 | 486 | ||
533 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 487 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
534 | } | 488 | } |
535 | }) | 489 | }) |
536 | 490 | ||
537 | it('Should fail with an invalid theme', async function () { | 491 | it('Should fail with an invalid theme', async function () { |
538 | const fields = { theme: 'invalid' } | 492 | const fields = { theme: 'invalid' } |
539 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 493 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
540 | }) | 494 | }) |
541 | 495 | ||
542 | it('Should fail with an unknown theme', async function () { | 496 | it('Should fail with an unknown theme', async function () { |
543 | const fields = { theme: 'peertube-theme-unknown' } | 497 | const fields = { theme: 'peertube-theme-unknown' } |
544 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 498 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
545 | }) | 499 | }) |
546 | 500 | ||
547 | it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { | 501 | it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { |
@@ -549,7 +503,7 @@ describe('Test users API validators', function () { | |||
549 | noInstanceConfigWarningModal: -1 | 503 | noInstanceConfigWarningModal: -1 |
550 | } | 504 | } |
551 | 505 | ||
552 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 506 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
553 | }) | 507 | }) |
554 | 508 | ||
555 | it('Should fail with an invalid noWelcomeModal attribute', async function () { | 509 | it('Should fail with an invalid noWelcomeModal attribute', async function () { |
@@ -557,12 +511,12 @@ describe('Test users API validators', function () { | |||
557 | noWelcomeModal: -1 | 511 | noWelcomeModal: -1 |
558 | } | 512 | } |
559 | 513 | ||
560 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | 514 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) |
561 | }) | 515 | }) |
562 | 516 | ||
563 | it('Should succeed to change password with the correct params', async function () { | 517 | it('Should succeed to change password with the correct params', async function () { |
564 | const fields = { | 518 | const fields = { |
565 | currentPassword: 'my super password', | 519 | currentPassword: 'password', |
566 | password: 'my super password', | 520 | password: 'my super password', |
567 | nsfwPolicy: 'blur', | 521 | nsfwPolicy: 'blur', |
568 | autoPlayVideo: false, | 522 | autoPlayVideo: false, |
@@ -575,7 +529,7 @@ describe('Test users API validators', function () { | |||
575 | await makePutBodyRequest({ | 529 | await makePutBodyRequest({ |
576 | url: server.url, | 530 | url: server.url, |
577 | path: path + 'me', | 531 | path: path + 'me', |
578 | token: userAccessToken, | 532 | token: userToken, |
579 | fields, | 533 | fields, |
580 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | 534 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
581 | }) | 535 | }) |
@@ -590,7 +544,7 @@ describe('Test users API validators', function () { | |||
590 | await makePutBodyRequest({ | 544 | await makePutBodyRequest({ |
591 | url: server.url, | 545 | url: server.url, |
592 | path: path + 'me', | 546 | path: path + 'me', |
593 | token: userAccessToken, | 547 | token: userToken, |
594 | fields, | 548 | fields, |
595 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | 549 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
596 | }) | 550 | }) |
@@ -647,28 +601,28 @@ describe('Test users API validators', function () { | |||
647 | describe('When managing my scoped tokens', function () { | 601 | describe('When managing my scoped tokens', function () { |
648 | 602 | ||
649 | it('Should fail to get my scoped tokens with an non authenticated user', async function () { | 603 | it('Should fail to get my scoped tokens with an non authenticated user', async function () { |
650 | await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) | 604 | await server.usersCommand.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
651 | }) | 605 | }) |
652 | 606 | ||
653 | it('Should fail to get my scoped tokens with a bad token', async function () { | 607 | it('Should fail to get my scoped tokens with a bad token', async function () { |
654 | await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) | 608 | await server.usersCommand.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
655 | 609 | ||
656 | }) | 610 | }) |
657 | 611 | ||
658 | it('Should succeed to get my scoped tokens', async function () { | 612 | it('Should succeed to get my scoped tokens', async function () { |
659 | await getUserScopedTokens(server.url, server.accessToken) | 613 | await server.usersCommand.getMyScopedTokens() |
660 | }) | 614 | }) |
661 | 615 | ||
662 | it('Should fail to renew my scoped tokens with an non authenticated user', async function () { | 616 | it('Should fail to renew my scoped tokens with an non authenticated user', async function () { |
663 | await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) | 617 | await server.usersCommand.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
664 | }) | 618 | }) |
665 | 619 | ||
666 | it('Should fail to renew my scoped tokens with a bad token', async function () { | 620 | it('Should fail to renew my scoped tokens with a bad token', async function () { |
667 | await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) | 621 | await server.usersCommand.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
668 | }) | 622 | }) |
669 | 623 | ||
670 | it('Should succeed to renew my scoped tokens', async function () { | 624 | it('Should succeed to renew my scoped tokens', async function () { |
671 | await renewUserScopedTokens(server.url, server.accessToken) | 625 | await server.usersCommand.renewMyScopedTokens() |
672 | }) | 626 | }) |
673 | }) | 627 | }) |
674 | 628 | ||
@@ -684,7 +638,7 @@ describe('Test users API validators', function () { | |||
684 | }) | 638 | }) |
685 | 639 | ||
686 | it('Should fail with a non admin user', async function () { | 640 | it('Should fail with a non admin user', async function () { |
687 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) | 641 | await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) |
688 | }) | 642 | }) |
689 | 643 | ||
690 | it('Should succeed with the correct params', async function () { | 644 | it('Should succeed with the correct params', async function () { |
@@ -728,7 +682,7 @@ describe('Test users API validators', function () { | |||
728 | 682 | ||
729 | it('Should fail with a too small password', async function () { | 683 | it('Should fail with a too small password', async function () { |
730 | const fields = { | 684 | const fields = { |
731 | currentPassword: 'my super password', | 685 | currentPassword: 'password', |
732 | password: 'bla' | 686 | password: 'bla' |
733 | } | 687 | } |
734 | 688 | ||
@@ -737,7 +691,7 @@ describe('Test users API validators', function () { | |||
737 | 691 | ||
738 | it('Should fail with a too long password', async function () { | 692 | it('Should fail with a too long password', async function () { |
739 | const fields = { | 693 | const fields = { |
740 | currentPassword: 'my super password', | 694 | currentPassword: 'password', |
741 | password: 'super'.repeat(61) | 695 | password: 'super'.repeat(61) |
742 | } | 696 | } |
743 | 697 | ||
@@ -780,7 +734,7 @@ describe('Test users API validators', function () { | |||
780 | await makePutBodyRequest({ | 734 | await makePutBodyRequest({ |
781 | url: server.url, | 735 | url: server.url, |
782 | path: path + moderatorId, | 736 | path: path + moderatorId, |
783 | token: moderatorAccessToken, | 737 | token: moderatorToken, |
784 | fields, | 738 | fields, |
785 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | 739 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
786 | }) | 740 | }) |
@@ -794,7 +748,7 @@ describe('Test users API validators', function () { | |||
794 | await makePutBodyRequest({ | 748 | await makePutBodyRequest({ |
795 | url: server.url, | 749 | url: server.url, |
796 | path: path + userId, | 750 | path: path + userId, |
797 | token: moderatorAccessToken, | 751 | token: moderatorToken, |
798 | fields, | 752 | fields, |
799 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | 753 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
800 | }) | 754 | }) |
@@ -820,31 +774,37 @@ describe('Test users API validators', function () { | |||
820 | 774 | ||
821 | describe('When getting my information', function () { | 775 | describe('When getting my information', function () { |
822 | it('Should fail with a non authenticated user', async function () { | 776 | it('Should fail with a non authenticated user', async function () { |
823 | await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401) | 777 | await server.usersCommand.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
824 | }) | 778 | }) |
825 | 779 | ||
826 | it('Should success with the correct parameters', async function () { | 780 | it('Should success with the correct parameters', async function () { |
827 | await getMyUserInformation(server.url, userAccessToken) | 781 | await server.usersCommand.getMyInfo({ token: userToken }) |
828 | }) | 782 | }) |
829 | }) | 783 | }) |
830 | 784 | ||
831 | describe('When getting my video rating', function () { | 785 | describe('When getting my video rating', function () { |
786 | let command: UsersCommand | ||
787 | |||
788 | before(function () { | ||
789 | command = server.usersCommand | ||
790 | }) | ||
791 | |||
832 | it('Should fail with a non authenticated user', async function () { | 792 | it('Should fail with a non authenticated user', async function () { |
833 | await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401) | 793 | await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
834 | }) | 794 | }) |
835 | 795 | ||
836 | it('Should fail with an incorrect video uuid', async function () { | 796 | it('Should fail with an incorrect video uuid', async function () { |
837 | await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400) | 797 | await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
838 | }) | 798 | }) |
839 | 799 | ||
840 | it('Should fail with an unknown video', async function () { | 800 | it('Should fail with an unknown video', async function () { |
841 | await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) | 801 | await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
842 | }) | 802 | }) |
843 | 803 | ||
844 | it('Should succeed with the correct parameters', async function () { | 804 | it('Should succeed with the correct parameters', async function () { |
845 | await getMyUserVideoRating(server.url, server.accessToken, video.id) | 805 | await command.getMyRating({ videoId: video.id }) |
846 | await getMyUserVideoRating(server.url, server.accessToken, video.uuid) | 806 | await command.getMyRating({ videoId: video.uuid }) |
847 | await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID) | 807 | await command.getMyRating({ videoId: video.shortUUID }) |
848 | }) | 808 | }) |
849 | }) | 809 | }) |
850 | 810 | ||
@@ -852,15 +812,15 @@ describe('Test users API validators', function () { | |||
852 | const path = '/api/v1/accounts/user1/ratings' | 812 | const path = '/api/v1/accounts/user1/ratings' |
853 | 813 | ||
854 | it('Should fail with a bad start pagination', async function () { | 814 | it('Should fail with a bad start pagination', async function () { |
855 | await checkBadStartPagination(server.url, path, userAccessToken) | 815 | await checkBadStartPagination(server.url, path, userToken) |
856 | }) | 816 | }) |
857 | 817 | ||
858 | it('Should fail with a bad count pagination', async function () { | 818 | it('Should fail with a bad count pagination', async function () { |
859 | await checkBadCountPagination(server.url, path, userAccessToken) | 819 | await checkBadCountPagination(server.url, path, userToken) |
860 | }) | 820 | }) |
861 | 821 | ||
862 | it('Should fail with an incorrect sort', async function () { | 822 | it('Should fail with an incorrect sort', async function () { |
863 | await checkBadSortPagination(server.url, path, userAccessToken) | 823 | await checkBadSortPagination(server.url, path, userToken) |
864 | }) | 824 | }) |
865 | 825 | ||
866 | it('Should fail with a unauthenticated user', async function () { | 826 | it('Should fail with a unauthenticated user', async function () { |
@@ -875,57 +835,70 @@ describe('Test users API validators', function () { | |||
875 | await makeGetRequest({ | 835 | await makeGetRequest({ |
876 | url: server.url, | 836 | url: server.url, |
877 | path, | 837 | path, |
878 | token: userAccessToken, | 838 | token: userToken, |
879 | query: { rating: 'toto ' }, | 839 | query: { rating: 'toto ' }, |
880 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | 840 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
881 | }) | 841 | }) |
882 | }) | 842 | }) |
883 | 843 | ||
884 | it('Should succeed with the correct params', async function () { | 844 | it('Should succeed with the correct params', async function () { |
885 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 }) | 845 | await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 }) |
886 | }) | 846 | }) |
887 | }) | 847 | }) |
888 | 848 | ||
889 | describe('When blocking/unblocking/removing user', function () { | 849 | describe('When blocking/unblocking/removing user', function () { |
850 | |||
890 | it('Should fail with an incorrect id', async function () { | 851 | it('Should fail with an incorrect id', async function () { |
891 | await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) | 852 | const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 } |
892 | await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) | 853 | |
893 | await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) | 854 | await server.usersCommand.remove(options) |
855 | await server.usersCommand.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
856 | await server.usersCommand.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
894 | }) | 857 | }) |
895 | 858 | ||
896 | it('Should fail with the root user', async function () { | 859 | it('Should fail with the root user', async function () { |
897 | await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) | 860 | const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 } |
898 | await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) | 861 | |
899 | await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) | 862 | await server.usersCommand.remove(options) |
863 | await server.usersCommand.banUser(options) | ||
864 | await server.usersCommand.unbanUser(options) | ||
900 | }) | 865 | }) |
901 | 866 | ||
902 | it('Should return 404 with a non existing id', async function () { | 867 | it('Should return 404 with a non existing id', async function () { |
903 | await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) | 868 | const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 } |
904 | await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) | 869 | |
905 | await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) | 870 | await server.usersCommand.remove(options) |
871 | await server.usersCommand.banUser(options) | ||
872 | await server.usersCommand.unbanUser(options) | ||
906 | }) | 873 | }) |
907 | 874 | ||
908 | it('Should fail with a non admin user', async function () { | 875 | it('Should fail with a non admin user', async function () { |
909 | await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) | 876 | const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 } |
910 | await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) | 877 | |
911 | await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) | 878 | await server.usersCommand.remove(options) |
879 | await server.usersCommand.banUser(options) | ||
880 | await server.usersCommand.unbanUser(options) | ||
912 | }) | 881 | }) |
913 | 882 | ||
914 | it('Should fail on a moderator with a moderator', async function () { | 883 | it('Should fail on a moderator with a moderator', async function () { |
915 | await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) | 884 | const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 } |
916 | await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) | 885 | |
917 | await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) | 886 | await server.usersCommand.remove(options) |
887 | await server.usersCommand.banUser(options) | ||
888 | await server.usersCommand.unbanUser(options) | ||
918 | }) | 889 | }) |
919 | 890 | ||
920 | it('Should succeed on a user with a moderator', async function () { | 891 | it('Should succeed on a user with a moderator', async function () { |
921 | await blockUser(server.url, userId, moderatorAccessToken) | 892 | const options = { userId, token: moderatorToken } |
922 | await unblockUser(server.url, userId, moderatorAccessToken) | 893 | |
894 | await server.usersCommand.banUser(options) | ||
895 | await server.usersCommand.unbanUser(options) | ||
923 | }) | 896 | }) |
924 | }) | 897 | }) |
925 | 898 | ||
926 | describe('When deleting our account', function () { | 899 | describe('When deleting our account', function () { |
927 | it('Should fail with with the root account', async function () { | 900 | it('Should fail with with the root account', async function () { |
928 | await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400) | 901 | await server.usersCommand.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
929 | }) | 902 | }) |
930 | }) | 903 | }) |
931 | 904 | ||
@@ -1087,7 +1060,7 @@ describe('Test users API validators', function () { | |||
1087 | 1060 | ||
1088 | describe('When registering multiple users on a server with users limit', function () { | 1061 | describe('When registering multiple users on a server with users limit', function () { |
1089 | it('Should fail when after 3 registrations', async function () { | 1062 | it('Should fail when after 3 registrations', async function () { |
1090 | await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403) | 1063 | await server.usersCommand.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
1091 | }) | 1064 | }) |
1092 | }) | 1065 | }) |
1093 | 1066 | ||