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