1 /* tslint:disable:no-unused-expression */
8 flushAndRunMultipleServers,
15 setAccessTokensToServers, userLogin
17 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
19 describe('Test blocklist API validators', function () {
20 let servers: ServerInfo[]
21 let server: ServerInfo
22 let userAccessToken: string
24 before(async function () {
29 servers = await flushAndRunMultipleServers(2)
30 await setAccessTokensToServers(servers)
34 const user = { username: 'user1', password: 'password' }
35 await createUser(server.url, server.accessToken, user.username, user.password)
37 userAccessToken = await userLogin(server, user)
39 await doubleFollow(servers[0], servers[1])
42 // ---------------------------------------------------------------
44 describe('When managing user blocklist', function () {
46 describe('When managing user accounts blocklist', function () {
47 const path = '/api/v1/users/me/blocklist/accounts'
49 describe('When listing blocked accounts', function () {
50 it('Should fail with an unauthenticated user', async function () {
51 await makeGetRequest({
54 statusCodeExpected: 401
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, path, server.accessToken)
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, path, server.accessToken)
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, path, server.accessToken)
71 describe('When blocking an account', function () {
72 it('Should fail with an unauthenticated user', async function () {
73 await makePostBodyRequest({
76 fields: { accountName: 'user1' },
77 statusCodeExpected: 401
81 it('Should fail with an unknown account', async function () {
82 await makePostBodyRequest({
84 token: server.accessToken,
86 fields: { accountName: 'user2' },
87 statusCodeExpected: 404
91 it('Should fail to block ourselves', async function () {
92 await makePostBodyRequest({
94 token: server.accessToken,
96 fields: { accountName: 'root' },
97 statusCodeExpected: 409
101 it('Should succeed with the correct params', async function () {
102 await makePostBodyRequest({
104 token: server.accessToken,
106 fields: { accountName: 'user1' },
107 statusCodeExpected: 204
112 describe('When unblocking an account', function () {
113 it('Should fail with an unauthenticated user', async function () {
114 await makeDeleteRequest({
116 path: path + '/user1',
117 statusCodeExpected: 401
121 it('Should fail with an unknown account block', async function () {
122 await makeDeleteRequest({
124 path: path + '/user2',
125 token: server.accessToken,
126 statusCodeExpected: 404
130 it('Should succeed with the correct params', async function () {
131 await makeDeleteRequest({
133 path: path + '/user1',
134 token: server.accessToken,
135 statusCodeExpected: 204
141 describe('When managing user servers blocklist', function () {
142 const path = '/api/v1/users/me/blocklist/servers'
144 describe('When listing blocked servers', function () {
145 it('Should fail with an unauthenticated user', async function () {
146 await makeGetRequest({
149 statusCodeExpected: 401
153 it('Should fail with a bad start pagination', async function () {
154 await checkBadStartPagination(server.url, path, server.accessToken)
157 it('Should fail with a bad count pagination', async function () {
158 await checkBadCountPagination(server.url, path, server.accessToken)
161 it('Should fail with an incorrect sort', async function () {
162 await checkBadSortPagination(server.url, path, server.accessToken)
166 describe('When blocking a server', function () {
167 it('Should fail with an unauthenticated user', async function () {
168 await makePostBodyRequest({
171 fields: { host: 'localhost:9002' },
172 statusCodeExpected: 401
176 it('Should fail with an unknown server', async function () {
177 await makePostBodyRequest({
179 token: server.accessToken,
181 fields: { host: 'localhost:9003' },
182 statusCodeExpected: 404
186 it('Should fail with our own server', async function () {
187 await makePostBodyRequest({
189 token: server.accessToken,
191 fields: { host: 'localhost:9001' },
192 statusCodeExpected: 409
196 it('Should succeed with the correct params', async function () {
197 await makePostBodyRequest({
199 token: server.accessToken,
201 fields: { host: 'localhost:9002' },
202 statusCodeExpected: 204
207 describe('When unblocking a server', function () {
208 it('Should fail with an unauthenticated user', async function () {
209 await makeDeleteRequest({
211 path: path + '/localhost:9002',
212 statusCodeExpected: 401
216 it('Should fail with an unknown server block', async function () {
217 await makeDeleteRequest({
219 path: path + '/localhost:9003',
220 token: server.accessToken,
221 statusCodeExpected: 404
225 it('Should succeed with the correct params', async function () {
226 await makeDeleteRequest({
228 path: path + '/localhost:9002',
229 token: server.accessToken,
230 statusCodeExpected: 204
237 describe('When managing server blocklist', function () {
239 describe('When managing server accounts blocklist', function () {
240 const path = '/api/v1/server/blocklist/accounts'
242 describe('When listing blocked accounts', function () {
243 it('Should fail with an unauthenticated user', async function () {
244 await makeGetRequest({
247 statusCodeExpected: 401
251 it('Should fail with a user without the appropriate rights', async function () {
252 await makeGetRequest({
254 token: userAccessToken,
256 statusCodeExpected: 403
260 it('Should fail with a bad start pagination', async function () {
261 await checkBadStartPagination(server.url, path, server.accessToken)
264 it('Should fail with a bad count pagination', async function () {
265 await checkBadCountPagination(server.url, path, server.accessToken)
268 it('Should fail with an incorrect sort', async function () {
269 await checkBadSortPagination(server.url, path, server.accessToken)
273 describe('When blocking an account', function () {
274 it('Should fail with an unauthenticated user', async function () {
275 await makePostBodyRequest({
278 fields: { accountName: 'user1' },
279 statusCodeExpected: 401
283 it('Should fail with a user without the appropriate rights', async function () {
284 await makePostBodyRequest({
286 token: userAccessToken,
288 fields: { accountName: 'user1' },
289 statusCodeExpected: 403
293 it('Should fail with an unknown account', async function () {
294 await makePostBodyRequest({
296 token: server.accessToken,
298 fields: { accountName: 'user2' },
299 statusCodeExpected: 404
303 it('Should fail to block ourselves', async function () {
304 await makePostBodyRequest({
306 token: server.accessToken,
308 fields: { accountName: 'root' },
309 statusCodeExpected: 409
313 it('Should succeed with the correct params', async function () {
314 await makePostBodyRequest({
316 token: server.accessToken,
318 fields: { accountName: 'user1' },
319 statusCodeExpected: 204
324 describe('When unblocking an account', function () {
325 it('Should fail with an unauthenticated user', async function () {
326 await makeDeleteRequest({
328 path: path + '/user1',
329 statusCodeExpected: 401
333 it('Should fail with a user without the appropriate rights', async function () {
334 await makeDeleteRequest({
336 path: path + '/user1',
337 token: userAccessToken,
338 statusCodeExpected: 403
342 it('Should fail with an unknown account block', async function () {
343 await makeDeleteRequest({
345 path: path + '/user2',
346 token: server.accessToken,
347 statusCodeExpected: 404
351 it('Should succeed with the correct params', async function () {
352 await makeDeleteRequest({
354 path: path + '/user1',
355 token: server.accessToken,
356 statusCodeExpected: 204
362 describe('When managing server servers blocklist', function () {
363 const path = '/api/v1/server/blocklist/servers'
365 describe('When listing blocked servers', function () {
366 it('Should fail with an unauthenticated user', async function () {
367 await makeGetRequest({
370 statusCodeExpected: 401
374 it('Should fail with a user without the appropriate rights', async function () {
375 await makeGetRequest({
377 token: userAccessToken,
379 statusCodeExpected: 403
383 it('Should fail with a bad start pagination', async function () {
384 await checkBadStartPagination(server.url, path, server.accessToken)
387 it('Should fail with a bad count pagination', async function () {
388 await checkBadCountPagination(server.url, path, server.accessToken)
391 it('Should fail with an incorrect sort', async function () {
392 await checkBadSortPagination(server.url, path, server.accessToken)
396 describe('When blocking a server', function () {
397 it('Should fail with an unauthenticated user', async function () {
398 await makePostBodyRequest({
401 fields: { host: 'localhost:9002' },
402 statusCodeExpected: 401
406 it('Should fail with a user without the appropriate rights', async function () {
407 await makePostBodyRequest({
409 token: userAccessToken,
411 fields: { host: 'localhost:9002' },
412 statusCodeExpected: 403
416 it('Should fail with an unknown server', async function () {
417 await makePostBodyRequest({
419 token: server.accessToken,
421 fields: { host: 'localhost:9003' },
422 statusCodeExpected: 404
426 it('Should fail with our own server', async function () {
427 await makePostBodyRequest({
429 token: server.accessToken,
431 fields: { host: 'localhost:9001' },
432 statusCodeExpected: 409
436 it('Should succeed with the correct params', async function () {
437 await makePostBodyRequest({
439 token: server.accessToken,
441 fields: { host: 'localhost:9002' },
442 statusCodeExpected: 204
447 describe('When unblocking a server', function () {
448 it('Should fail with an unauthenticated user', async function () {
449 await makeDeleteRequest({
451 path: path + '/localhost:9002',
452 statusCodeExpected: 401
456 it('Should fail with a user without the appropriate rights', async function () {
457 await makeDeleteRequest({
459 path: path + '/localhost:9002',
460 token: userAccessToken,
461 statusCodeExpected: 403
465 it('Should fail with an unknown server block', async function () {
466 await makeDeleteRequest({
468 path: path + '/localhost:9003',
469 token: server.accessToken,
470 statusCodeExpected: 404
474 it('Should succeed with the correct params', async function () {
475 await makeDeleteRequest({
477 path: path + '/localhost:9002',
478 token: server.accessToken,
479 statusCodeExpected: 204
486 after(async function () {
487 killallServers(servers)
489 // Keep the logs if the test failed