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