]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
26d21b78 | 3 | import { omit } from 'lodash' |
0e1dc3e7 | 4 | import 'mocha' |
47564bbe | 5 | import { join } from 'path' |
187501f8 | 6 | import { UserRole, VideoImport, VideoImportState } from '../../../../shared' |
0e1dc3e7 C |
7 | |
8 | import { | |
42e1ec25 | 9 | blockUser, |
7c3b7976 | 10 | cleanupTests, |
42e1ec25 C |
11 | createUser, |
12 | deleteMe, | |
13 | flushAndRunServer, | |
14 | getMyUserInformation, | |
15 | getMyUserVideoRating, | |
16 | getUsersList, | |
17 | immutableAssign, | |
42e1ec25 C |
18 | makeGetRequest, |
19 | makePostBodyRequest, | |
20 | makePutBodyRequest, | |
21 | makeUploadRequest, | |
22 | registerUser, | |
23 | removeUser, | |
24 | ServerInfo, | |
25 | setAccessTokensToServers, | |
26 | unblockUser, | |
27 | updateUser, | |
28 | uploadVideo, | |
29 | userLogin | |
94565d52 | 30 | } from '../../../../shared/extra-utils' |
9639bd17 | 31 | import { |
32 | checkBadCountPagination, | |
33 | checkBadSortPagination, | |
34 | checkBadStartPagination | |
94565d52 C |
35 | } from '../../../../shared/extra-utils/requests/check-api-params' |
36 | import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' | |
187501f8 | 37 | import { VideoPrivacy } from '../../../../shared/models/videos' |
94565d52 | 38 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
187501f8 | 39 | import { expect } from 'chai' |
1eddc9a7 | 40 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
0e1dc3e7 C |
41 | |
42 | describe('Test users API validators', function () { | |
43 | const path = '/api/v1/users/' | |
44 | let userId: number | |
45 | let rootId: number | |
46 | let videoId: number | |
47 | let server: ServerInfo | |
48 | let serverWithRegistrationDisabled: ServerInfo | |
49 | let userAccessToken = '' | |
187501f8 | 50 | let channelId: number |
f8b8c36b C |
51 | const user = { |
52 | username: 'user1', | |
53 | password: 'my super password' | |
54 | } | |
0e1dc3e7 C |
55 | |
56 | // --------------------------------------------------------------- | |
57 | ||
58 | before(async function () { | |
e212f887 | 59 | this.timeout(30000) |
0e1dc3e7 | 60 | |
210feb6c C |
61 | server = await flushAndRunServer(1) |
62 | serverWithRegistrationDisabled = await flushAndRunServer(2) | |
0e1dc3e7 C |
63 | |
64 | await setAccessTokensToServers([ server ]) | |
65 | ||
26d21b78 | 66 | const videoQuota = 42000000 |
1eddc9a7 C |
67 | await createUser({ |
68 | url: server.url, | |
69 | accessToken: server.accessToken, | |
70 | username: user.username, | |
71 | password: user.password, | |
72 | videoQuota: videoQuota | |
73 | }) | |
eec63bbc | 74 | userAccessToken = await userLogin(server, user) |
26d21b78 | 75 | |
187501f8 C |
76 | { |
77 | const res = await getMyUserInformation(server.url, server.accessToken) | |
78 | channelId = res.body.videoChannels[ 0 ].id | |
79 | } | |
80 | ||
81 | { | |
82 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
83 | videoId = res.body.video.id | |
84 | } | |
0e1dc3e7 C |
85 | }) |
86 | ||
87 | describe('When listing users', function () { | |
88 | it('Should fail with a bad start pagination', async function () { | |
26d21b78 | 89 | await checkBadStartPagination(server.url, path, server.accessToken) |
0e1dc3e7 C |
90 | }) |
91 | ||
92 | it('Should fail with a bad count pagination', async function () { | |
26d21b78 | 93 | await checkBadCountPagination(server.url, path, server.accessToken) |
0e1dc3e7 C |
94 | }) |
95 | ||
96 | it('Should fail with an incorrect sort', async function () { | |
26d21b78 | 97 | await checkBadSortPagination(server.url, path, server.accessToken) |
0e1dc3e7 | 98 | }) |
86d13ec2 C |
99 | |
100 | it('Should fail with a non authenticated user', async function () { | |
26d21b78 C |
101 | await makeGetRequest({ |
102 | url: server.url, | |
103 | path, | |
104 | statusCodeExpected: 401 | |
105 | }) | |
86d13ec2 C |
106 | }) |
107 | ||
108 | it('Should fail with a non admin user', async function () { | |
26d21b78 C |
109 | await makeGetRequest({ |
110 | url: server.url, | |
111 | path, | |
112 | token: userAccessToken, | |
113 | statusCodeExpected: 403 | |
114 | }) | |
86d13ec2 | 115 | }) |
0e1dc3e7 C |
116 | }) |
117 | ||
118 | describe('When adding a new user', function () { | |
26d21b78 C |
119 | const baseCorrectParams = { |
120 | username: 'user2', | |
121 | email: 'test@example.com', | |
122 | password: 'my super password', | |
123 | videoQuota: -1, | |
bee0abff | 124 | videoQuotaDaily: -1, |
1eddc9a7 C |
125 | role: UserRole.USER, |
126 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST | |
26d21b78 C |
127 | } |
128 | ||
0e1dc3e7 | 129 | it('Should fail with a too small username', async function () { |
d0ce42c1 | 130 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
0e1dc3e7 C |
131 | |
132 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
133 | }) | |
134 | ||
135 | it('Should fail with a too long username', async function () { | |
9f7a1953 | 136 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) |
0e1dc3e7 C |
137 | |
138 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
139 | }) | |
140 | ||
563d032e | 141 | it('Should fail with a not lowercase username', async function () { |
26d21b78 | 142 | const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) |
563d032e C |
143 | |
144 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
145 | }) | |
146 | ||
0e1dc3e7 | 147 | it('Should fail with an incorrect username', async function () { |
26d21b78 | 148 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) |
0e1dc3e7 C |
149 | |
150 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
151 | }) | |
152 | ||
153 | it('Should fail with a missing email', async function () { | |
26d21b78 | 154 | const fields = omit(baseCorrectParams, 'email') |
0e1dc3e7 C |
155 | |
156 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
157 | }) | |
158 | ||
159 | it('Should fail with an invalid email', async function () { | |
26d21b78 | 160 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) |
0e1dc3e7 C |
161 | |
162 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
163 | }) | |
164 | ||
165 | it('Should fail with a too small password', async function () { | |
26d21b78 | 166 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) |
0e1dc3e7 C |
167 | |
168 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
169 | }) | |
170 | ||
171 | it('Should fail with a too long password', async function () { | |
26d21b78 | 172 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) |
0e1dc3e7 C |
173 | |
174 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
175 | }) | |
176 | ||
1eddc9a7 C |
177 | it('Should fail with invalid admin flags', async function () { |
178 | const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) | |
179 | ||
180 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
181 | }) | |
182 | ||
0e1dc3e7 | 183 | it('Should fail with an non authenticated user', async function () { |
26d21b78 C |
184 | await makePostBodyRequest({ |
185 | url: server.url, | |
186 | path, | |
187 | token: 'super token', | |
188 | fields: baseCorrectParams, | |
189 | statusCodeExpected: 401 | |
190 | }) | |
0e1dc3e7 C |
191 | }) |
192 | ||
193 | it('Should fail if we add a user with the same username', async function () { | |
26d21b78 | 194 | const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) |
0e1dc3e7 C |
195 | |
196 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
197 | }) | |
198 | ||
199 | it('Should fail if we add a user with the same email', async function () { | |
26d21b78 | 200 | const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) |
0e1dc3e7 C |
201 | |
202 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
203 | }) | |
204 | ||
77a5501f | 205 | it('Should fail without a videoQuota', async function () { |
26d21b78 | 206 | const fields = omit(baseCorrectParams, 'videoQuota') |
77a5501f C |
207 | |
208 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
209 | }) | |
210 | ||
bee0abff FA |
211 | it('Should fail without a videoQuotaDaily', async function () { |
212 | const fields = omit(baseCorrectParams, 'videoQuotaDaily') | |
213 | ||
214 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
215 | }) | |
216 | ||
77a5501f | 217 | it('Should fail with an invalid videoQuota', async function () { |
26d21b78 | 218 | const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) |
757f0da3 C |
219 | |
220 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
221 | }) | |
222 | ||
bee0abff FA |
223 | it('Should fail with an invalid videoQuotaDaily', async function () { |
224 | const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) | |
225 | ||
226 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
227 | }) | |
228 | ||
757f0da3 | 229 | it('Should fail without a user role', async function () { |
26d21b78 | 230 | const fields = omit(baseCorrectParams, 'role') |
757f0da3 C |
231 | |
232 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
233 | }) | |
234 | ||
235 | it('Should fail with an invalid user role', async function () { | |
26d21b78 | 236 | const fields = immutableAssign(baseCorrectParams, { role: 88989 }) |
77a5501f C |
237 | |
238 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
239 | }) | |
240 | ||
2ef6a063 C |
241 | it('Should fail with a "peertube" username', async function () { |
242 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
243 | ||
244 | await makePostBodyRequest({ | |
245 | url: server.url, | |
246 | path, | |
247 | token: server.accessToken, | |
248 | fields, | |
249 | statusCodeExpected: 409 | |
250 | }) | |
251 | }) | |
252 | ||
0e1dc3e7 | 253 | it('Should succeed with the correct params', async function () { |
26d21b78 C |
254 | await makePostBodyRequest({ |
255 | url: server.url, | |
256 | path, | |
257 | token: server.accessToken, | |
258 | fields: baseCorrectParams, | |
f05a1c30 | 259 | statusCodeExpected: 200 |
26d21b78 | 260 | }) |
0e1dc3e7 C |
261 | }) |
262 | ||
263 | it('Should fail with a non admin user', async function () { | |
26d21b78 | 264 | const user = { |
0e1dc3e7 | 265 | username: 'user1', |
0e1dc3e7 C |
266 | password: 'my super password' |
267 | } | |
26d21b78 | 268 | userAccessToken = await userLogin(server, user) |
0e1dc3e7 | 269 | |
0e1dc3e7 C |
270 | const fields = { |
271 | username: 'user3', | |
272 | email: 'test@example.com', | |
77a5501f C |
273 | password: 'my super password', |
274 | videoQuota: 42000000 | |
0e1dc3e7 C |
275 | } |
276 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | |
277 | }) | |
278 | }) | |
279 | ||
77a5501f C |
280 | describe('When updating my account', function () { |
281 | it('Should fail with an invalid email attribute', async function () { | |
282 | const fields = { | |
283 | email: 'blabla' | |
284 | } | |
0e1dc3e7 | 285 | |
77a5501f | 286 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields }) |
0e1dc3e7 C |
287 | }) |
288 | ||
289 | it('Should fail with a too small password', async function () { | |
290 | const fields = { | |
a890d1e0 | 291 | currentPassword: 'my super password', |
0e1dc3e7 C |
292 | password: 'bla' |
293 | } | |
294 | ||
77a5501f | 295 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
296 | }) |
297 | ||
298 | it('Should fail with a too long password', async function () { | |
299 | const fields = { | |
a890d1e0 | 300 | currentPassword: 'my super password', |
26d21b78 | 301 | password: 'super'.repeat(61) |
0e1dc3e7 C |
302 | } |
303 | ||
77a5501f | 304 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
305 | }) |
306 | ||
a890d1e0 C |
307 | it('Should fail without the current password', async function () { |
308 | const fields = { | |
309 | currentPassword: 'my super password', | |
310 | password: 'super'.repeat(61) | |
311 | } | |
312 | ||
313 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
314 | }) | |
315 | ||
316 | it('Should fail with an invalid current password', async function () { | |
317 | const fields = { | |
318 | currentPassword: 'my super password fail', | |
319 | password: 'super'.repeat(61) | |
320 | } | |
321 | ||
322 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 }) | |
323 | }) | |
324 | ||
0883b324 | 325 | it('Should fail with an invalid NSFW policy attribute', async function () { |
0e1dc3e7 | 326 | const fields = { |
0883b324 | 327 | nsfwPolicy: 'hello' |
0e1dc3e7 C |
328 | } |
329 | ||
77a5501f | 330 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
331 | }) |
332 | ||
7efe153b AL |
333 | it('Should fail with an invalid autoPlayVideo attribute', async function () { |
334 | const fields = { | |
335 | autoPlayVideo: -1 | |
336 | } | |
337 | ||
338 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
339 | }) | |
340 | ||
8b9a525a C |
341 | it('Should fail with an invalid videosHistoryEnabled attribute', async function () { |
342 | const fields = { | |
343 | videosHistoryEnabled: -1 | |
344 | } | |
345 | ||
346 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
347 | }) | |
348 | ||
0e1dc3e7 C |
349 | it('Should fail with an non authenticated user', async function () { |
350 | const fields = { | |
a890d1e0 | 351 | currentPassword: 'my super password', |
0e1dc3e7 C |
352 | password: 'my super password' |
353 | } | |
354 | ||
77a5501f | 355 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) |
0e1dc3e7 C |
356 | }) |
357 | ||
2422c46b C |
358 | it('Should fail with a too long description', async function () { |
359 | const fields = { | |
d23e6a1c | 360 | description: 'super'.repeat(201) |
2422c46b C |
361 | } |
362 | ||
363 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
364 | }) | |
365 | ||
a890d1e0 | 366 | it('Should succeed to change password with the correct params', async function () { |
0e1dc3e7 | 367 | const fields = { |
a890d1e0 | 368 | currentPassword: 'my super password', |
0e1dc3e7 | 369 | password: 'my super password', |
0883b324 | 370 | nsfwPolicy: 'blur', |
7efe153b | 371 | autoPlayVideo: false, |
77a5501f | 372 | email: 'super_email@example.com' |
0e1dc3e7 C |
373 | } |
374 | ||
77a5501f C |
375 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) |
376 | }) | |
a890d1e0 C |
377 | |
378 | it('Should succeed without password change with the correct params', async function () { | |
379 | const fields = { | |
380 | nsfwPolicy: 'blur', | |
381 | autoPlayVideo: false, | |
382 | email: 'super_email@example.com' | |
383 | } | |
384 | ||
385 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) | |
386 | }) | |
77a5501f C |
387 | }) |
388 | ||
c5911fd3 C |
389 | describe('When updating my avatar', function () { |
390 | it('Should fail without an incorrect input file', async function () { | |
391 | const fields = {} | |
392 | const attaches = { | |
99d10301 | 393 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
c5911fd3 | 394 | } |
ac81d1a0 | 395 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
c5911fd3 C |
396 | }) |
397 | ||
01de67b9 C |
398 | it('Should fail with a big file', async function () { |
399 | const fields = {} | |
400 | const attaches = { | |
99d10301 | 401 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
01de67b9 | 402 | } |
ac81d1a0 | 403 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
01de67b9 C |
404 | }) |
405 | ||
4bbfc6c6 C |
406 | it('Should fail with an unauthenticated user', async function () { |
407 | const fields = {} | |
408 | const attaches = { | |
409 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
410 | } | |
411 | await makeUploadRequest({ | |
412 | url: server.url, | |
413 | path: path + '/me/avatar/pick', | |
414 | fields, | |
415 | attaches, | |
416 | statusCodeExpected: 401 | |
417 | }) | |
418 | }) | |
419 | ||
c5911fd3 C |
420 | it('Should succeed with the correct params', async function () { |
421 | const fields = {} | |
422 | const attaches = { | |
99d10301 | 423 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
c5911fd3 | 424 | } |
ac81d1a0 | 425 | await makeUploadRequest({ |
47564bbe C |
426 | url: server.url, |
427 | path: path + '/me/avatar/pick', | |
428 | token: server.accessToken, | |
429 | fields, | |
430 | attaches, | |
431 | statusCodeExpected: 200 | |
432 | }) | |
c5911fd3 C |
433 | }) |
434 | }) | |
435 | ||
94ff4c23 C |
436 | describe('When getting a user', function () { |
437 | before(async function () { | |
438 | const res = await getUsersList(server.url, server.accessToken) | |
439 | ||
440 | userId = res.body.data[1].id | |
441 | }) | |
442 | ||
443 | it('Should fail with an non authenticated user', async function () { | |
444 | await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 }) | |
445 | }) | |
446 | ||
447 | it('Should fail with a non admin user', async function () { | |
448 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 }) | |
449 | }) | |
450 | ||
451 | it('Should succeed with the correct params', async function () { | |
452 | await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 }) | |
453 | }) | |
454 | }) | |
455 | ||
77a5501f C |
456 | describe('When updating a user', function () { |
457 | ||
458 | before(async function () { | |
86d13ec2 | 459 | const res = await getUsersList(server.url, server.accessToken) |
77a5501f C |
460 | |
461 | userId = res.body.data[1].id | |
462 | rootId = res.body.data[2].id | |
463 | }) | |
464 | ||
465 | it('Should fail with an invalid email attribute', async function () { | |
466 | const fields = { | |
467 | email: 'blabla' | |
468 | } | |
469 | ||
470 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
471 | }) | |
472 | ||
fc2ec87a JM |
473 | it('Should fail with an invalid emailVerified attribute', async function () { |
474 | const fields = { | |
475 | emailVerified: 'yes' | |
476 | } | |
477 | ||
478 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
479 | }) | |
480 | ||
77a5501f C |
481 | it('Should fail with an invalid videoQuota attribute', async function () { |
482 | const fields = { | |
483 | videoQuota: -90 | |
484 | } | |
485 | ||
486 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
487 | }) | |
488 | ||
757f0da3 C |
489 | it('Should fail with an invalid user role attribute', async function () { |
490 | const fields = { | |
491 | role: 54878 | |
492 | } | |
493 | ||
494 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
495 | }) | |
496 | ||
b426edd4 C |
497 | it('Should fail with a too small password', async function () { |
498 | const fields = { | |
499 | currentPassword: 'my super password', | |
500 | password: 'bla' | |
501 | } | |
502 | ||
503 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
504 | }) | |
505 | ||
506 | it('Should fail with a too long password', async function () { | |
507 | const fields = { | |
508 | currentPassword: 'my super password', | |
509 | password: 'super'.repeat(61) | |
510 | } | |
511 | ||
512 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
513 | }) | |
514 | ||
77a5501f C |
515 | it('Should fail with an non authenticated user', async function () { |
516 | const fields = { | |
517 | videoQuota: 42 | |
518 | } | |
519 | ||
520 | await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) | |
521 | }) | |
522 | ||
f8b8c36b C |
523 | it('Should fail when updating root role', async function () { |
524 | const fields = { | |
525 | role: UserRole.MODERATOR | |
526 | } | |
527 | ||
528 | await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields }) | |
1eddc9a7 C |
529 | }) |
530 | ||
531 | it('Should fail with invalid admin flags', async function () { | |
532 | const fields = { adminFlags: 'toto' } | |
533 | ||
534 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
f8b8c36b C |
535 | }) |
536 | ||
77a5501f C |
537 | it('Should succeed with the correct params', async function () { |
538 | const fields = { | |
539 | email: 'email@example.com', | |
fc2ec87a | 540 | emailVerified: true, |
757f0da3 | 541 | videoQuota: 42, |
2f1548fd | 542 | role: UserRole.USER |
77a5501f C |
543 | } |
544 | ||
545 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
0e1dc3e7 C |
546 | }) |
547 | }) | |
548 | ||
549 | describe('When getting my information', function () { | |
550 | it('Should fail with a non authenticated user', async function () { | |
26d21b78 | 551 | await getMyUserInformation(server.url, 'fake_token', 401) |
0e1dc3e7 C |
552 | }) |
553 | ||
554 | it('Should success with the correct parameters', async function () { | |
26d21b78 | 555 | await getMyUserInformation(server.url, userAccessToken) |
0e1dc3e7 C |
556 | }) |
557 | }) | |
558 | ||
559 | describe('When getting my video rating', function () { | |
560 | it('Should fail with a non authenticated user', async function () { | |
26d21b78 | 561 | await getMyUserVideoRating(server.url, 'fake_token', videoId, 401) |
0e1dc3e7 C |
562 | }) |
563 | ||
564 | it('Should fail with an incorrect video uuid', async function () { | |
26d21b78 | 565 | await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400) |
0e1dc3e7 C |
566 | }) |
567 | ||
568 | it('Should fail with an unknown video', async function () { | |
26d21b78 | 569 | await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) |
0e1dc3e7 C |
570 | }) |
571 | ||
26d21b78 C |
572 | it('Should succeed with the correct parameters', async function () { |
573 | await getMyUserVideoRating(server.url, server.accessToken, videoId) | |
0e1dc3e7 C |
574 | }) |
575 | }) | |
576 | ||
22834691 C |
577 | describe('When retrieving my global ratings', function () { |
578 | const path = '/api/v1/accounts/user1/ratings' | |
579 | ||
580 | it('Should fail with a bad start pagination', async function () { | |
581 | await checkBadStartPagination(server.url, path, userAccessToken) | |
582 | }) | |
583 | ||
584 | it('Should fail with a bad count pagination', async function () { | |
585 | await checkBadCountPagination(server.url, path, userAccessToken) | |
586 | }) | |
587 | ||
588 | it('Should fail with an incorrect sort', async function () { | |
589 | await checkBadSortPagination(server.url, path, userAccessToken) | |
590 | }) | |
591 | ||
592 | it('Should fail with a unauthenticated user', async function () { | |
593 | await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) | |
594 | }) | |
595 | ||
596 | it('Should fail with a another user', async function () { | |
597 | await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) | |
598 | }) | |
599 | ||
600 | it('Should fail with a bad type', async function () { | |
601 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) | |
602 | }) | |
603 | ||
604 | it('Should succeed with the correct params', async function () { | |
605 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) | |
606 | }) | |
607 | }) | |
608 | ||
e6921918 | 609 | describe('When blocking/unblocking/removing user', function () { |
0e1dc3e7 | 610 | it('Should fail with an incorrect id', async function () { |
26d21b78 | 611 | await removeUser(server.url, 'blabla', server.accessToken, 400) |
e6921918 C |
612 | await blockUser(server.url, 'blabla', server.accessToken, 400) |
613 | await unblockUser(server.url, 'blabla', server.accessToken, 400) | |
0e1dc3e7 C |
614 | }) |
615 | ||
616 | it('Should fail with the root user', async function () { | |
26d21b78 | 617 | await removeUser(server.url, rootId, server.accessToken, 400) |
e6921918 C |
618 | await blockUser(server.url, rootId, server.accessToken, 400) |
619 | await unblockUser(server.url, rootId, server.accessToken, 400) | |
0e1dc3e7 C |
620 | }) |
621 | ||
622 | it('Should return 404 with a non existing id', async function () { | |
26d21b78 | 623 | await removeUser(server.url, 4545454, server.accessToken, 404) |
e6921918 C |
624 | await blockUser(server.url, 4545454, server.accessToken, 404) |
625 | await unblockUser(server.url, 4545454, server.accessToken, 404) | |
626 | }) | |
627 | ||
628 | it('Should fail with a non admin user', async function () { | |
629 | await removeUser(server.url, userId, userAccessToken, 403) | |
630 | await blockUser(server.url, userId, userAccessToken, 403) | |
631 | await unblockUser(server.url, userId, userAccessToken, 403) | |
0e1dc3e7 C |
632 | }) |
633 | }) | |
634 | ||
92b9d60c C |
635 | describe('When deleting our account', function () { |
636 | it('Should fail with with the root account', async function () { | |
637 | await deleteMe(server.url, server.accessToken, 400) | |
638 | }) | |
639 | }) | |
640 | ||
0e1dc3e7 C |
641 | describe('When register a new user', function () { |
642 | const registrationPath = path + '/register' | |
26d21b78 C |
643 | const baseCorrectParams = { |
644 | username: 'user3', | |
645 | email: 'test3@example.com', | |
646 | password: 'my super password' | |
647 | } | |
0e1dc3e7 C |
648 | |
649 | it('Should fail with a too small username', async function () { | |
d0ce42c1 | 650 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
0e1dc3e7 C |
651 | |
652 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
653 | }) | |
654 | ||
655 | it('Should fail with a too long username', async function () { | |
9f7a1953 | 656 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) |
0e1dc3e7 C |
657 | |
658 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
659 | }) | |
660 | ||
661 | it('Should fail with an incorrect username', async function () { | |
26d21b78 | 662 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) |
0e1dc3e7 C |
663 | |
664 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
665 | }) | |
666 | ||
667 | it('Should fail with a missing email', async function () { | |
26d21b78 | 668 | const fields = omit(baseCorrectParams, 'email') |
0e1dc3e7 C |
669 | |
670 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
671 | }) | |
672 | ||
673 | it('Should fail with an invalid email', async function () { | |
26d21b78 | 674 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) |
0e1dc3e7 C |
675 | |
676 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
677 | }) | |
678 | ||
679 | it('Should fail with a too small password', async function () { | |
26d21b78 | 680 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) |
0e1dc3e7 C |
681 | |
682 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
683 | }) | |
684 | ||
685 | it('Should fail with a too long password', async function () { | |
26d21b78 | 686 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) |
0e1dc3e7 C |
687 | |
688 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
689 | }) | |
690 | ||
691 | it('Should fail if we register a user with the same username', async function () { | |
26d21b78 | 692 | const fields = immutableAssign(baseCorrectParams, { username: 'root' }) |
0e1dc3e7 | 693 | |
26d21b78 C |
694 | await makePostBodyRequest({ |
695 | url: server.url, | |
696 | path: registrationPath, | |
697 | token: server.accessToken, | |
698 | fields, | |
699 | statusCodeExpected: 409 | |
700 | }) | |
0e1dc3e7 C |
701 | }) |
702 | ||
2ef6a063 C |
703 | it('Should fail with a "peertube" username', async function () { |
704 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
705 | ||
706 | await makePostBodyRequest({ | |
707 | url: server.url, | |
708 | path: registrationPath, | |
709 | token: server.accessToken, | |
710 | fields, | |
711 | statusCodeExpected: 409 | |
712 | }) | |
713 | }) | |
714 | ||
0e1dc3e7 | 715 | it('Should fail if we register a user with the same email', async function () { |
7c3b7976 | 716 | const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) |
0e1dc3e7 | 717 | |
26d21b78 C |
718 | await makePostBodyRequest({ |
719 | url: server.url, | |
720 | path: registrationPath, | |
721 | token: server.accessToken, | |
722 | fields, | |
723 | statusCodeExpected: 409 | |
724 | }) | |
0e1dc3e7 C |
725 | }) |
726 | ||
727 | it('Should succeed with the correct params', async function () { | |
26d21b78 C |
728 | await makePostBodyRequest({ |
729 | url: server.url, | |
730 | path: registrationPath, | |
731 | token: server.accessToken, | |
732 | fields: baseCorrectParams, | |
733 | statusCodeExpected: 204 | |
734 | }) | |
0e1dc3e7 C |
735 | }) |
736 | ||
737 | it('Should fail on a server with registration disabled', async function () { | |
738 | const fields = { | |
739 | username: 'user4', | |
740 | email: 'test4@example.com', | |
741 | password: 'my super password 4' | |
742 | } | |
743 | ||
744 | await makePostBodyRequest({ | |
745 | url: serverWithRegistrationDisabled.url, | |
746 | path: registrationPath, | |
747 | token: serverWithRegistrationDisabled.accessToken, | |
748 | fields, | |
749 | statusCodeExpected: 403 | |
750 | }) | |
751 | }) | |
752 | }) | |
753 | ||
754 | describe('When registering multiple users on a server with users limit', function () { | |
755 | it('Should fail when after 3 registrations', async function () { | |
756 | await registerUser(server.url, 'user42', 'super password', 403) | |
757 | }) | |
758 | }) | |
759 | ||
77a5501f | 760 | describe('When having a video quota', function () { |
bee0abff | 761 | it('Should fail with a user having too many videos', async function () { |
26d21b78 C |
762 | await updateUser({ |
763 | url: server.url, | |
764 | userId: rootId, | |
765 | accessToken: server.accessToken, | |
77a5501f | 766 | videoQuota: 42 |
26d21b78 | 767 | }) |
77a5501f | 768 | |
26d21b78 | 769 | await uploadVideo(server.url, server.accessToken, {}, 403) |
77a5501f C |
770 | }) |
771 | ||
bee0abff | 772 | it('Should fail with a registered user having too many videos', async function () { |
adc236fe | 773 | this.timeout(30000) |
77a5501f | 774 | |
26d21b78 | 775 | const user = { |
77a5501f | 776 | username: 'user3', |
77a5501f C |
777 | password: 'my super password' |
778 | } | |
26d21b78 | 779 | userAccessToken = await userLogin(server, user) |
77a5501f C |
780 | |
781 | const videoAttributes = { fixture: 'video_short2.webm' } | |
782 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
783 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
784 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
785 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
786 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
787 | await uploadVideo(server.url, userAccessToken, videoAttributes, 403) | |
788 | }) | |
187501f8 C |
789 | |
790 | it('Should fail to import with HTTP/Torrent/magnet', async function () { | |
a031ab0b | 791 | this.timeout(120000) |
187501f8 C |
792 | |
793 | const baseAttributes = { | |
794 | channelId: 1, | |
795 | privacy: VideoPrivacy.PUBLIC | |
796 | } | |
797 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })) | |
798 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) | |
3e17515e | 799 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' })) |
187501f8 C |
800 | |
801 | await waitJobs([ server ]) | |
802 | ||
803 | const res = await getMyVideoImports(server.url, server.accessToken) | |
804 | ||
805 | expect(res.body.total).to.equal(3) | |
806 | const videoImports: VideoImport[] = res.body.data | |
807 | expect(videoImports).to.have.lengthOf(3) | |
808 | ||
809 | for (const videoImport of videoImports) { | |
810 | expect(videoImport.state.id).to.equal(VideoImportState.FAILED) | |
811 | expect(videoImport.error).not.to.be.undefined | |
812 | expect(videoImport.error).to.contain('user video quota is exceeded') | |
813 | } | |
814 | }) | |
77a5501f C |
815 | }) |
816 | ||
bee0abff FA |
817 | describe('When having a daily video quota', function () { |
818 | it('Should fail with a user having too many videos', async function () { | |
819 | await updateUser({ | |
820 | url: server.url, | |
821 | userId: rootId, | |
822 | accessToken: server.accessToken, | |
823 | videoQuotaDaily: 42 | |
824 | }) | |
825 | ||
826 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
827 | }) | |
828 | }) | |
829 | ||
830 | describe('When having an absolute and daily video quota', function () { | |
831 | it('Should fail if exceeding total quota', async function () { | |
832 | await updateUser({ | |
833 | url: server.url, | |
834 | userId: rootId, | |
835 | accessToken: server.accessToken, | |
836 | videoQuota: 42, | |
837 | videoQuotaDaily: 1024 * 1024 * 1024 | |
838 | }) | |
839 | ||
840 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
841 | }) | |
842 | ||
843 | it('Should fail if exceeding daily quota', async function () { | |
844 | await updateUser({ | |
845 | url: server.url, | |
846 | userId: rootId, | |
847 | accessToken: server.accessToken, | |
848 | videoQuota: 1024 * 1024 * 1024, | |
849 | videoQuotaDaily: 42 | |
850 | }) | |
851 | ||
852 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
853 | }) | |
854 | }) | |
855 | ||
f076daa7 C |
856 | describe('When asking a password reset', function () { |
857 | const path = '/api/v1/users/ask-reset-password' | |
858 | ||
859 | it('Should fail with a missing email', async function () { | |
860 | const fields = {} | |
861 | ||
862 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
863 | }) | |
864 | ||
865 | it('Should fail with an invalid email', async function () { | |
866 | const fields = { email: 'hello' } | |
867 | ||
868 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
869 | }) | |
870 | ||
871 | it('Should success with the correct params', async function () { | |
872 | const fields = { email: 'admin@example.com' } | |
873 | ||
874 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
875 | }) | |
876 | }) | |
877 | ||
d9eaee39 JM |
878 | describe('When asking for an account verification email', function () { |
879 | const path = '/api/v1/users/ask-send-verify-email' | |
880 | ||
881 | it('Should fail with a missing email', async function () { | |
882 | const fields = {} | |
883 | ||
884 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
885 | }) | |
886 | ||
887 | it('Should fail with an invalid email', async function () { | |
888 | const fields = { email: 'hello' } | |
889 | ||
890 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
891 | }) | |
892 | ||
893 | it('Should succeed with the correct params', async function () { | |
894 | const fields = { email: 'admin@example.com' } | |
895 | ||
896 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
897 | }) | |
898 | }) | |
899 | ||
7c3b7976 C |
900 | after(async function () { |
901 | await cleanupTests([ server, serverWithRegistrationDisabled ]) | |
0e1dc3e7 C |
902 | }) |
903 | }) |