1 /* tslint:disable:no-unused-expression */
8 flushAndRunMultipleServers,
15 setAccessTokensToServers, userLogin
16 } from '../../../../shared/utils'
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21 } from '../../../../shared/utils/requests/check-api-params'
23 describe('Test blocklist API validators', function () {
24 let servers: ServerInfo[]
25 let server: ServerInfo
26 let userAccessToken: string
28 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
38 const user = { username: 'user1', password: 'password' }
39 await createUser(server.url, server.accessToken, user.username, user.password)
41 userAccessToken = await userLogin(server, user)
43 await doubleFollow(servers[0], servers[1])
46 // ---------------------------------------------------------------
48 describe('When managing user blocklist', function () {
50 describe('When managing user accounts blocklist', function () {
51 const path = '/api/v1/users/me/blocklist/accounts'
53 describe('When listing blocked accounts', function () {
54 it('Should fail with an unauthenticated user', async function () {
55 await makeGetRequest({
58 statusCodeExpected: 401
62 it('Should fail with a bad start pagination', async function () {
63 await checkBadStartPagination(server.url, path, server.accessToken)
66 it('Should fail with a bad count pagination', async function () {
67 await checkBadCountPagination(server.url, path, server.accessToken)
70 it('Should fail with an incorrect sort', async function () {
71 await checkBadSortPagination(server.url, path, server.accessToken)
75 describe('When blocking an account', function () {
76 it('Should fail with an unauthenticated user', async function () {
77 await makePostBodyRequest({
80 fields: { accountName: 'user1' },
81 statusCodeExpected: 401
85 it('Should fail with an unknown account', async function () {
86 await makePostBodyRequest({
88 token: server.accessToken,
90 fields: { accountName: 'user2' },
91 statusCodeExpected: 404
95 it('Should fail to block ourselves', async function () {
96 await makePostBodyRequest({
98 token: server.accessToken,
100 fields: { accountName: 'root' },
101 statusCodeExpected: 409
105 it('Should succeed with the correct params', async function () {
106 await makePostBodyRequest({
108 token: server.accessToken,
110 fields: { accountName: 'user1' },
111 statusCodeExpected: 204
116 describe('When unblocking an account', function () {
117 it('Should fail with an unauthenticated user', async function () {
118 await makeDeleteRequest({
120 path: path + '/user1',
121 statusCodeExpected: 401
125 it('Should fail with an unknown account block', async function () {
126 await makeDeleteRequest({
128 path: path + '/user2',
129 token: server.accessToken,
130 statusCodeExpected: 404
134 it('Should succeed with the correct params', async function () {
135 await makeDeleteRequest({
137 path: path + '/user1',
138 token: server.accessToken,
139 statusCodeExpected: 204
145 describe('When managing user servers blocklist', function () {
146 const path = '/api/v1/users/me/blocklist/servers'
148 describe('When listing blocked servers', function () {
149 it('Should fail with an unauthenticated user', async function () {
150 await makeGetRequest({
153 statusCodeExpected: 401
157 it('Should fail with a bad start pagination', async function () {
158 await checkBadStartPagination(server.url, path, server.accessToken)
161 it('Should fail with a bad count pagination', async function () {
162 await checkBadCountPagination(server.url, path, server.accessToken)
165 it('Should fail with an incorrect sort', async function () {
166 await checkBadSortPagination(server.url, path, server.accessToken)
170 describe('When blocking a server', function () {
171 it('Should fail with an unauthenticated user', async function () {
172 await makePostBodyRequest({
175 fields: { host: 'localhost:9002' },
176 statusCodeExpected: 401
180 it('Should fail with an unknown server', async function () {
181 await makePostBodyRequest({
183 token: server.accessToken,
185 fields: { host: 'localhost:9003' },
186 statusCodeExpected: 404
190 it('Should fail with our own server', async function () {
191 await makePostBodyRequest({
193 token: server.accessToken,
195 fields: { host: 'localhost:9001' },
196 statusCodeExpected: 409
200 it('Should succeed with the correct params', async function () {
201 await makePostBodyRequest({
203 token: server.accessToken,
205 fields: { host: 'localhost:9002' },
206 statusCodeExpected: 204
211 describe('When unblocking a server', function () {
212 it('Should fail with an unauthenticated user', async function () {
213 await makeDeleteRequest({
215 path: path + '/localhost:9002',
216 statusCodeExpected: 401
220 it('Should fail with an unknown server block', async function () {
221 await makeDeleteRequest({
223 path: path + '/localhost:9003',
224 token: server.accessToken,
225 statusCodeExpected: 404
229 it('Should succeed with the correct params', async function () {
230 await makeDeleteRequest({
232 path: path + '/localhost:9002',
233 token: server.accessToken,
234 statusCodeExpected: 204
241 describe('When managing server blocklist', function () {
243 describe('When managing server accounts blocklist', function () {
244 const path = '/api/v1/server/blocklist/accounts'
246 describe('When listing blocked accounts', function () {
247 it('Should fail with an unauthenticated user', async function () {
248 await makeGetRequest({
251 statusCodeExpected: 401
255 it('Should fail with a user without the appropriate rights', async function () {
256 await makeGetRequest({
258 token: userAccessToken,
260 statusCodeExpected: 403
264 it('Should fail with a bad start pagination', async function () {
265 await checkBadStartPagination(server.url, path, server.accessToken)
268 it('Should fail with a bad count pagination', async function () {
269 await checkBadCountPagination(server.url, path, server.accessToken)
272 it('Should fail with an incorrect sort', async function () {
273 await checkBadSortPagination(server.url, path, server.accessToken)
277 describe('When blocking an account', function () {
278 it('Should fail with an unauthenticated user', async function () {
279 await makePostBodyRequest({
282 fields: { accountName: 'user1' },
283 statusCodeExpected: 401
287 it('Should fail with a user without the appropriate rights', async function () {
288 await makePostBodyRequest({
290 token: userAccessToken,
292 fields: { accountName: 'user1' },
293 statusCodeExpected: 403
297 it('Should fail with an unknown account', async function () {
298 await makePostBodyRequest({
300 token: server.accessToken,
302 fields: { accountName: 'user2' },
303 statusCodeExpected: 404
307 it('Should fail to block ourselves', async function () {
308 await makePostBodyRequest({
310 token: server.accessToken,
312 fields: { accountName: 'root' },
313 statusCodeExpected: 409
317 it('Should succeed with the correct params', async function () {
318 await makePostBodyRequest({
320 token: server.accessToken,
322 fields: { accountName: 'user1' },
323 statusCodeExpected: 204
328 describe('When unblocking an account', function () {
329 it('Should fail with an unauthenticated user', async function () {
330 await makeDeleteRequest({
332 path: path + '/user1',
333 statusCodeExpected: 401
337 it('Should fail with a user without the appropriate rights', async function () {
338 await makeDeleteRequest({
340 path: path + '/user1',
341 token: userAccessToken,
342 statusCodeExpected: 403
346 it('Should fail with an unknown account block', async function () {
347 await makeDeleteRequest({
349 path: path + '/user2',
350 token: server.accessToken,
351 statusCodeExpected: 404
355 it('Should succeed with the correct params', async function () {
356 await makeDeleteRequest({
358 path: path + '/user1',
359 token: server.accessToken,
360 statusCodeExpected: 204
366 describe('When managing server servers blocklist', function () {
367 const path = '/api/v1/server/blocklist/servers'
369 describe('When listing blocked servers', function () {
370 it('Should fail with an unauthenticated user', async function () {
371 await makeGetRequest({
374 statusCodeExpected: 401
378 it('Should fail with a user without the appropriate rights', async function () {
379 await makeGetRequest({
381 token: userAccessToken,
383 statusCodeExpected: 403
387 it('Should fail with a bad start pagination', async function () {
388 await checkBadStartPagination(server.url, path, server.accessToken)
391 it('Should fail with a bad count pagination', async function () {
392 await checkBadCountPagination(server.url, path, server.accessToken)
395 it('Should fail with an incorrect sort', async function () {
396 await checkBadSortPagination(server.url, path, server.accessToken)
400 describe('When blocking a server', function () {
401 it('Should fail with an unauthenticated user', async function () {
402 await makePostBodyRequest({
405 fields: { host: 'localhost:9002' },
406 statusCodeExpected: 401
410 it('Should fail with a user without the appropriate rights', async function () {
411 await makePostBodyRequest({
413 token: userAccessToken,
415 fields: { host: 'localhost:9002' },
416 statusCodeExpected: 403
420 it('Should fail with an unknown server', async function () {
421 await makePostBodyRequest({
423 token: server.accessToken,
425 fields: { host: 'localhost:9003' },
426 statusCodeExpected: 404
430 it('Should fail with our own server', async function () {
431 await makePostBodyRequest({
433 token: server.accessToken,
435 fields: { host: 'localhost:9001' },
436 statusCodeExpected: 409
440 it('Should succeed with the correct params', async function () {
441 await makePostBodyRequest({
443 token: server.accessToken,
445 fields: { host: 'localhost:9002' },
446 statusCodeExpected: 204
451 describe('When unblocking a server', function () {
452 it('Should fail with an unauthenticated user', async function () {
453 await makeDeleteRequest({
455 path: path + '/localhost:9002',
456 statusCodeExpected: 401
460 it('Should fail with a user without the appropriate rights', async function () {
461 await makeDeleteRequest({
463 path: path + '/localhost:9002',
464 token: userAccessToken,
465 statusCodeExpected: 403
469 it('Should fail with an unknown server block', async function () {
470 await makeDeleteRequest({
472 path: path + '/localhost:9003',
473 token: server.accessToken,
474 statusCodeExpected: 404
478 it('Should succeed with the correct params', async function () {
479 await makeDeleteRequest({
481 path: path + '/localhost:9002',
482 token: server.accessToken,
483 statusCodeExpected: 204
490 after(async function () {
491 killallServers(servers)
493 // Keep the logs if the test failed