aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-08 14:58:21 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 15:22:58 +0200
commite69219184b1a3262ec5e617d30337b6431c9840c (patch)
tree959b32e1ed28047052604941870563e946be9de1 /server/tests/api
parent6b09aba90dfe4c61331b66b1a6ef1f58ddc61485 (diff)
downloadPeerTube-e69219184b1a3262ec5e617d30337b6431c9840c.tar.gz
PeerTube-e69219184b1a3262ec5e617d30337b6431c9840c.tar.zst
PeerTube-e69219184b1a3262ec5e617d30337b6431c9840c.zip
Implement user blocking on server side
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/users.ts16
-rw-r--r--server/tests/api/users/users.ts31
2 files changed, 40 insertions, 7 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 60165ae22..b3fb61f6c 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -8,7 +8,7 @@ import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
8import { 8import {
9 createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, 9 createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest,
10 makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, 10 makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers,
11 updateUser, uploadVideo, userLogin, deleteMe 11 updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser
12} from '../../utils' 12} from '../../utils'
13import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 13import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
14import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports' 14import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports'
@@ -455,17 +455,29 @@ describe('Test users API validators', function () {
455 }) 455 })
456 }) 456 })
457 457
458 describe('When removing an user', function () { 458 describe('When blocking/unblocking/removing user', function () {
459 it('Should fail with an incorrect id', async function () { 459 it('Should fail with an incorrect id', async function () {
460 await removeUser(server.url, 'blabla', server.accessToken, 400) 460 await removeUser(server.url, 'blabla', server.accessToken, 400)
461 await blockUser(server.url, 'blabla', server.accessToken, 400)
462 await unblockUser(server.url, 'blabla', server.accessToken, 400)
461 }) 463 })
462 464
463 it('Should fail with the root user', async function () { 465 it('Should fail with the root user', async function () {
464 await removeUser(server.url, rootId, server.accessToken, 400) 466 await removeUser(server.url, rootId, server.accessToken, 400)
467 await blockUser(server.url, rootId, server.accessToken, 400)
468 await unblockUser(server.url, rootId, server.accessToken, 400)
465 }) 469 })
466 470
467 it('Should return 404 with a non existing id', async function () { 471 it('Should return 404 with a non existing id', async function () {
468 await removeUser(server.url, 4545454, server.accessToken, 404) 472 await removeUser(server.url, 4545454, server.accessToken, 404)
473 await blockUser(server.url, 4545454, server.accessToken, 404)
474 await unblockUser(server.url, 4545454, server.accessToken, 404)
475 })
476
477 it('Should fail with a non admin user', async function () {
478 await removeUser(server.url, userId, userAccessToken, 403)
479 await blockUser(server.url, userId, userAccessToken, 403)
480 await unblockUser(server.url, userId, userAccessToken, 403)
469 }) 481 })
470 }) 482 })
471 483
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index c9e8eb6f9..77aa00f60 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -7,7 +7,7 @@ import {
7 createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, 7 createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating,
8 getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, 8 getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo,
9 registerUser, removeUser, removeVideo, runServer, ServerInfo, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo, userLogin, 9 registerUser, removeUser, removeVideo, runServer, ServerInfo, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo, userLogin,
10 deleteMe 10 deleteMe, blockUser, unblockUser
11} from '../../utils/index' 11} from '../../utils/index'
12import { follow } from '../../utils/server/follows' 12import { follow } from '../../utils/server/follows'
13import { setAccessTokensToServers } from '../../utils/users/login' 13import { setAccessTokensToServers } from '../../utils/users/login'
@@ -45,28 +45,28 @@ describe('Test users', function () {
45 const client = { id: 'client', secret: server.client.secret } 45 const client = { id: 'client', secret: server.client.secret }
46 const res = await login(server.url, client, server.user, 400) 46 const res = await login(server.url, client, server.user, 400)
47 47
48 expect(res.body.error).to.equal('Authentication failed.') 48 expect(res.body.error).to.contain('client is invalid')
49 }) 49 })
50 50
51 it('Should not login with an invalid client secret', async function () { 51 it('Should not login with an invalid client secret', async function () {
52 const client = { id: server.client.id, secret: 'coucou' } 52 const client = { id: server.client.id, secret: 'coucou' }
53 const res = await login(server.url, client, server.user, 400) 53 const res = await login(server.url, client, server.user, 400)
54 54
55 expect(res.body.error).to.equal('Authentication failed.') 55 expect(res.body.error).to.contain('client is invalid')
56 }) 56 })
57 57
58 it('Should not login with an invalid username', async function () { 58 it('Should not login with an invalid username', async function () {
59 const user = { username: 'captain crochet', password: server.user.password } 59 const user = { username: 'captain crochet', password: server.user.password }
60 const res = await login(server.url, server.client, user, 400) 60 const res = await login(server.url, server.client, user, 400)
61 61
62 expect(res.body.error).to.equal('Authentication failed.') 62 expect(res.body.error).to.contain('credentials are invalid')
63 }) 63 })
64 64
65 it('Should not login with an invalid password', async function () { 65 it('Should not login with an invalid password', async function () {
66 const user = { username: server.user.username, password: 'mew_three' } 66 const user = { username: server.user.username, password: 'mew_three' }
67 const res = await login(server.url, server.client, user, 400) 67 const res = await login(server.url, server.client, user, 400)
68 68
69 expect(res.body.error).to.equal('Authentication failed.') 69 expect(res.body.error).to.contain('credentials are invalid')
70 }) 70 })
71 71
72 it('Should not be able to upload a video', async function () { 72 it('Should not be able to upload a video', async function () {
@@ -493,6 +493,27 @@ describe('Test users', function () {
493 } 493 }
494 }) 494 })
495 495
496 it('Should block and unblock a user', async function () {
497 const user16 = {
498 username: 'user_16',
499 password: 'my super password'
500 }
501 const resUser = await createUser(server.url, server.accessToken, user16.username, user16.password)
502 const user16Id = resUser.body.user.id
503
504 accessToken = await userLogin(server, user16)
505
506 await getMyUserInformation(server.url, accessToken, 200)
507 await blockUser(server.url, user16Id, server.accessToken)
508
509 await getMyUserInformation(server.url, accessToken, 401)
510 await userLogin(server, user16, 400)
511
512 await unblockUser(server.url, user16Id, server.accessToken)
513 accessToken = await userLogin(server, user16)
514 await getMyUserInformation(server.url, accessToken, 200)
515 })
516
496 after(async function () { 517 after(async function () {
497 killallServers([ server ]) 518 killallServers([ server ])
498 519