]>
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, | |
97 | role: UserRole.USER | |
98 | } | |
99 | ||
0e1dc3e7 | 100 | it('Should fail with a too small username', async function () { |
26d21b78 | 101 | const fields = immutableAssign(baseCorrectParams, { username: 'fi' }) |
0e1dc3e7 C |
102 | |
103 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
104 | }) | |
105 | ||
106 | it('Should fail with a too long username', async function () { | |
26d21b78 | 107 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) |
0e1dc3e7 C |
108 | |
109 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
110 | }) | |
111 | ||
563d032e | 112 | it('Should fail with a not lowercase username', async function () { |
26d21b78 | 113 | const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) |
563d032e C |
114 | |
115 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
116 | }) | |
117 | ||
0e1dc3e7 | 118 | it('Should fail with an incorrect username', async function () { |
26d21b78 | 119 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) |
0e1dc3e7 C |
120 | |
121 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
122 | }) | |
123 | ||
124 | it('Should fail with a missing email', async function () { | |
26d21b78 | 125 | const fields = omit(baseCorrectParams, 'email') |
0e1dc3e7 C |
126 | |
127 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
128 | }) | |
129 | ||
130 | it('Should fail with an invalid email', async function () { | |
26d21b78 | 131 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) |
0e1dc3e7 C |
132 | |
133 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
134 | }) | |
135 | ||
136 | it('Should fail with a too small password', async function () { | |
26d21b78 | 137 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) |
0e1dc3e7 C |
138 | |
139 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
140 | }) | |
141 | ||
142 | it('Should fail with a too long password', async function () { | |
26d21b78 | 143 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) |
0e1dc3e7 C |
144 | |
145 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
146 | }) | |
147 | ||
148 | it('Should fail with an non authenticated user', async function () { | |
26d21b78 C |
149 | await makePostBodyRequest({ |
150 | url: server.url, | |
151 | path, | |
152 | token: 'super token', | |
153 | fields: baseCorrectParams, | |
154 | statusCodeExpected: 401 | |
155 | }) | |
0e1dc3e7 C |
156 | }) |
157 | ||
158 | it('Should fail if we add a user with the same username', async function () { | |
26d21b78 | 159 | const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) |
0e1dc3e7 C |
160 | |
161 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
162 | }) | |
163 | ||
164 | it('Should fail if we add a user with the same email', async function () { | |
26d21b78 | 165 | const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) |
0e1dc3e7 C |
166 | |
167 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
168 | }) | |
169 | ||
77a5501f | 170 | it('Should fail without a videoQuota', async function () { |
26d21b78 | 171 | const fields = omit(baseCorrectParams, 'videoQuota') |
77a5501f C |
172 | |
173 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
174 | }) | |
175 | ||
176 | it('Should fail with an invalid videoQuota', async function () { | |
26d21b78 | 177 | const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) |
757f0da3 C |
178 | |
179 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
180 | }) | |
181 | ||
182 | it('Should fail without a user role', async function () { | |
26d21b78 | 183 | const fields = omit(baseCorrectParams, 'role') |
757f0da3 C |
184 | |
185 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
186 | }) | |
187 | ||
188 | it('Should fail with an invalid user role', async function () { | |
26d21b78 | 189 | const fields = immutableAssign(baseCorrectParams, { role: 88989 }) |
77a5501f C |
190 | |
191 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
192 | }) | |
193 | ||
2ef6a063 C |
194 | it('Should fail with a "peertube" username', async function () { |
195 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
196 | ||
197 | await makePostBodyRequest({ | |
198 | url: server.url, | |
199 | path, | |
200 | token: server.accessToken, | |
201 | fields, | |
202 | statusCodeExpected: 409 | |
203 | }) | |
204 | }) | |
205 | ||
0e1dc3e7 | 206 | it('Should succeed with the correct params', async function () { |
26d21b78 C |
207 | await makePostBodyRequest({ |
208 | url: server.url, | |
209 | path, | |
210 | token: server.accessToken, | |
211 | fields: baseCorrectParams, | |
f05a1c30 | 212 | statusCodeExpected: 200 |
26d21b78 | 213 | }) |
0e1dc3e7 C |
214 | }) |
215 | ||
216 | it('Should fail with a non admin user', async function () { | |
26d21b78 | 217 | const user = { |
0e1dc3e7 | 218 | username: 'user1', |
0e1dc3e7 C |
219 | password: 'my super password' |
220 | } | |
26d21b78 | 221 | userAccessToken = await userLogin(server, user) |
0e1dc3e7 | 222 | |
0e1dc3e7 C |
223 | const fields = { |
224 | username: 'user3', | |
225 | email: 'test@example.com', | |
77a5501f C |
226 | password: 'my super password', |
227 | videoQuota: 42000000 | |
0e1dc3e7 C |
228 | } |
229 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | |
230 | }) | |
231 | }) | |
232 | ||
77a5501f C |
233 | describe('When updating my account', function () { |
234 | it('Should fail with an invalid email attribute', async function () { | |
235 | const fields = { | |
236 | email: 'blabla' | |
237 | } | |
0e1dc3e7 | 238 | |
77a5501f | 239 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields }) |
0e1dc3e7 C |
240 | }) |
241 | ||
242 | it('Should fail with a too small password', async function () { | |
243 | const fields = { | |
244 | password: 'bla' | |
245 | } | |
246 | ||
77a5501f | 247 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
248 | }) |
249 | ||
250 | it('Should fail with a too long password', async function () { | |
251 | const fields = { | |
26d21b78 | 252 | password: 'super'.repeat(61) |
0e1dc3e7 C |
253 | } |
254 | ||
77a5501f | 255 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
256 | }) |
257 | ||
0883b324 | 258 | it('Should fail with an invalid NSFW policy attribute', async function () { |
0e1dc3e7 | 259 | const fields = { |
0883b324 | 260 | nsfwPolicy: 'hello' |
0e1dc3e7 C |
261 | } |
262 | ||
77a5501f | 263 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
0e1dc3e7 C |
264 | }) |
265 | ||
7efe153b AL |
266 | it('Should fail with an invalid autoPlayVideo attribute', async function () { |
267 | const fields = { | |
268 | autoPlayVideo: -1 | |
269 | } | |
270 | ||
271 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
272 | }) | |
273 | ||
0e1dc3e7 C |
274 | it('Should fail with an non authenticated user', async function () { |
275 | const fields = { | |
276 | password: 'my super password' | |
277 | } | |
278 | ||
77a5501f | 279 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) |
0e1dc3e7 C |
280 | }) |
281 | ||
2422c46b C |
282 | it('Should fail with a too long description', async function () { |
283 | const fields = { | |
284 | description: 'super'.repeat(60) | |
285 | } | |
286 | ||
287 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
288 | }) | |
289 | ||
0e1dc3e7 C |
290 | it('Should succeed with the correct params', async function () { |
291 | const fields = { | |
292 | password: 'my super password', | |
0883b324 | 293 | nsfwPolicy: 'blur', |
7efe153b | 294 | autoPlayVideo: false, |
77a5501f | 295 | email: 'super_email@example.com' |
0e1dc3e7 C |
296 | } |
297 | ||
77a5501f C |
298 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) |
299 | }) | |
300 | }) | |
301 | ||
c5911fd3 C |
302 | describe('When updating my avatar', function () { |
303 | it('Should fail without an incorrect input file', async function () { | |
304 | const fields = {} | |
305 | const attaches = { | |
99d10301 | 306 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
c5911fd3 | 307 | } |
ac81d1a0 | 308 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
c5911fd3 C |
309 | }) |
310 | ||
01de67b9 C |
311 | it('Should fail with a big file', async function () { |
312 | const fields = {} | |
313 | const attaches = { | |
99d10301 | 314 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
01de67b9 | 315 | } |
ac81d1a0 | 316 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
01de67b9 C |
317 | }) |
318 | ||
4bbfc6c6 C |
319 | it('Should fail with an unauthenticated user', async function () { |
320 | const fields = {} | |
321 | const attaches = { | |
322 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
323 | } | |
324 | await makeUploadRequest({ | |
325 | url: server.url, | |
326 | path: path + '/me/avatar/pick', | |
327 | fields, | |
328 | attaches, | |
329 | statusCodeExpected: 401 | |
330 | }) | |
331 | }) | |
332 | ||
c5911fd3 C |
333 | it('Should succeed with the correct params', async function () { |
334 | const fields = {} | |
335 | const attaches = { | |
99d10301 | 336 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
c5911fd3 | 337 | } |
ac81d1a0 | 338 | await makeUploadRequest({ |
47564bbe C |
339 | url: server.url, |
340 | path: path + '/me/avatar/pick', | |
341 | token: server.accessToken, | |
342 | fields, | |
343 | attaches, | |
344 | statusCodeExpected: 200 | |
345 | }) | |
c5911fd3 C |
346 | }) |
347 | }) | |
348 | ||
94ff4c23 C |
349 | describe('When getting a user', function () { |
350 | before(async function () { | |
351 | const res = await getUsersList(server.url, server.accessToken) | |
352 | ||
353 | userId = res.body.data[1].id | |
354 | }) | |
355 | ||
356 | it('Should fail with an non authenticated user', async function () { | |
357 | await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 }) | |
358 | }) | |
359 | ||
360 | it('Should fail with a non admin user', async function () { | |
361 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 }) | |
362 | }) | |
363 | ||
364 | it('Should succeed with the correct params', async function () { | |
365 | await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 }) | |
366 | }) | |
367 | }) | |
368 | ||
77a5501f C |
369 | describe('When updating a user', function () { |
370 | ||
371 | before(async function () { | |
86d13ec2 | 372 | const res = await getUsersList(server.url, server.accessToken) |
77a5501f C |
373 | |
374 | userId = res.body.data[1].id | |
375 | rootId = res.body.data[2].id | |
376 | }) | |
377 | ||
378 | it('Should fail with an invalid email attribute', async function () { | |
379 | const fields = { | |
380 | email: 'blabla' | |
381 | } | |
382 | ||
383 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
384 | }) | |
385 | ||
386 | it('Should fail with an invalid videoQuota attribute', async function () { | |
387 | const fields = { | |
388 | videoQuota: -90 | |
389 | } | |
390 | ||
391 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
392 | }) | |
393 | ||
757f0da3 C |
394 | it('Should fail with an invalid user role attribute', async function () { |
395 | const fields = { | |
396 | role: 54878 | |
397 | } | |
398 | ||
399 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
400 | }) | |
401 | ||
77a5501f C |
402 | it('Should fail with an non authenticated user', async function () { |
403 | const fields = { | |
404 | videoQuota: 42 | |
405 | } | |
406 | ||
407 | await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) | |
408 | }) | |
409 | ||
f8b8c36b C |
410 | it('Should fail when updating root role', async function () { |
411 | const fields = { | |
412 | role: UserRole.MODERATOR | |
413 | } | |
414 | ||
415 | await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields }) | |
416 | }) | |
417 | ||
77a5501f C |
418 | it('Should succeed with the correct params', async function () { |
419 | const fields = { | |
420 | email: 'email@example.com', | |
757f0da3 C |
421 | videoQuota: 42, |
422 | role: UserRole.MODERATOR | |
77a5501f C |
423 | } |
424 | ||
425 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
f8b8c36b | 426 | userAccessToken = await userLogin(server, user) |
0e1dc3e7 C |
427 | }) |
428 | }) | |
429 | ||
430 | describe('When getting my information', function () { | |
431 | it('Should fail with a non authenticated user', async function () { | |
26d21b78 | 432 | await getMyUserInformation(server.url, 'fake_token', 401) |
0e1dc3e7 C |
433 | }) |
434 | ||
435 | it('Should success with the correct parameters', async function () { | |
26d21b78 | 436 | await getMyUserInformation(server.url, userAccessToken) |
0e1dc3e7 C |
437 | }) |
438 | }) | |
439 | ||
440 | describe('When getting my video rating', function () { | |
441 | it('Should fail with a non authenticated user', async function () { | |
26d21b78 | 442 | await getMyUserVideoRating(server.url, 'fake_token', videoId, 401) |
0e1dc3e7 C |
443 | }) |
444 | ||
445 | it('Should fail with an incorrect video uuid', async function () { | |
26d21b78 | 446 | await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400) |
0e1dc3e7 C |
447 | }) |
448 | ||
449 | it('Should fail with an unknown video', async function () { | |
26d21b78 | 450 | await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) |
0e1dc3e7 C |
451 | }) |
452 | ||
26d21b78 C |
453 | it('Should succeed with the correct parameters', async function () { |
454 | await getMyUserVideoRating(server.url, server.accessToken, videoId) | |
0e1dc3e7 C |
455 | }) |
456 | }) | |
457 | ||
e6921918 | 458 | describe('When blocking/unblocking/removing user', function () { |
0e1dc3e7 | 459 | it('Should fail with an incorrect id', async function () { |
26d21b78 | 460 | await removeUser(server.url, 'blabla', server.accessToken, 400) |
e6921918 C |
461 | await blockUser(server.url, 'blabla', server.accessToken, 400) |
462 | await unblockUser(server.url, 'blabla', server.accessToken, 400) | |
0e1dc3e7 C |
463 | }) |
464 | ||
465 | it('Should fail with the root user', async function () { | |
26d21b78 | 466 | await removeUser(server.url, rootId, server.accessToken, 400) |
e6921918 C |
467 | await blockUser(server.url, rootId, server.accessToken, 400) |
468 | await unblockUser(server.url, rootId, server.accessToken, 400) | |
0e1dc3e7 C |
469 | }) |
470 | ||
471 | it('Should return 404 with a non existing id', async function () { | |
26d21b78 | 472 | await removeUser(server.url, 4545454, server.accessToken, 404) |
e6921918 C |
473 | await blockUser(server.url, 4545454, server.accessToken, 404) |
474 | await unblockUser(server.url, 4545454, server.accessToken, 404) | |
475 | }) | |
476 | ||
477 | it('Should fail with a non admin user', async function () { | |
478 | await removeUser(server.url, userId, userAccessToken, 403) | |
479 | await blockUser(server.url, userId, userAccessToken, 403) | |
480 | await unblockUser(server.url, userId, userAccessToken, 403) | |
0e1dc3e7 C |
481 | }) |
482 | }) | |
483 | ||
92b9d60c C |
484 | describe('When deleting our account', function () { |
485 | it('Should fail with with the root account', async function () { | |
486 | await deleteMe(server.url, server.accessToken, 400) | |
487 | }) | |
488 | }) | |
489 | ||
0e1dc3e7 C |
490 | describe('When register a new user', function () { |
491 | const registrationPath = path + '/register' | |
26d21b78 C |
492 | const baseCorrectParams = { |
493 | username: 'user3', | |
494 | email: 'test3@example.com', | |
495 | password: 'my super password' | |
496 | } | |
0e1dc3e7 C |
497 | |
498 | it('Should fail with a too small username', async function () { | |
26d21b78 | 499 | const fields = immutableAssign(baseCorrectParams, { username: 'ji' }) |
0e1dc3e7 C |
500 | |
501 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
502 | }) | |
503 | ||
504 | it('Should fail with a too long username', async function () { | |
26d21b78 | 505 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) |
0e1dc3e7 C |
506 | |
507 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
508 | }) | |
509 | ||
510 | it('Should fail with an incorrect username', async function () { | |
26d21b78 | 511 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) |
0e1dc3e7 C |
512 | |
513 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
514 | }) | |
515 | ||
516 | it('Should fail with a missing email', async function () { | |
26d21b78 | 517 | const fields = omit(baseCorrectParams, 'email') |
0e1dc3e7 C |
518 | |
519 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
520 | }) | |
521 | ||
522 | it('Should fail with an invalid email', async function () { | |
26d21b78 | 523 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) |
0e1dc3e7 C |
524 | |
525 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
526 | }) | |
527 | ||
528 | it('Should fail with a too small password', async function () { | |
26d21b78 | 529 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) |
0e1dc3e7 C |
530 | |
531 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
532 | }) | |
533 | ||
534 | it('Should fail with a too long password', async function () { | |
26d21b78 | 535 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) |
0e1dc3e7 C |
536 | |
537 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
538 | }) | |
539 | ||
540 | it('Should fail if we register a user with the same username', async function () { | |
26d21b78 | 541 | const fields = immutableAssign(baseCorrectParams, { username: 'root' }) |
0e1dc3e7 | 542 | |
26d21b78 C |
543 | await makePostBodyRequest({ |
544 | url: server.url, | |
545 | path: registrationPath, | |
546 | token: server.accessToken, | |
547 | fields, | |
548 | statusCodeExpected: 409 | |
549 | }) | |
0e1dc3e7 C |
550 | }) |
551 | ||
2ef6a063 C |
552 | it('Should fail with a "peertube" username', async function () { |
553 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
554 | ||
555 | await makePostBodyRequest({ | |
556 | url: server.url, | |
557 | path: registrationPath, | |
558 | token: server.accessToken, | |
559 | fields, | |
560 | statusCodeExpected: 409 | |
561 | }) | |
562 | }) | |
563 | ||
0e1dc3e7 | 564 | it('Should fail if we register a user with the same email', async function () { |
26d21b78 | 565 | const fields = immutableAssign(baseCorrectParams, { email: 'admin1@example.com' }) |
0e1dc3e7 | 566 | |
26d21b78 C |
567 | await makePostBodyRequest({ |
568 | url: server.url, | |
569 | path: registrationPath, | |
570 | token: server.accessToken, | |
571 | fields, | |
572 | statusCodeExpected: 409 | |
573 | }) | |
0e1dc3e7 C |
574 | }) |
575 | ||
576 | it('Should succeed with the correct params', async function () { | |
26d21b78 C |
577 | await makePostBodyRequest({ |
578 | url: server.url, | |
579 | path: registrationPath, | |
580 | token: server.accessToken, | |
581 | fields: baseCorrectParams, | |
582 | statusCodeExpected: 204 | |
583 | }) | |
0e1dc3e7 C |
584 | }) |
585 | ||
586 | it('Should fail on a server with registration disabled', async function () { | |
587 | const fields = { | |
588 | username: 'user4', | |
589 | email: 'test4@example.com', | |
590 | password: 'my super password 4' | |
591 | } | |
592 | ||
593 | await makePostBodyRequest({ | |
594 | url: serverWithRegistrationDisabled.url, | |
595 | path: registrationPath, | |
596 | token: serverWithRegistrationDisabled.accessToken, | |
597 | fields, | |
598 | statusCodeExpected: 403 | |
599 | }) | |
600 | }) | |
601 | }) | |
602 | ||
603 | describe('When registering multiple users on a server with users limit', function () { | |
604 | it('Should fail when after 3 registrations', async function () { | |
605 | await registerUser(server.url, 'user42', 'super password', 403) | |
606 | }) | |
607 | }) | |
608 | ||
77a5501f C |
609 | describe('When having a video quota', function () { |
610 | it('Should fail with a user having too many video', async function () { | |
26d21b78 C |
611 | await updateUser({ |
612 | url: server.url, | |
613 | userId: rootId, | |
614 | accessToken: server.accessToken, | |
77a5501f | 615 | videoQuota: 42 |
26d21b78 | 616 | }) |
77a5501f | 617 | |
26d21b78 | 618 | await uploadVideo(server.url, server.accessToken, {}, 403) |
77a5501f C |
619 | }) |
620 | ||
621 | it('Should fail with a registered user having too many video', async function () { | |
adc236fe | 622 | this.timeout(30000) |
77a5501f | 623 | |
26d21b78 | 624 | const user = { |
77a5501f | 625 | username: 'user3', |
77a5501f C |
626 | password: 'my super password' |
627 | } | |
26d21b78 | 628 | userAccessToken = await userLogin(server, user) |
77a5501f C |
629 | |
630 | const videoAttributes = { fixture: 'video_short2.webm' } | |
631 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
632 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
633 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
634 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
635 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
636 | await uploadVideo(server.url, userAccessToken, videoAttributes, 403) | |
637 | }) | |
187501f8 C |
638 | |
639 | it('Should fail to import with HTTP/Torrent/magnet', async function () { | |
a031ab0b | 640 | this.timeout(120000) |
187501f8 C |
641 | |
642 | const baseAttributes = { | |
643 | channelId: 1, | |
644 | privacy: VideoPrivacy.PUBLIC | |
645 | } | |
646 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })) | |
647 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) | |
3e17515e | 648 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' })) |
187501f8 C |
649 | |
650 | await waitJobs([ server ]) | |
651 | ||
652 | const res = await getMyVideoImports(server.url, server.accessToken) | |
653 | ||
654 | expect(res.body.total).to.equal(3) | |
655 | const videoImports: VideoImport[] = res.body.data | |
656 | expect(videoImports).to.have.lengthOf(3) | |
657 | ||
658 | for (const videoImport of videoImports) { | |
659 | expect(videoImport.state.id).to.equal(VideoImportState.FAILED) | |
660 | expect(videoImport.error).not.to.be.undefined | |
661 | expect(videoImport.error).to.contain('user video quota is exceeded') | |
662 | } | |
663 | }) | |
77a5501f C |
664 | }) |
665 | ||
f076daa7 C |
666 | describe('When asking a password reset', function () { |
667 | const path = '/api/v1/users/ask-reset-password' | |
668 | ||
669 | it('Should fail with a missing email', async function () { | |
670 | const fields = {} | |
671 | ||
672 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
673 | }) | |
674 | ||
675 | it('Should fail with an invalid email', async function () { | |
676 | const fields = { email: 'hello' } | |
677 | ||
678 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
679 | }) | |
680 | ||
681 | it('Should success with the correct params', async function () { | |
682 | const fields = { email: 'admin@example.com' } | |
683 | ||
684 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
685 | }) | |
686 | }) | |
687 | ||
0e1dc3e7 C |
688 | after(async function () { |
689 | killallServers([ server, serverWithRegistrationDisabled ]) | |
690 | ||
691 | // Keep the logs if the test failed | |
692 | if (this['ok']) { | |
693 | await flushTests() | |
694 | } | |
695 | }) | |
696 | }) |