aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/users.ts')
-rw-r--r--server/tests/api/check-params/users.ts425
1 files changed, 196 insertions, 229 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 70a872ce5..9d8f933db 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -2,43 +2,24 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { User, UserRole, VideoCreateResult } from '../../../../shared'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 5import {
8 addVideoChannel,
9 blockUser,
10 buildAbsoluteFixturePath, 6 buildAbsoluteFixturePath,
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
11 cleanupTests, 10 cleanupTests,
12 createUser, 11 createSingleServer,
13 deleteMe,
14 flushAndRunServer,
15 getMyUserInformation,
16 getMyUserVideoRating,
17 getUserScopedTokens,
18 getUsersList,
19 immutableAssign,
20 killallServers, 12 killallServers,
21 makeGetRequest, 13 makeGetRequest,
22 makePostBodyRequest, 14 makePostBodyRequest,
23 makePutBodyRequest, 15 makePutBodyRequest,
24 makeUploadRequest, 16 makeUploadRequest,
25 registerUser, 17 MockSmtpServer,
26 removeUser, 18 PeerTubeServer,
27 renewUserScopedTokens,
28 reRunServer,
29 ServerInfo,
30 setAccessTokensToServers, 19 setAccessTokensToServers,
31 unblockUser, 20 UsersCommand
32 uploadVideo, 21} from '@shared/extra-utils'
33 userLogin 22import { HttpStatusCode, UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models'
34} from '../../../../shared/extra-utils'
35import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
36import {
37 checkBadCountPagination,
38 checkBadSortPagination,
39 checkBadStartPagination
40} from '../../../../shared/extra-utils/requests/check-api-params'
41import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
42 23
43describe('Test users API validators', function () { 24describe('Test users API validators', function () {
44 const path = '/api/v1/users/' 25 const path = '/api/v1/users/'
@@ -46,10 +27,10 @@ describe('Test users API validators', function () {
46 let rootId: number 27 let rootId: number
47 let moderatorId: number 28 let moderatorId: number
48 let video: VideoCreateResult 29 let video: VideoCreateResult
49 let server: ServerInfo 30 let server: PeerTubeServer
50 let serverWithRegistrationDisabled: ServerInfo 31 let serverWithRegistrationDisabled: PeerTubeServer
51 let userAccessToken = '' 32 let userToken = ''
52 let moderatorAccessToken = '' 33 let moderatorToken = ''
53 let emailPort: number 34 let emailPort: number
54 let overrideConfig: Object 35 let overrideConfig: Object
55 36
@@ -65,8 +46,8 @@ describe('Test users API validators', function () {
65 46
66 { 47 {
67 const res = await Promise.all([ 48 const res = await Promise.all([
68 flushAndRunServer(1, overrideConfig), 49 createSingleServer(1, overrideConfig),
69 flushAndRunServer(2) 50 createSingleServer(2)
70 ]) 51 ])
71 52
72 server = res[0] 53 server = res[0]
@@ -76,66 +57,31 @@ describe('Test users API validators', function () {
76 } 57 }
77 58
78 { 59 {
79 const user = { 60 const user = { username: 'user1' }
80 username: 'user1', 61 await server.users.create({ ...user })
81 password: 'my super password' 62 userToken = await server.login.getAccessToken(user)
82 }
83
84 const videoQuota = 42000000
85 await createUser({
86 url: server.url,
87 accessToken: server.accessToken,
88 username: user.username,
89 password: user.password,
90 videoQuota: videoQuota
91 })
92 userAccessToken = await userLogin(server, user)
93 } 63 }
94 64
95 { 65 {
96 const moderator = { 66 const moderator = { username: 'moderator1' }
97 username: 'moderator1', 67 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
98 password: 'super password' 68 moderatorToken = await server.login.getAccessToken(moderator)
99 }
100
101 await createUser({
102 url: server.url,
103 accessToken: server.accessToken,
104 username: moderator.username,
105 password: moderator.password,
106 role: UserRole.MODERATOR
107 })
108
109 moderatorAccessToken = await userLogin(server, moderator)
110 } 69 }
111 70
112 { 71 {
113 const moderator = { 72 const moderator = { username: 'moderator2' }
114 username: 'moderator2', 73 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
115 password: 'super password'
116 }
117
118 await createUser({
119 url: server.url,
120 accessToken: server.accessToken,
121 username: moderator.username,
122 password: moderator.password,
123 role: UserRole.MODERATOR
124 })
125 } 74 }
126 75
127 { 76 {
128 const res = await uploadVideo(server.url, server.accessToken, {}) 77 video = await server.videos.upload()
129 video = res.body.video
130 } 78 }
131 79
132 { 80 {
133 const res = await getUsersList(server.url, server.accessToken) 81 const { data } = await server.users.list()
134 const users: User[] = res.body.data 82 userId = data.find(u => u.username === 'user1').id
135 83 rootId = data.find(u => u.username === 'root').id
136 userId = users.find(u => u.username === 'user1').id 84 moderatorId = data.find(u => u.username === 'moderator2').id
137 rootId = users.find(u => u.username === 'root').id
138 moderatorId = users.find(u => u.username === 'moderator2').id
139 } 85 }
140 }) 86 })
141 87
@@ -156,7 +102,7 @@ describe('Test users API validators', function () {
156 await makeGetRequest({ 102 await makeGetRequest({
157 url: server.url, 103 url: server.url,
158 path, 104 path,
159 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 105 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
160 }) 106 })
161 }) 107 })
162 108
@@ -164,8 +110,8 @@ describe('Test users API validators', function () {
164 await makeGetRequest({ 110 await makeGetRequest({
165 url: server.url, 111 url: server.url,
166 path, 112 path,
167 token: userAccessToken, 113 token: userToken,
168 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 114 expectedStatus: HttpStatusCode.FORBIDDEN_403
169 }) 115 })
170 }) 116 })
171 }) 117 })
@@ -182,25 +128,25 @@ describe('Test users API validators', function () {
182 } 128 }
183 129
184 it('Should fail with a too small username', async function () { 130 it('Should fail with a too small username', async function () {
185 const fields = immutableAssign(baseCorrectParams, { username: '' }) 131 const fields = { ...baseCorrectParams, username: '' }
186 132
187 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 133 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
188 }) 134 })
189 135
190 it('Should fail with a too long username', async function () { 136 it('Should fail with a too long username', async function () {
191 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 137 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
192 138
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 139 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
194 }) 140 })
195 141
196 it('Should fail with a not lowercase username', async function () { 142 it('Should fail with a not lowercase username', async function () {
197 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) 143 const fields = { ...baseCorrectParams, username: 'Toto' }
198 144
199 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 145 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
200 }) 146 })
201 147
202 it('Should fail with an incorrect username', async function () { 148 it('Should fail with an incorrect username', async function () {
203 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 149 const fields = { ...baseCorrectParams, username: 'my username' }
204 150
205 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 151 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
206 }) 152 })
@@ -212,25 +158,25 @@ describe('Test users API validators', function () {
212 }) 158 })
213 159
214 it('Should fail with an invalid email', async function () { 160 it('Should fail with an invalid email', async function () {
215 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 161 const fields = { ...baseCorrectParams, email: 'test_example.com' }
216 162
217 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 163 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
218 }) 164 })
219 165
220 it('Should fail with a too small password', async function () { 166 it('Should fail with a too small password', async function () {
221 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 167 const fields = { ...baseCorrectParams, password: 'bla' }
222 168
223 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 169 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 }) 170 })
225 171
226 it('Should fail with a too long password', async function () { 172 it('Should fail with a too long password', async function () {
227 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 173 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
228 174
229 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 175 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
230 }) 176 })
231 177
232 it('Should fail with empty password and no smtp configured', async function () { 178 it('Should fail with empty password and no smtp configured', async function () {
233 const fields = immutableAssign(baseCorrectParams, { password: '' }) 179 const fields = { ...baseCorrectParams, password: '' }
234 180
235 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 181 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
236 }) 182 })
@@ -238,33 +184,37 @@ describe('Test users API validators', function () {
238 it('Should succeed with no password on a server with smtp enabled', async function () { 184 it('Should succeed with no password on a server with smtp enabled', async function () {
239 this.timeout(20000) 185 this.timeout(20000)
240 186
241 killallServers([ server ]) 187 await killallServers([ server ])
188
189 const config = {
190 ...overrideConfig,
242 191
243 const config = immutableAssign(overrideConfig, {
244 smtp: { 192 smtp: {
245 hostname: 'localhost', 193 hostname: 'localhost',
246 port: emailPort 194 port: emailPort
247 } 195 }
248 }) 196 }
249 await reRunServer(server, config) 197 await server.run(config)
198
199 const fields = {
200 ...baseCorrectParams,
250 201
251 const fields = immutableAssign(baseCorrectParams, {
252 password: '', 202 password: '',
253 username: 'create_password', 203 username: 'create_password',
254 email: 'create_password@example.com' 204 email: 'create_password@example.com'
255 }) 205 }
256 206
257 await makePostBodyRequest({ 207 await makePostBodyRequest({
258 url: server.url, 208 url: server.url,
259 path: path, 209 path: path,
260 token: server.accessToken, 210 token: server.accessToken,
261 fields, 211 fields,
262 statusCodeExpected: HttpStatusCode.OK_200 212 expectedStatus: HttpStatusCode.OK_200
263 }) 213 })
264 }) 214 })
265 215
266 it('Should fail with invalid admin flags', async function () { 216 it('Should fail with invalid admin flags', async function () {
267 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) 217 const fields = { ...baseCorrectParams, adminFlags: 'toto' }
268 218
269 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 219 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
270 }) 220 })
@@ -275,31 +225,31 @@ describe('Test users API validators', function () {
275 path, 225 path,
276 token: 'super token', 226 token: 'super token',
277 fields: baseCorrectParams, 227 fields: baseCorrectParams,
278 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 228 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
279 }) 229 })
280 }) 230 })
281 231
282 it('Should fail if we add a user with the same username', async function () { 232 it('Should fail if we add a user with the same username', async function () {
283 const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) 233 const fields = { ...baseCorrectParams, username: 'user1' }
284 234
285 await makePostBodyRequest({ 235 await makePostBodyRequest({
286 url: server.url, 236 url: server.url,
287 path, 237 path,
288 token: server.accessToken, 238 token: server.accessToken,
289 fields, 239 fields,
290 statusCodeExpected: HttpStatusCode.CONFLICT_409 240 expectedStatus: HttpStatusCode.CONFLICT_409
291 }) 241 })
292 }) 242 })
293 243
294 it('Should fail if we add a user with the same email', async function () { 244 it('Should fail if we add a user with the same email', async function () {
295 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) 245 const fields = { ...baseCorrectParams, email: 'user1@example.com' }
296 246
297 await makePostBodyRequest({ 247 await makePostBodyRequest({
298 url: server.url, 248 url: server.url,
299 path, 249 path,
300 token: server.accessToken, 250 token: server.accessToken,
301 fields, 251 fields,
302 statusCodeExpected: HttpStatusCode.CONFLICT_409 252 expectedStatus: HttpStatusCode.CONFLICT_409
303 }) 253 })
304 }) 254 })
305 255
@@ -316,13 +266,13 @@ describe('Test users API validators', function () {
316 }) 266 })
317 267
318 it('Should fail with an invalid videoQuota', async function () { 268 it('Should fail with an invalid videoQuota', async function () {
319 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) 269 const fields = { ...baseCorrectParams, videoQuota: -5 }
320 270
321 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 271 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
322 }) 272 })
323 273
324 it('Should fail with an invalid videoQuotaDaily', async function () { 274 it('Should fail with an invalid videoQuotaDaily', async function () {
325 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) 275 const fields = { ...baseCorrectParams, videoQuotaDaily: -7 }
326 276
327 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 277 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
328 }) 278 })
@@ -334,46 +284,46 @@ describe('Test users API validators', function () {
334 }) 284 })
335 285
336 it('Should fail with an invalid user role', async function () { 286 it('Should fail with an invalid user role', async function () {
337 const fields = immutableAssign(baseCorrectParams, { role: 88989 }) 287 const fields = { ...baseCorrectParams, role: 88989 }
338 288
339 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 289 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
340 }) 290 })
341 291
342 it('Should fail with a "peertube" username', async function () { 292 it('Should fail with a "peertube" username', async function () {
343 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 293 const fields = { ...baseCorrectParams, username: 'peertube' }
344 294
345 await makePostBodyRequest({ 295 await makePostBodyRequest({
346 url: server.url, 296 url: server.url,
347 path, 297 path,
348 token: server.accessToken, 298 token: server.accessToken,
349 fields, 299 fields,
350 statusCodeExpected: HttpStatusCode.CONFLICT_409 300 expectedStatus: HttpStatusCode.CONFLICT_409
351 }) 301 })
352 }) 302 })
353 303
354 it('Should fail to create a moderator or an admin with a moderator', async function () { 304 it('Should fail to create a moderator or an admin with a moderator', async function () {
355 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) { 305 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
356 const fields = immutableAssign(baseCorrectParams, { role }) 306 const fields = { ...baseCorrectParams, role }
357 307
358 await makePostBodyRequest({ 308 await makePostBodyRequest({
359 url: server.url, 309 url: server.url,
360 path, 310 path,
361 token: moderatorAccessToken, 311 token: moderatorToken,
362 fields, 312 fields,
363 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 313 expectedStatus: HttpStatusCode.FORBIDDEN_403
364 }) 314 })
365 } 315 }
366 }) 316 })
367 317
368 it('Should succeed to create a user with a moderator', async function () { 318 it('Should succeed to create a user with a moderator', async function () {
369 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }) 319 const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }
370 320
371 await makePostBodyRequest({ 321 await makePostBodyRequest({
372 url: server.url, 322 url: server.url,
373 path, 323 path,
374 token: moderatorAccessToken, 324 token: moderatorToken,
375 fields, 325 fields,
376 statusCodeExpected: HttpStatusCode.OK_200 326 expectedStatus: HttpStatusCode.OK_200
377 }) 327 })
378 }) 328 })
379 329
@@ -383,16 +333,13 @@ describe('Test users API validators', function () {
383 path, 333 path,
384 token: server.accessToken, 334 token: server.accessToken,
385 fields: baseCorrectParams, 335 fields: baseCorrectParams,
386 statusCodeExpected: HttpStatusCode.OK_200 336 expectedStatus: HttpStatusCode.OK_200
387 }) 337 })
388 }) 338 })
389 339
390 it('Should fail with a non admin user', async function () { 340 it('Should fail with a non admin user', async function () {
391 const user = { 341 const user = { username: 'user1' }
392 username: 'user1', 342 userToken = await server.login.getAccessToken(user)
393 password: 'my super password'
394 }
395 userAccessToken = await userLogin(server, user)
396 343
397 const fields = { 344 const fields = {
398 username: 'user3', 345 username: 'user3',
@@ -400,11 +347,12 @@ describe('Test users API validators', function () {
400 password: 'my super password', 347 password: 'my super password',
401 videoQuota: 42000000 348 videoQuota: 42000000
402 } 349 }
403 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 350 await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
404 }) 351 })
405 }) 352 })
406 353
407 describe('When updating my account', function () { 354 describe('When updating my account', function () {
355
408 it('Should fail with an invalid email attribute', async function () { 356 it('Should fail with an invalid email attribute', async function () {
409 const fields = { 357 const fields = {
410 email: 'blabla' 358 email: 'blabla'
@@ -415,29 +363,29 @@ describe('Test users API validators', function () {
415 363
416 it('Should fail with a too small password', async function () { 364 it('Should fail with a too small password', async function () {
417 const fields = { 365 const fields = {
418 currentPassword: 'my super password', 366 currentPassword: 'password',
419 password: 'bla' 367 password: 'bla'
420 } 368 }
421 369
422 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 370 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
423 }) 371 })
424 372
425 it('Should fail with a too long password', async function () { 373 it('Should fail with a too long password', async function () {
426 const fields = { 374 const fields = {
427 currentPassword: 'my super password', 375 currentPassword: 'password',
428 password: 'super'.repeat(61) 376 password: 'super'.repeat(61)
429 } 377 }
430 378
431 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 379 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
432 }) 380 })
433 381
434 it('Should fail without the current password', async function () { 382 it('Should fail without the current password', async function () {
435 const fields = { 383 const fields = {
436 currentPassword: 'my super password', 384 currentPassword: 'password',
437 password: 'super'.repeat(61) 385 password: 'super'.repeat(61)
438 } 386 }
439 387
440 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 388 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
441 }) 389 })
442 390
443 it('Should fail with an invalid current password', async function () { 391 it('Should fail with an invalid current password', async function () {
@@ -449,9 +397,9 @@ describe('Test users API validators', function () {
449 await makePutBodyRequest({ 397 await makePutBodyRequest({
450 url: server.url, 398 url: server.url,
451 path: path + 'me', 399 path: path + 'me',
452 token: userAccessToken, 400 token: userToken,
453 fields, 401 fields,
454 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 402 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
455 }) 403 })
456 }) 404 })
457 405
@@ -460,7 +408,7 @@ describe('Test users API validators', function () {
460 nsfwPolicy: 'hello' 408 nsfwPolicy: 'hello'
461 } 409 }
462 410
463 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 411 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
464 }) 412 })
465 413
466 it('Should fail with an invalid autoPlayVideo attribute', async function () { 414 it('Should fail with an invalid autoPlayVideo attribute', async function () {
@@ -468,7 +416,7 @@ describe('Test users API validators', function () {
468 autoPlayVideo: -1 416 autoPlayVideo: -1
469 } 417 }
470 418
471 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 419 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
472 }) 420 })
473 421
474 it('Should fail with an invalid autoPlayNextVideo attribute', async function () { 422 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
@@ -476,7 +424,7 @@ describe('Test users API validators', function () {
476 autoPlayNextVideo: -1 424 autoPlayNextVideo: -1
477 } 425 }
478 426
479 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 427 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
480 }) 428 })
481 429
482 it('Should fail with an invalid videosHistoryEnabled attribute', async function () { 430 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
@@ -484,12 +432,12 @@ describe('Test users API validators', function () {
484 videosHistoryEnabled: -1 432 videosHistoryEnabled: -1
485 } 433 }
486 434
487 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 435 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
488 }) 436 })
489 437
490 it('Should fail with an non authenticated user', async function () { 438 it('Should fail with an non authenticated user', async function () {
491 const fields = { 439 const fields = {
492 currentPassword: 'my super password', 440 currentPassword: 'password',
493 password: 'my super password' 441 password: 'my super password'
494 } 442 }
495 443
@@ -498,7 +446,7 @@ describe('Test users API validators', function () {
498 path: path + 'me', 446 path: path + 'me',
499 token: 'super token', 447 token: 'super token',
500 fields, 448 fields,
501 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 449 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
502 }) 450 })
503 }) 451 })
504 452
@@ -507,7 +455,7 @@ describe('Test users API validators', function () {
507 description: 'super'.repeat(201) 455 description: 'super'.repeat(201)
508 } 456 }
509 457
510 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 458 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
511 }) 459 })
512 460
513 it('Should fail with an invalid videoLanguages attribute', async function () { 461 it('Should fail with an invalid videoLanguages attribute', async function () {
@@ -516,7 +464,7 @@ describe('Test users API validators', function () {
516 videoLanguages: 'toto' 464 videoLanguages: 'toto'
517 } 465 }
518 466
519 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 467 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
520 } 468 }
521 469
522 { 470 {
@@ -529,18 +477,18 @@ describe('Test users API validators', function () {
529 videoLanguages: languages 477 videoLanguages: languages
530 } 478 }
531 479
532 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 480 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
533 } 481 }
534 }) 482 })
535 483
536 it('Should fail with an invalid theme', async function () { 484 it('Should fail with an invalid theme', async function () {
537 const fields = { theme: 'invalid' } 485 const fields = { theme: 'invalid' }
538 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 486 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
539 }) 487 })
540 488
541 it('Should fail with an unknown theme', async function () { 489 it('Should fail with an unknown theme', async function () {
542 const fields = { theme: 'peertube-theme-unknown' } 490 const fields = { theme: 'peertube-theme-unknown' }
543 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 491 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
544 }) 492 })
545 493
546 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { 494 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
@@ -548,7 +496,7 @@ describe('Test users API validators', function () {
548 noInstanceConfigWarningModal: -1 496 noInstanceConfigWarningModal: -1
549 } 497 }
550 498
551 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 499 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
552 }) 500 })
553 501
554 it('Should fail with an invalid noWelcomeModal attribute', async function () { 502 it('Should fail with an invalid noWelcomeModal attribute', async function () {
@@ -556,12 +504,12 @@ describe('Test users API validators', function () {
556 noWelcomeModal: -1 504 noWelcomeModal: -1
557 } 505 }
558 506
559 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 507 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
560 }) 508 })
561 509
562 it('Should succeed to change password with the correct params', async function () { 510 it('Should succeed to change password with the correct params', async function () {
563 const fields = { 511 const fields = {
564 currentPassword: 'my super password', 512 currentPassword: 'password',
565 password: 'my super password', 513 password: 'my super password',
566 nsfwPolicy: 'blur', 514 nsfwPolicy: 'blur',
567 autoPlayVideo: false, 515 autoPlayVideo: false,
@@ -574,9 +522,9 @@ describe('Test users API validators', function () {
574 await makePutBodyRequest({ 522 await makePutBodyRequest({
575 url: server.url, 523 url: server.url,
576 path: path + 'me', 524 path: path + 'me',
577 token: userAccessToken, 525 token: userToken,
578 fields, 526 fields,
579 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 527 expectedStatus: HttpStatusCode.NO_CONTENT_204
580 }) 528 })
581 }) 529 })
582 530
@@ -589,9 +537,9 @@ describe('Test users API validators', function () {
589 await makePutBodyRequest({ 537 await makePutBodyRequest({
590 url: server.url, 538 url: server.url,
591 path: path + 'me', 539 path: path + 'me',
592 token: userAccessToken, 540 token: userToken,
593 fields, 541 fields,
594 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 542 expectedStatus: HttpStatusCode.NO_CONTENT_204
595 }) 543 })
596 }) 544 })
597 }) 545 })
@@ -623,7 +571,7 @@ describe('Test users API validators', function () {
623 path: path + '/me/avatar/pick', 571 path: path + '/me/avatar/pick',
624 fields, 572 fields,
625 attaches, 573 attaches,
626 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 574 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
627 }) 575 })
628 }) 576 })
629 577
@@ -638,7 +586,7 @@ describe('Test users API validators', function () {
638 token: server.accessToken, 586 token: server.accessToken,
639 fields, 587 fields,
640 attaches, 588 attaches,
641 statusCodeExpected: HttpStatusCode.OK_200 589 expectedStatus: HttpStatusCode.OK_200
642 }) 590 })
643 }) 591 })
644 }) 592 })
@@ -646,28 +594,28 @@ describe('Test users API validators', function () {
646 describe('When managing my scoped tokens', function () { 594 describe('When managing my scoped tokens', function () {
647 595
648 it('Should fail to get my scoped tokens with an non authenticated user', async function () { 596 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
649 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) 597 await server.users.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
650 }) 598 })
651 599
652 it('Should fail to get my scoped tokens with a bad token', async function () { 600 it('Should fail to get my scoped tokens with a bad token', async function () {
653 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) 601 await server.users.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
654 602
655 }) 603 })
656 604
657 it('Should succeed to get my scoped tokens', async function () { 605 it('Should succeed to get my scoped tokens', async function () {
658 await getUserScopedTokens(server.url, server.accessToken) 606 await server.users.getMyScopedTokens()
659 }) 607 })
660 608
661 it('Should fail to renew my scoped tokens with an non authenticated user', async function () { 609 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
662 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) 610 await server.users.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
663 }) 611 })
664 612
665 it('Should fail to renew my scoped tokens with a bad token', async function () { 613 it('Should fail to renew my scoped tokens with a bad token', async function () {
666 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) 614 await server.users.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
667 }) 615 })
668 616
669 it('Should succeed to renew my scoped tokens', async function () { 617 it('Should succeed to renew my scoped tokens', async function () {
670 await renewUserScopedTokens(server.url, server.accessToken) 618 await server.users.renewMyScopedTokens()
671 }) 619 })
672 }) 620 })
673 621
@@ -678,16 +626,16 @@ describe('Test users API validators', function () {
678 url: server.url, 626 url: server.url,
679 path: path + userId, 627 path: path + userId,
680 token: 'super token', 628 token: 'super token',
681 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 629 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
682 }) 630 })
683 }) 631 })
684 632
685 it('Should fail with a non admin user', async function () { 633 it('Should fail with a non admin user', async function () {
686 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 634 await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
687 }) 635 })
688 636
689 it('Should succeed with the correct params', async function () { 637 it('Should succeed with the correct params', async function () {
690 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 }) 638 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 })
691 }) 639 })
692 }) 640 })
693 641
@@ -727,7 +675,7 @@ describe('Test users API validators', function () {
727 675
728 it('Should fail with a too small password', async function () { 676 it('Should fail with a too small password', async function () {
729 const fields = { 677 const fields = {
730 currentPassword: 'my super password', 678 currentPassword: 'password',
731 password: 'bla' 679 password: 'bla'
732 } 680 }
733 681
@@ -736,7 +684,7 @@ describe('Test users API validators', function () {
736 684
737 it('Should fail with a too long password', async function () { 685 it('Should fail with a too long password', async function () {
738 const fields = { 686 const fields = {
739 currentPassword: 'my super password', 687 currentPassword: 'password',
740 password: 'super'.repeat(61) 688 password: 'super'.repeat(61)
741 } 689 }
742 690
@@ -753,7 +701,7 @@ describe('Test users API validators', function () {
753 path: path + userId, 701 path: path + userId,
754 token: 'super token', 702 token: 'super token',
755 fields, 703 fields,
756 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 704 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
757 }) 705 })
758 }) 706 })
759 707
@@ -779,9 +727,9 @@ describe('Test users API validators', function () {
779 await makePutBodyRequest({ 727 await makePutBodyRequest({
780 url: server.url, 728 url: server.url,
781 path: path + moderatorId, 729 path: path + moderatorId,
782 token: moderatorAccessToken, 730 token: moderatorToken,
783 fields, 731 fields,
784 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 732 expectedStatus: HttpStatusCode.FORBIDDEN_403
785 }) 733 })
786 }) 734 })
787 735
@@ -793,9 +741,9 @@ describe('Test users API validators', function () {
793 await makePutBodyRequest({ 741 await makePutBodyRequest({
794 url: server.url, 742 url: server.url,
795 path: path + userId, 743 path: path + userId,
796 token: moderatorAccessToken, 744 token: moderatorToken,
797 fields, 745 fields,
798 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 746 expectedStatus: HttpStatusCode.NO_CONTENT_204
799 }) 747 })
800 }) 748 })
801 749
@@ -812,38 +760,44 @@ describe('Test users API validators', function () {
812 path: path + userId, 760 path: path + userId,
813 token: server.accessToken, 761 token: server.accessToken,
814 fields, 762 fields,
815 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 763 expectedStatus: HttpStatusCode.NO_CONTENT_204
816 }) 764 })
817 }) 765 })
818 }) 766 })
819 767
820 describe('When getting my information', function () { 768 describe('When getting my information', function () {
821 it('Should fail with a non authenticated user', async function () { 769 it('Should fail with a non authenticated user', async function () {
822 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401) 770 await server.users.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
823 }) 771 })
824 772
825 it('Should success with the correct parameters', async function () { 773 it('Should success with the correct parameters', async function () {
826 await getMyUserInformation(server.url, userAccessToken) 774 await server.users.getMyInfo({ token: userToken })
827 }) 775 })
828 }) 776 })
829 777
830 describe('When getting my video rating', function () { 778 describe('When getting my video rating', function () {
779 let command: UsersCommand
780
781 before(function () {
782 command = server.users
783 })
784
831 it('Should fail with a non authenticated user', async function () { 785 it('Should fail with a non authenticated user', async function () {
832 await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401) 786 await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
833 }) 787 })
834 788
835 it('Should fail with an incorrect video uuid', async function () { 789 it('Should fail with an incorrect video uuid', async function () {
836 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400) 790 await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
837 }) 791 })
838 792
839 it('Should fail with an unknown video', async function () { 793 it('Should fail with an unknown video', async function () {
840 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 794 await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
841 }) 795 })
842 796
843 it('Should succeed with the correct parameters', async function () { 797 it('Should succeed with the correct parameters', async function () {
844 await getMyUserVideoRating(server.url, server.accessToken, video.id) 798 await command.getMyRating({ videoId: video.id })
845 await getMyUserVideoRating(server.url, server.accessToken, video.uuid) 799 await command.getMyRating({ videoId: video.uuid })
846 await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID) 800 await command.getMyRating({ videoId: video.shortUUID })
847 }) 801 })
848 }) 802 })
849 803
@@ -851,80 +805,93 @@ describe('Test users API validators', function () {
851 const path = '/api/v1/accounts/user1/ratings' 805 const path = '/api/v1/accounts/user1/ratings'
852 806
853 it('Should fail with a bad start pagination', async function () { 807 it('Should fail with a bad start pagination', async function () {
854 await checkBadStartPagination(server.url, path, userAccessToken) 808 await checkBadStartPagination(server.url, path, userToken)
855 }) 809 })
856 810
857 it('Should fail with a bad count pagination', async function () { 811 it('Should fail with a bad count pagination', async function () {
858 await checkBadCountPagination(server.url, path, userAccessToken) 812 await checkBadCountPagination(server.url, path, userToken)
859 }) 813 })
860 814
861 it('Should fail with an incorrect sort', async function () { 815 it('Should fail with an incorrect sort', async function () {
862 await checkBadSortPagination(server.url, path, userAccessToken) 816 await checkBadSortPagination(server.url, path, userToken)
863 }) 817 })
864 818
865 it('Should fail with a unauthenticated user', async function () { 819 it('Should fail with a unauthenticated user', async function () {
866 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 820 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
867 }) 821 })
868 822
869 it('Should fail with a another user', async function () { 823 it('Should fail with a another user', async function () {
870 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 824 await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
871 }) 825 })
872 826
873 it('Should fail with a bad type', async function () { 827 it('Should fail with a bad type', async function () {
874 await makeGetRequest({ 828 await makeGetRequest({
875 url: server.url, 829 url: server.url,
876 path, 830 path,
877 token: userAccessToken, 831 token: userToken,
878 query: { rating: 'toto ' }, 832 query: { rating: 'toto ' },
879 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 833 expectedStatus: HttpStatusCode.BAD_REQUEST_400
880 }) 834 })
881 }) 835 })
882 836
883 it('Should succeed with the correct params', async function () { 837 it('Should succeed with the correct params', async function () {
884 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 }) 838 await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.OK_200 })
885 }) 839 })
886 }) 840 })
887 841
888 describe('When blocking/unblocking/removing user', function () { 842 describe('When blocking/unblocking/removing user', function () {
843
889 it('Should fail with an incorrect id', async function () { 844 it('Should fail with an incorrect id', async function () {
890 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 845 const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
891 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 846
892 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 847 await server.users.remove(options)
848 await server.users.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
849 await server.users.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
893 }) 850 })
894 851
895 it('Should fail with the root user', async function () { 852 it('Should fail with the root user', async function () {
896 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 853 const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
897 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 854
898 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 855 await server.users.remove(options)
856 await server.users.banUser(options)
857 await server.users.unbanUser(options)
899 }) 858 })
900 859
901 it('Should return 404 with a non existing id', async function () { 860 it('Should return 404 with a non existing id', async function () {
902 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 861 const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
903 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 862
904 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 863 await server.users.remove(options)
864 await server.users.banUser(options)
865 await server.users.unbanUser(options)
905 }) 866 })
906 867
907 it('Should fail with a non admin user', async function () { 868 it('Should fail with a non admin user', async function () {
908 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 869 const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
909 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 870
910 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 871 await server.users.remove(options)
872 await server.users.banUser(options)
873 await server.users.unbanUser(options)
911 }) 874 })
912 875
913 it('Should fail on a moderator with a moderator', async function () { 876 it('Should fail on a moderator with a moderator', async function () {
914 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 877 const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
915 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 878
916 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 879 await server.users.remove(options)
880 await server.users.banUser(options)
881 await server.users.unbanUser(options)
917 }) 882 })
918 883
919 it('Should succeed on a user with a moderator', async function () { 884 it('Should succeed on a user with a moderator', async function () {
920 await blockUser(server.url, userId, moderatorAccessToken) 885 const options = { userId, token: moderatorToken }
921 await unblockUser(server.url, userId, moderatorAccessToken) 886
887 await server.users.banUser(options)
888 await server.users.unbanUser(options)
922 }) 889 })
923 }) 890 })
924 891
925 describe('When deleting our account', function () { 892 describe('When deleting our account', function () {
926 it('Should fail with with the root account', async function () { 893 it('Should fail with with the root account', async function () {
927 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 894 await server.users.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
928 }) 895 })
929 }) 896 })
930 897
@@ -938,19 +905,19 @@ describe('Test users API validators', function () {
938 } 905 }
939 906
940 it('Should fail with a too small username', async function () { 907 it('Should fail with a too small username', async function () {
941 const fields = immutableAssign(baseCorrectParams, { username: '' }) 908 const fields = { ...baseCorrectParams, username: '' }
942 909
943 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 910 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
944 }) 911 })
945 912
946 it('Should fail with a too long username', async function () { 913 it('Should fail with a too long username', async function () {
947 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 914 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
948 915
949 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 916 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
950 }) 917 })
951 918
952 it('Should fail with an incorrect username', async function () { 919 it('Should fail with an incorrect username', async function () {
953 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 920 const fields = { ...baseCorrectParams, username: 'my username' }
954 921
955 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 922 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
956 }) 923 })
@@ -962,108 +929,108 @@ describe('Test users API validators', function () {
962 }) 929 })
963 930
964 it('Should fail with an invalid email', async function () { 931 it('Should fail with an invalid email', async function () {
965 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 932 const fields = { ...baseCorrectParams, email: 'test_example.com' }
966 933
967 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 934 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
968 }) 935 })
969 936
970 it('Should fail with a too small password', async function () { 937 it('Should fail with a too small password', async function () {
971 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 938 const fields = { ...baseCorrectParams, password: 'bla' }
972 939
973 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 940 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
974 }) 941 })
975 942
976 it('Should fail with a too long password', async function () { 943 it('Should fail with a too long password', async function () {
977 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 944 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
978 945
979 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 946 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
980 }) 947 })
981 948
982 it('Should fail if we register a user with the same username', async function () { 949 it('Should fail if we register a user with the same username', async function () {
983 const fields = immutableAssign(baseCorrectParams, { username: 'root' }) 950 const fields = { ...baseCorrectParams, username: 'root' }
984 951
985 await makePostBodyRequest({ 952 await makePostBodyRequest({
986 url: server.url, 953 url: server.url,
987 path: registrationPath, 954 path: registrationPath,
988 token: server.accessToken, 955 token: server.accessToken,
989 fields, 956 fields,
990 statusCodeExpected: HttpStatusCode.CONFLICT_409 957 expectedStatus: HttpStatusCode.CONFLICT_409
991 }) 958 })
992 }) 959 })
993 960
994 it('Should fail with a "peertube" username', async function () { 961 it('Should fail with a "peertube" username', async function () {
995 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 962 const fields = { ...baseCorrectParams, username: 'peertube' }
996 963
997 await makePostBodyRequest({ 964 await makePostBodyRequest({
998 url: server.url, 965 url: server.url,
999 path: registrationPath, 966 path: registrationPath,
1000 token: server.accessToken, 967 token: server.accessToken,
1001 fields, 968 fields,
1002 statusCodeExpected: HttpStatusCode.CONFLICT_409 969 expectedStatus: HttpStatusCode.CONFLICT_409
1003 }) 970 })
1004 }) 971 })
1005 972
1006 it('Should fail if we register a user with the same email', async function () { 973 it('Should fail if we register a user with the same email', async function () {
1007 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) 974 const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' }
1008 975
1009 await makePostBodyRequest({ 976 await makePostBodyRequest({
1010 url: server.url, 977 url: server.url,
1011 path: registrationPath, 978 path: registrationPath,
1012 token: server.accessToken, 979 token: server.accessToken,
1013 fields, 980 fields,
1014 statusCodeExpected: HttpStatusCode.CONFLICT_409 981 expectedStatus: HttpStatusCode.CONFLICT_409
1015 }) 982 })
1016 }) 983 })
1017 984
1018 it('Should fail with a bad display name', async function () { 985 it('Should fail with a bad display name', async function () {
1019 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) }) 986 const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) }
1020 987
1021 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 988 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1022 }) 989 })
1023 990
1024 it('Should fail with a bad channel name', async function () { 991 it('Should fail with a bad channel name', async function () {
1025 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } }) 992 const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } }
1026 993
1027 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 994 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1028 }) 995 })
1029 996
1030 it('Should fail with a bad channel display name', async function () { 997 it('Should fail with a bad channel display name', async function () {
1031 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } }) 998 const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } }
1032 999
1033 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1000 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1034 }) 1001 })
1035 1002
1036 it('Should fail with a channel name that is the same as username', async function () { 1003 it('Should fail with a channel name that is the same as username', async function () {
1037 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } } 1004 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1038 const fields = immutableAssign(baseCorrectParams, source) 1005 const fields = { ...baseCorrectParams, ...source }
1039 1006
1040 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1007 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1041 }) 1008 })
1042 1009
1043 it('Should fail with an existing channel', async function () { 1010 it('Should fail with an existing channel', async function () {
1044 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' } 1011 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1045 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg) 1012 await server.channels.create({ attributes })
1046 1013
1047 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) 1014 const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } }
1048 1015
1049 await makePostBodyRequest({ 1016 await makePostBodyRequest({
1050 url: server.url, 1017 url: server.url,
1051 path: registrationPath, 1018 path: registrationPath,
1052 token: server.accessToken, 1019 token: server.accessToken,
1053 fields, 1020 fields,
1054 statusCodeExpected: HttpStatusCode.CONFLICT_409 1021 expectedStatus: HttpStatusCode.CONFLICT_409
1055 }) 1022 })
1056 }) 1023 })
1057 1024
1058 it('Should succeed with the correct params', async function () { 1025 it('Should succeed with the correct params', async function () {
1059 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } }) 1026 const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } }
1060 1027
1061 await makePostBodyRequest({ 1028 await makePostBodyRequest({
1062 url: server.url, 1029 url: server.url,
1063 path: registrationPath, 1030 path: registrationPath,
1064 token: server.accessToken, 1031 token: server.accessToken,
1065 fields: fields, 1032 fields: fields,
1066 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 1033 expectedStatus: HttpStatusCode.NO_CONTENT_204
1067 }) 1034 })
1068 }) 1035 })
1069 1036
@@ -1079,14 +1046,14 @@ describe('Test users API validators', function () {
1079 path: registrationPath, 1046 path: registrationPath,
1080 token: serverWithRegistrationDisabled.accessToken, 1047 token: serverWithRegistrationDisabled.accessToken,
1081 fields, 1048 fields,
1082 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 1049 expectedStatus: HttpStatusCode.FORBIDDEN_403
1083 }) 1050 })
1084 }) 1051 })
1085 }) 1052 })
1086 1053
1087 describe('When registering multiple users on a server with users limit', function () { 1054 describe('When registering multiple users on a server with users limit', function () {
1088 it('Should fail when after 3 registrations', async function () { 1055 it('Should fail when after 3 registrations', async function () {
1089 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403) 1056 await server.users.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
1090 }) 1057 })
1091 }) 1058 })
1092 1059
@@ -1113,7 +1080,7 @@ describe('Test users API validators', function () {
1113 path, 1080 path,
1114 token: server.accessToken, 1081 token: server.accessToken,
1115 fields, 1082 fields,
1116 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 1083 expectedStatus: HttpStatusCode.NO_CONTENT_204
1117 }) 1084 })
1118 }) 1085 })
1119 }) 1086 })
@@ -1141,7 +1108,7 @@ describe('Test users API validators', function () {
1141 path, 1108 path,
1142 token: server.accessToken, 1109 token: server.accessToken,
1143 fields, 1110 fields,
1144 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 1111 expectedStatus: HttpStatusCode.NO_CONTENT_204
1145 }) 1112 })
1146 }) 1113 })
1147 }) 1114 })