]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/blocklist.ts
Merge branch 'feature/webtorrent-disabling' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / blocklist.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4
5 import {
6 createUser,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 flushTests,
10 killallServers,
11 makeDeleteRequest,
12 makeGetRequest,
13 makePostBodyRequest,
14 ServerInfo,
15 setAccessTokensToServers, userLogin
16 } from '../../utils'
17 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
18
19 describe('Test blocklist API validators', function () {
20 let servers: ServerInfo[]
21 let server: ServerInfo
22 let userAccessToken: string
23
24 before(async function () {
25 this.timeout(60000)
26
27 await flushTests()
28
29 servers = await flushAndRunMultipleServers(2)
30 await setAccessTokensToServers(servers)
31
32 server = servers[0]
33
34 const user = { username: 'user1', password: 'password' }
35 await createUser(server.url, server.accessToken, user.username, user.password)
36
37 userAccessToken = await userLogin(server, user)
38
39 await doubleFollow(servers[0], servers[1])
40 })
41
42 // ---------------------------------------------------------------
43
44 describe('When managing user blocklist', function () {
45
46 describe('When managing user accounts blocklist', function () {
47 const path = '/api/v1/users/me/blocklist/accounts'
48
49 describe('When listing blocked accounts', function () {
50 it('Should fail with an unauthenticated user', async function () {
51 await makeGetRequest({
52 url: server.url,
53 path,
54 statusCodeExpected: 401
55 })
56 })
57
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, path, server.accessToken)
60 })
61
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, path, server.accessToken)
64 })
65
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, path, server.accessToken)
68 })
69 })
70
71 describe('When blocking an account', function () {
72 it('Should fail with an unauthenticated user', async function () {
73 await makePostBodyRequest({
74 url: server.url,
75 path,
76 fields: { accountName: 'user1' },
77 statusCodeExpected: 401
78 })
79 })
80
81 it('Should fail with an unknown account', async function () {
82 await makePostBodyRequest({
83 url: server.url,
84 token: server.accessToken,
85 path,
86 fields: { accountName: 'user2' },
87 statusCodeExpected: 404
88 })
89 })
90
91 it('Should fail to block ourselves', async function () {
92 await makePostBodyRequest({
93 url: server.url,
94 token: server.accessToken,
95 path,
96 fields: { accountName: 'root' },
97 statusCodeExpected: 409
98 })
99 })
100
101 it('Should succeed with the correct params', async function () {
102 await makePostBodyRequest({
103 url: server.url,
104 token: server.accessToken,
105 path,
106 fields: { accountName: 'user1' },
107 statusCodeExpected: 204
108 })
109 })
110 })
111
112 describe('When unblocking an account', function () {
113 it('Should fail with an unauthenticated user', async function () {
114 await makeDeleteRequest({
115 url: server.url,
116 path: path + '/user1',
117 statusCodeExpected: 401
118 })
119 })
120
121 it('Should fail with an unknown account block', async function () {
122 await makeDeleteRequest({
123 url: server.url,
124 path: path + '/user2',
125 token: server.accessToken,
126 statusCodeExpected: 404
127 })
128 })
129
130 it('Should succeed with the correct params', async function () {
131 await makeDeleteRequest({
132 url: server.url,
133 path: path + '/user1',
134 token: server.accessToken,
135 statusCodeExpected: 204
136 })
137 })
138 })
139 })
140
141 describe('When managing user servers blocklist', function () {
142 const path = '/api/v1/users/me/blocklist/servers'
143
144 describe('When listing blocked servers', function () {
145 it('Should fail with an unauthenticated user', async function () {
146 await makeGetRequest({
147 url: server.url,
148 path,
149 statusCodeExpected: 401
150 })
151 })
152
153 it('Should fail with a bad start pagination', async function () {
154 await checkBadStartPagination(server.url, path, server.accessToken)
155 })
156
157 it('Should fail with a bad count pagination', async function () {
158 await checkBadCountPagination(server.url, path, server.accessToken)
159 })
160
161 it('Should fail with an incorrect sort', async function () {
162 await checkBadSortPagination(server.url, path, server.accessToken)
163 })
164 })
165
166 describe('When blocking a server', function () {
167 it('Should fail with an unauthenticated user', async function () {
168 await makePostBodyRequest({
169 url: server.url,
170 path,
171 fields: { host: 'localhost:9002' },
172 statusCodeExpected: 401
173 })
174 })
175
176 it('Should fail with an unknown server', async function () {
177 await makePostBodyRequest({
178 url: server.url,
179 token: server.accessToken,
180 path,
181 fields: { host: 'localhost:9003' },
182 statusCodeExpected: 404
183 })
184 })
185
186 it('Should fail with our own server', async function () {
187 await makePostBodyRequest({
188 url: server.url,
189 token: server.accessToken,
190 path,
191 fields: { host: 'localhost:9001' },
192 statusCodeExpected: 409
193 })
194 })
195
196 it('Should succeed with the correct params', async function () {
197 await makePostBodyRequest({
198 url: server.url,
199 token: server.accessToken,
200 path,
201 fields: { host: 'localhost:9002' },
202 statusCodeExpected: 204
203 })
204 })
205 })
206
207 describe('When unblocking a server', function () {
208 it('Should fail with an unauthenticated user', async function () {
209 await makeDeleteRequest({
210 url: server.url,
211 path: path + '/localhost:9002',
212 statusCodeExpected: 401
213 })
214 })
215
216 it('Should fail with an unknown server block', async function () {
217 await makeDeleteRequest({
218 url: server.url,
219 path: path + '/localhost:9003',
220 token: server.accessToken,
221 statusCodeExpected: 404
222 })
223 })
224
225 it('Should succeed with the correct params', async function () {
226 await makeDeleteRequest({
227 url: server.url,
228 path: path + '/localhost:9002',
229 token: server.accessToken,
230 statusCodeExpected: 204
231 })
232 })
233 })
234 })
235 })
236
237 describe('When managing server blocklist', function () {
238
239 describe('When managing server accounts blocklist', function () {
240 const path = '/api/v1/server/blocklist/accounts'
241
242 describe('When listing blocked accounts', function () {
243 it('Should fail with an unauthenticated user', async function () {
244 await makeGetRequest({
245 url: server.url,
246 path,
247 statusCodeExpected: 401
248 })
249 })
250
251 it('Should fail with a user without the appropriate rights', async function () {
252 await makeGetRequest({
253 url: server.url,
254 token: userAccessToken,
255 path,
256 statusCodeExpected: 403
257 })
258 })
259
260 it('Should fail with a bad start pagination', async function () {
261 await checkBadStartPagination(server.url, path, server.accessToken)
262 })
263
264 it('Should fail with a bad count pagination', async function () {
265 await checkBadCountPagination(server.url, path, server.accessToken)
266 })
267
268 it('Should fail with an incorrect sort', async function () {
269 await checkBadSortPagination(server.url, path, server.accessToken)
270 })
271 })
272
273 describe('When blocking an account', function () {
274 it('Should fail with an unauthenticated user', async function () {
275 await makePostBodyRequest({
276 url: server.url,
277 path,
278 fields: { accountName: 'user1' },
279 statusCodeExpected: 401
280 })
281 })
282
283 it('Should fail with a user without the appropriate rights', async function () {
284 await makePostBodyRequest({
285 url: server.url,
286 token: userAccessToken,
287 path,
288 fields: { accountName: 'user1' },
289 statusCodeExpected: 403
290 })
291 })
292
293 it('Should fail with an unknown account', async function () {
294 await makePostBodyRequest({
295 url: server.url,
296 token: server.accessToken,
297 path,
298 fields: { accountName: 'user2' },
299 statusCodeExpected: 404
300 })
301 })
302
303 it('Should fail to block ourselves', async function () {
304 await makePostBodyRequest({
305 url: server.url,
306 token: server.accessToken,
307 path,
308 fields: { accountName: 'root' },
309 statusCodeExpected: 409
310 })
311 })
312
313 it('Should succeed with the correct params', async function () {
314 await makePostBodyRequest({
315 url: server.url,
316 token: server.accessToken,
317 path,
318 fields: { accountName: 'user1' },
319 statusCodeExpected: 204
320 })
321 })
322 })
323
324 describe('When unblocking an account', function () {
325 it('Should fail with an unauthenticated user', async function () {
326 await makeDeleteRequest({
327 url: server.url,
328 path: path + '/user1',
329 statusCodeExpected: 401
330 })
331 })
332
333 it('Should fail with a user without the appropriate rights', async function () {
334 await makeDeleteRequest({
335 url: server.url,
336 path: path + '/user1',
337 token: userAccessToken,
338 statusCodeExpected: 403
339 })
340 })
341
342 it('Should fail with an unknown account block', async function () {
343 await makeDeleteRequest({
344 url: server.url,
345 path: path + '/user2',
346 token: server.accessToken,
347 statusCodeExpected: 404
348 })
349 })
350
351 it('Should succeed with the correct params', async function () {
352 await makeDeleteRequest({
353 url: server.url,
354 path: path + '/user1',
355 token: server.accessToken,
356 statusCodeExpected: 204
357 })
358 })
359 })
360 })
361
362 describe('When managing server servers blocklist', function () {
363 const path = '/api/v1/server/blocklist/servers'
364
365 describe('When listing blocked servers', function () {
366 it('Should fail with an unauthenticated user', async function () {
367 await makeGetRequest({
368 url: server.url,
369 path,
370 statusCodeExpected: 401
371 })
372 })
373
374 it('Should fail with a user without the appropriate rights', async function () {
375 await makeGetRequest({
376 url: server.url,
377 token: userAccessToken,
378 path,
379 statusCodeExpected: 403
380 })
381 })
382
383 it('Should fail with a bad start pagination', async function () {
384 await checkBadStartPagination(server.url, path, server.accessToken)
385 })
386
387 it('Should fail with a bad count pagination', async function () {
388 await checkBadCountPagination(server.url, path, server.accessToken)
389 })
390
391 it('Should fail with an incorrect sort', async function () {
392 await checkBadSortPagination(server.url, path, server.accessToken)
393 })
394 })
395
396 describe('When blocking a server', function () {
397 it('Should fail with an unauthenticated user', async function () {
398 await makePostBodyRequest({
399 url: server.url,
400 path,
401 fields: { host: 'localhost:9002' },
402 statusCodeExpected: 401
403 })
404 })
405
406 it('Should fail with a user without the appropriate rights', async function () {
407 await makePostBodyRequest({
408 url: server.url,
409 token: userAccessToken,
410 path,
411 fields: { host: 'localhost:9002' },
412 statusCodeExpected: 403
413 })
414 })
415
416 it('Should fail with an unknown server', async function () {
417 await makePostBodyRequest({
418 url: server.url,
419 token: server.accessToken,
420 path,
421 fields: { host: 'localhost:9003' },
422 statusCodeExpected: 404
423 })
424 })
425
426 it('Should fail with our own server', async function () {
427 await makePostBodyRequest({
428 url: server.url,
429 token: server.accessToken,
430 path,
431 fields: { host: 'localhost:9001' },
432 statusCodeExpected: 409
433 })
434 })
435
436 it('Should succeed with the correct params', async function () {
437 await makePostBodyRequest({
438 url: server.url,
439 token: server.accessToken,
440 path,
441 fields: { host: 'localhost:9002' },
442 statusCodeExpected: 204
443 })
444 })
445 })
446
447 describe('When unblocking a server', function () {
448 it('Should fail with an unauthenticated user', async function () {
449 await makeDeleteRequest({
450 url: server.url,
451 path: path + '/localhost:9002',
452 statusCodeExpected: 401
453 })
454 })
455
456 it('Should fail with a user without the appropriate rights', async function () {
457 await makeDeleteRequest({
458 url: server.url,
459 path: path + '/localhost:9002',
460 token: userAccessToken,
461 statusCodeExpected: 403
462 })
463 })
464
465 it('Should fail with an unknown server block', async function () {
466 await makeDeleteRequest({
467 url: server.url,
468 path: path + '/localhost:9003',
469 token: server.accessToken,
470 statusCodeExpected: 404
471 })
472 })
473
474 it('Should succeed with the correct params', async function () {
475 await makeDeleteRequest({
476 url: server.url,
477 path: path + '/localhost:9002',
478 token: server.accessToken,
479 statusCodeExpected: 204
480 })
481 })
482 })
483 })
484 })
485
486 after(async function () {
487 killallServers(servers)
488
489 // Keep the logs if the test failed
490 if (this['ok']) {
491 await flushTests()
492 }
493 })
494 })