aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/users.ts17
-rw-r--r--server/tests/api/users/users.ts37
-rw-r--r--server/tests/utils/users/login.ts4
3 files changed, 35 insertions, 23 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index b0f35b9f7..9938fe3a2 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -20,6 +20,10 @@ describe('Test users API validators', function () {
20 let server: ServerInfo 20 let server: ServerInfo
21 let serverWithRegistrationDisabled: ServerInfo 21 let serverWithRegistrationDisabled: ServerInfo
22 let userAccessToken = '' 22 let userAccessToken = ''
23 const user = {
24 username: 'user1',
25 password: 'my super password'
26 }
23 27
24 // --------------------------------------------------------------- 28 // ---------------------------------------------------------------
25 29
@@ -33,10 +37,6 @@ describe('Test users API validators', function () {
33 37
34 await setAccessTokensToServers([ server ]) 38 await setAccessTokensToServers([ server ])
35 39
36 const user = {
37 username: 'user1',
38 password: 'my super password'
39 }
40 const videoQuota = 42000000 40 const videoQuota = 42000000
41 await createUser(server.url, server.accessToken, user.username, user.password, videoQuota) 41 await createUser(server.url, server.accessToken, user.username, user.password, videoQuota)
42 userAccessToken = await userLogin(server, user) 42 userAccessToken = await userLogin(server, user)
@@ -341,6 +341,14 @@ describe('Test users API validators', function () {
341 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) 341 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
342 }) 342 })
343 343
344 it('Should fail when updating root role', async function () {
345 const fields = {
346 role: UserRole.MODERATOR
347 }
348
349 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
350 })
351
344 it('Should succeed with the correct params', async function () { 352 it('Should succeed with the correct params', async function () {
345 const fields = { 353 const fields = {
346 email: 'email@example.com', 354 email: 'email@example.com',
@@ -349,6 +357,7 @@ describe('Test users API validators', function () {
349 } 357 }
350 358
351 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) 359 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
360 userAccessToken = await userLogin(server, user)
352 }) 361 })
353 }) 362 })
354 363
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 6bb5fd698..c23b58089 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -4,10 +4,9 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { UserRole } from '../../../../shared/index' 5import { UserRole } from '../../../../shared/index'
6import { 6import {
7 createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, getUserInformation, 7 createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating,
8 getUsersList, 8 getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo,
9 getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, 9 registerUser, removeUser, removeVideo, runServer, ServerInfo, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo, userLogin
10 runServer, ServerInfo, serverLogin, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo
11} from '../../utils/index' 10} from '../../utils/index'
12import { follow } from '../../utils/server/follows' 11import { follow } from '../../utils/server/follows'
13import { setAccessTokensToServers } from '../../utils/users/login' 12import { setAccessTokensToServers } from '../../utils/users/login'
@@ -21,6 +20,10 @@ describe('Test users', function () {
21 let accessTokenUser: string 20 let accessTokenUser: string
22 let videoId: number 21 let videoId: number
23 let userId: number 22 let userId: number
23 const user = {
24 username: 'user_1',
25 password: 'super password'
26 }
24 27
25 before(async function () { 28 before(async function () {
26 this.timeout(30000) 29 this.timeout(30000)
@@ -152,16 +155,11 @@ describe('Test users', function () {
152 it('Should be able to upload a video again') 155 it('Should be able to upload a video again')
153 156
154 it('Should be able to create a new user', async function () { 157 it('Should be able to create a new user', async function () {
155 await createUser(server.url, accessToken, 'user_1', 'super password', 2 * 1024 * 1024) 158 await createUser(server.url, accessToken, user.username,user.password, 2 * 1024 * 1024)
156 }) 159 })
157 160
158 it('Should be able to login with this user', async function () { 161 it('Should be able to login with this user', async function () {
159 server.user = { 162 accessTokenUser = await userLogin(server, user)
160 username: 'user_1',
161 password: 'super password'
162 }
163
164 accessTokenUser = await serverLogin(server)
165 }) 163 })
166 164
167 it('Should be able to get the user information', async function () { 165 it('Should be able to get the user information', async function () {
@@ -297,9 +295,9 @@ describe('Test users', function () {
297 accessToken: accessTokenUser, 295 accessToken: accessTokenUser,
298 newPassword: 'new password' 296 newPassword: 'new password'
299 }) 297 })
300 server.user.password = 'new password' 298 user.password = 'new password'
301 299
302 await login(server.url, server.client, server.user, 200) 300 await userLogin(server, user, 200)
303 }) 301 })
304 302
305 it('Should be able to change the NSFW display attribute', async function () { 303 it('Should be able to change the NSFW display attribute', async function () {
@@ -386,6 +384,12 @@ describe('Test users', function () {
386 expect(user.id).to.be.a('number') 384 expect(user.id).to.be.a('number')
387 }) 385 })
388 386
387 it('Should have removed the user token', async function () {
388 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
389
390 accessTokenUser = await userLogin(server, user)
391 })
392
389 it('Should not be able to delete a user by a moderator', async function () { 393 it('Should not be able to delete a user by a moderator', async function () {
390 await removeUser(server.url, 2, accessTokenUser, 403) 394 await removeUser(server.url, 2, accessTokenUser, 403)
391 }) 395 })
@@ -399,8 +403,7 @@ describe('Test users', function () {
399 }) 403 })
400 404
401 it('Should not be able to login with this user', async function () { 405 it('Should not be able to login with this user', async function () {
402 // server.user is already set to user 1 406 await userLogin(server, user, 400)
403 await login(server.url, server.client, server.user, 400)
404 }) 407 })
405 408
406 it('Should not have videos of this user', async function () { 409 it('Should not have videos of this user', async function () {
@@ -417,12 +420,12 @@ describe('Test users', function () {
417 }) 420 })
418 421
419 it('Should be able to login with this registered user', async function () { 422 it('Should be able to login with this registered user', async function () {
420 server.user = { 423 const user15 = {
421 username: 'user_15', 424 username: 'user_15',
422 password: 'my super password' 425 password: 'my super password'
423 } 426 }
424 427
425 accessToken = await serverLogin(server) 428 accessToken = await userLogin(server, user15)
426 }) 429 })
427 430
428 it('Should have the correct video quota', async function () { 431 it('Should have the correct video quota', async function () {
diff --git a/server/tests/utils/users/login.ts b/server/tests/utils/users/login.ts
index 04444e2f1..338ae1c00 100644
--- a/server/tests/utils/users/login.ts
+++ b/server/tests/utils/users/login.ts
@@ -32,8 +32,8 @@ async function serverLogin (server: Server) {
32 return res.body.access_token as string 32 return res.body.access_token as string
33} 33}
34 34
35async function userLogin (server: Server, user: User) { 35async function userLogin (server: Server, user: User, expectedStatus = 200) {
36 const res = await login(server.url, server.client, user, 200) 36 const res = await login(server.url, server.client, user, expectedStatus)
37 37
38 return res.body.access_token as string 38 return res.body.access_token as string
39} 39}