1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
9 flushAndRunMultipleServers,
14 setAccessTokensToServers,
16 } from '../../../../shared/extra-utils'
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21 } from '../../../../shared/extra-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 () {
31 servers = await flushAndRunMultipleServers(2)
32 await setAccessTokensToServers(servers)
36 const user = { username: 'user1', password: 'password' }
37 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
39 userAccessToken = await userLogin(server, user)
41 await doubleFollow(servers[0], servers[1])
44 // ---------------------------------------------------------------
46 describe('When managing user blocklist', function () {
48 describe('When managing user accounts blocklist', function () {
49 const path = '/api/v1/users/me/blocklist/accounts'
51 describe('When listing blocked accounts', function () {
52 it('Should fail with an unauthenticated user', async function () {
53 await makeGetRequest({
56 statusCodeExpected: 401
60 it('Should fail with a bad start pagination', async function () {
61 await checkBadStartPagination(server.url, path, server.accessToken)
64 it('Should fail with a bad count pagination', async function () {
65 await checkBadCountPagination(server.url, path, server.accessToken)
68 it('Should fail with an incorrect sort', async function () {
69 await checkBadSortPagination(server.url, path, server.accessToken)
73 describe('When blocking an account', function () {
74 it('Should fail with an unauthenticated user', async function () {
75 await makePostBodyRequest({
78 fields: { accountName: 'user1' },
79 statusCodeExpected: 401
83 it('Should fail with an unknown account', async function () {
84 await makePostBodyRequest({
86 token: server.accessToken,
88 fields: { accountName: 'user2' },
89 statusCodeExpected: 404
93 it('Should fail to block ourselves', async function () {
94 await makePostBodyRequest({
96 token: server.accessToken,
98 fields: { accountName: 'root' },
99 statusCodeExpected: 409
103 it('Should succeed with the correct params', async function () {
104 await makePostBodyRequest({
106 token: server.accessToken,
108 fields: { accountName: 'user1' },
109 statusCodeExpected: 204
114 describe('When unblocking an account', function () {
115 it('Should fail with an unauthenticated user', async function () {
116 await makeDeleteRequest({
118 path: path + '/user1',
119 statusCodeExpected: 401
123 it('Should fail with an unknown account block', async function () {
124 await makeDeleteRequest({
126 path: path + '/user2',
127 token: server.accessToken,
128 statusCodeExpected: 404
132 it('Should succeed with the correct params', async function () {
133 await makeDeleteRequest({
135 path: path + '/user1',
136 token: server.accessToken,
137 statusCodeExpected: 204
143 describe('When managing user servers blocklist', function () {
144 const path = '/api/v1/users/me/blocklist/servers'
146 describe('When listing blocked servers', function () {
147 it('Should fail with an unauthenticated user', async function () {
148 await makeGetRequest({
151 statusCodeExpected: 401
155 it('Should fail with a bad start pagination', async function () {
156 await checkBadStartPagination(server.url, path, server.accessToken)
159 it('Should fail with a bad count pagination', async function () {
160 await checkBadCountPagination(server.url, path, server.accessToken)
163 it('Should fail with an incorrect sort', async function () {
164 await checkBadSortPagination(server.url, path, server.accessToken)
168 describe('When blocking a server', function () {
169 it('Should fail with an unauthenticated user', async function () {
170 await makePostBodyRequest({
173 fields: { host: 'localhost:9002' },
174 statusCodeExpected: 401
178 it('Should fail with an unknown server', async function () {
179 await makePostBodyRequest({
181 token: server.accessToken,
183 fields: { host: 'localhost:9003' },
184 statusCodeExpected: 404
188 it('Should fail with our own server', async function () {
189 await makePostBodyRequest({
191 token: server.accessToken,
193 fields: { host: 'localhost:' + server.port },
194 statusCodeExpected: 409
198 it('Should succeed with the correct params', async function () {
199 await makePostBodyRequest({
201 token: server.accessToken,
203 fields: { host: 'localhost:' + servers[1].port },
204 statusCodeExpected: 204
209 describe('When unblocking a server', function () {
210 it('Should fail with an unauthenticated user', async function () {
211 await makeDeleteRequest({
213 path: path + '/localhost:' + servers[1].port,
214 statusCodeExpected: 401
218 it('Should fail with an unknown server block', async function () {
219 await makeDeleteRequest({
221 path: path + '/localhost:9003',
222 token: server.accessToken,
223 statusCodeExpected: 404
227 it('Should succeed with the correct params', async function () {
228 await makeDeleteRequest({
230 path: path + '/localhost:' + servers[1].port,
231 token: server.accessToken,
232 statusCodeExpected: 204
239 describe('When managing server blocklist', function () {
241 describe('When managing server accounts blocklist', function () {
242 const path = '/api/v1/server/blocklist/accounts'
244 describe('When listing blocked accounts', function () {
245 it('Should fail with an unauthenticated user', async function () {
246 await makeGetRequest({
249 statusCodeExpected: 401
253 it('Should fail with a user without the appropriate rights', async function () {
254 await makeGetRequest({
256 token: userAccessToken,
258 statusCodeExpected: 403
262 it('Should fail with a bad start pagination', async function () {
263 await checkBadStartPagination(server.url, path, server.accessToken)
266 it('Should fail with a bad count pagination', async function () {
267 await checkBadCountPagination(server.url, path, server.accessToken)
270 it('Should fail with an incorrect sort', async function () {
271 await checkBadSortPagination(server.url, path, server.accessToken)
275 describe('When blocking an account', function () {
276 it('Should fail with an unauthenticated user', async function () {
277 await makePostBodyRequest({
280 fields: { accountName: 'user1' },
281 statusCodeExpected: 401
285 it('Should fail with a user without the appropriate rights', async function () {
286 await makePostBodyRequest({
288 token: userAccessToken,
290 fields: { accountName: 'user1' },
291 statusCodeExpected: 403
295 it('Should fail with an unknown account', async function () {
296 await makePostBodyRequest({
298 token: server.accessToken,
300 fields: { accountName: 'user2' },
301 statusCodeExpected: 404
305 it('Should fail to block ourselves', async function () {
306 await makePostBodyRequest({
308 token: server.accessToken,
310 fields: { accountName: 'root' },
311 statusCodeExpected: 409
315 it('Should succeed with the correct params', async function () {
316 await makePostBodyRequest({
318 token: server.accessToken,
320 fields: { accountName: 'user1' },
321 statusCodeExpected: 204
326 describe('When unblocking an account', function () {
327 it('Should fail with an unauthenticated user', async function () {
328 await makeDeleteRequest({
330 path: path + '/user1',
331 statusCodeExpected: 401
335 it('Should fail with a user without the appropriate rights', async function () {
336 await makeDeleteRequest({
338 path: path + '/user1',
339 token: userAccessToken,
340 statusCodeExpected: 403
344 it('Should fail with an unknown account block', async function () {
345 await makeDeleteRequest({
347 path: path + '/user2',
348 token: server.accessToken,
349 statusCodeExpected: 404
353 it('Should succeed with the correct params', async function () {
354 await makeDeleteRequest({
356 path: path + '/user1',
357 token: server.accessToken,
358 statusCodeExpected: 204
364 describe('When managing server servers blocklist', function () {
365 const path = '/api/v1/server/blocklist/servers'
367 describe('When listing blocked servers', function () {
368 it('Should fail with an unauthenticated user', async function () {
369 await makeGetRequest({
372 statusCodeExpected: 401
376 it('Should fail with a user without the appropriate rights', async function () {
377 await makeGetRequest({
379 token: userAccessToken,
381 statusCodeExpected: 403
385 it('Should fail with a bad start pagination', async function () {
386 await checkBadStartPagination(server.url, path, server.accessToken)
389 it('Should fail with a bad count pagination', async function () {
390 await checkBadCountPagination(server.url, path, server.accessToken)
393 it('Should fail with an incorrect sort', async function () {
394 await checkBadSortPagination(server.url, path, server.accessToken)
398 describe('When blocking a server', function () {
399 it('Should fail with an unauthenticated user', async function () {
400 await makePostBodyRequest({
403 fields: { host: 'localhost:' + servers[1].port },
404 statusCodeExpected: 401
408 it('Should fail with a user without the appropriate rights', async function () {
409 await makePostBodyRequest({
411 token: userAccessToken,
413 fields: { host: 'localhost:' + servers[1].port },
414 statusCodeExpected: 403
418 it('Should fail with an unknown server', async function () {
419 await makePostBodyRequest({
421 token: server.accessToken,
423 fields: { host: 'localhost:9003' },
424 statusCodeExpected: 404
428 it('Should fail with our own server', async function () {
429 await makePostBodyRequest({
431 token: server.accessToken,
433 fields: { host: 'localhost:' + server.port },
434 statusCodeExpected: 409
438 it('Should succeed with the correct params', async function () {
439 await makePostBodyRequest({
441 token: server.accessToken,
443 fields: { host: 'localhost:' + servers[1].port },
444 statusCodeExpected: 204
449 describe('When unblocking a server', function () {
450 it('Should fail with an unauthenticated user', async function () {
451 await makeDeleteRequest({
453 path: path + '/localhost:' + servers[1].port,
454 statusCodeExpected: 401
458 it('Should fail with a user without the appropriate rights', async function () {
459 await makeDeleteRequest({
461 path: path + '/localhost:' + servers[1].port,
462 token: userAccessToken,
463 statusCodeExpected: 403
467 it('Should fail with an unknown server block', async function () {
468 await makeDeleteRequest({
470 path: path + '/localhost:9003',
471 token: server.accessToken,
472 statusCodeExpected: 404
476 it('Should succeed with the correct params', async function () {
477 await makeDeleteRequest({
479 path: path + '/localhost:' + servers[1].port,
480 token: server.accessToken,
481 statusCodeExpected: 204
488 after(async function () {
489 await cleanupTests(servers)