aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/users.ts16
-rw-r--r--server/tests/api/users/users.ts31
-rw-r--r--server/tests/utils/users/users.ts22
3 files changed, 62 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
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index e24e721bd..7e15fc86e 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -134,6 +134,26 @@ function removeUser (url: string, userId: number | string, accessToken: string,
134 .expect(expectedStatus) 134 .expect(expectedStatus)
135} 135}
136 136
137function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) {
138 const path = '/api/v1/users'
139
140 return request(url)
141 .post(path + '/' + userId + '/block')
142 .set('Accept', 'application/json')
143 .set('Authorization', 'Bearer ' + accessToken)
144 .expect(expectedStatus)
145}
146
147function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) {
148 const path = '/api/v1/users'
149
150 return request(url)
151 .post(path + '/' + userId + '/unblock')
152 .set('Accept', 'application/json')
153 .set('Authorization', 'Bearer ' + accessToken)
154 .expect(expectedStatus)
155}
156
137function updateMyUser (options: { 157function updateMyUser (options: {
138 url: string 158 url: string
139 accessToken: string, 159 accessToken: string,
@@ -234,6 +254,8 @@ export {
234 updateUser, 254 updateUser,
235 updateMyUser, 255 updateMyUser,
236 getUserInformation, 256 getUserInformation,
257 blockUser,
258 unblockUser,
237 askResetPassword, 259 askResetPassword,
238 resetPassword, 260 resetPassword,
239 updateMyAvatar 261 updateMyAvatar