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'
22 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 describe('Test blocklist API validators', function () {
25 let servers: ServerInfo[]
26 let server: ServerInfo
27 let userAccessToken: string
29 before(async function () {
32 servers = await flushAndRunMultipleServers(2)
33 await setAccessTokensToServers(servers)
37 const user = { username: 'user1', password: 'password' }
38 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
40 userAccessToken = await userLogin(server, user)
42 await doubleFollow(servers[0], servers[1])
45 // ---------------------------------------------------------------
47 describe('When managing user blocklist', function () {
49 describe('When managing user accounts blocklist', function () {
50 const path = '/api/v1/users/me/blocklist/accounts'
52 describe('When listing blocked accounts', function () {
53 it('Should fail with an unauthenticated user', async function () {
54 await makeGetRequest({
57 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
61 it('Should fail with a bad start pagination', async function () {
62 await checkBadStartPagination(server.url, path, server.accessToken)
65 it('Should fail with a bad count pagination', async function () {
66 await checkBadCountPagination(server.url, path, server.accessToken)
69 it('Should fail with an incorrect sort', async function () {
70 await checkBadSortPagination(server.url, path, server.accessToken)
74 describe('When blocking an account', function () {
75 it('Should fail with an unauthenticated user', async function () {
76 await makePostBodyRequest({
79 fields: { accountName: 'user1' },
80 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
84 it('Should fail with an unknown account', async function () {
85 await makePostBodyRequest({
87 token: server.accessToken,
89 fields: { accountName: 'user2' },
90 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
94 it('Should fail to block ourselves', async function () {
95 await makePostBodyRequest({
97 token: server.accessToken,
99 fields: { accountName: 'root' },
100 statusCodeExpected: HttpStatusCode.CONFLICT_409
104 it('Should succeed with the correct params', async function () {
105 await makePostBodyRequest({
107 token: server.accessToken,
109 fields: { accountName: 'user1' },
110 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
115 describe('When unblocking an account', function () {
116 it('Should fail with an unauthenticated user', async function () {
117 await makeDeleteRequest({
119 path: path + '/user1',
120 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
124 it('Should fail with an unknown account block', async function () {
125 await makeDeleteRequest({
127 path: path + '/user2',
128 token: server.accessToken,
129 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
133 it('Should succeed with the correct params', async function () {
134 await makeDeleteRequest({
136 path: path + '/user1',
137 token: server.accessToken,
138 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
144 describe('When managing user servers blocklist', function () {
145 const path = '/api/v1/users/me/blocklist/servers'
147 describe('When listing blocked servers', function () {
148 it('Should fail with an unauthenticated user', async function () {
149 await makeGetRequest({
152 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
156 it('Should fail with a bad start pagination', async function () {
157 await checkBadStartPagination(server.url, path, server.accessToken)
160 it('Should fail with a bad count pagination', async function () {
161 await checkBadCountPagination(server.url, path, server.accessToken)
164 it('Should fail with an incorrect sort', async function () {
165 await checkBadSortPagination(server.url, path, server.accessToken)
169 describe('When blocking a server', function () {
170 it('Should fail with an unauthenticated user', async function () {
171 await makePostBodyRequest({
174 fields: { host: 'localhost:9002' },
175 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
179 it('Should succeed with an unknown server', async function () {
180 await makePostBodyRequest({
182 token: server.accessToken,
184 fields: { host: 'localhost:9003' },
185 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
189 it('Should fail with our own server', async function () {
190 await makePostBodyRequest({
192 token: server.accessToken,
194 fields: { host: 'localhost:' + server.port },
195 statusCodeExpected: HttpStatusCode.CONFLICT_409
199 it('Should succeed with the correct params', async function () {
200 await makePostBodyRequest({
202 token: server.accessToken,
204 fields: { host: 'localhost:' + servers[1].port },
205 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
210 describe('When unblocking a server', function () {
211 it('Should fail with an unauthenticated user', async function () {
212 await makeDeleteRequest({
214 path: path + '/localhost:' + servers[1].port,
215 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
219 it('Should fail with an unknown server block', async function () {
220 await makeDeleteRequest({
222 path: path + '/localhost:9004',
223 token: server.accessToken,
224 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
228 it('Should succeed with the correct params', async function () {
229 await makeDeleteRequest({
231 path: path + '/localhost:' + servers[1].port,
232 token: server.accessToken,
233 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
240 describe('When managing server blocklist', function () {
242 describe('When managing server accounts blocklist', function () {
243 const path = '/api/v1/server/blocklist/accounts'
245 describe('When listing blocked accounts', function () {
246 it('Should fail with an unauthenticated user', async function () {
247 await makeGetRequest({
250 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
254 it('Should fail with a user without the appropriate rights', async function () {
255 await makeGetRequest({
257 token: userAccessToken,
259 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
263 it('Should fail with a bad start pagination', async function () {
264 await checkBadStartPagination(server.url, path, server.accessToken)
267 it('Should fail with a bad count pagination', async function () {
268 await checkBadCountPagination(server.url, path, server.accessToken)
271 it('Should fail with an incorrect sort', async function () {
272 await checkBadSortPagination(server.url, path, server.accessToken)
276 describe('When blocking an account', function () {
277 it('Should fail with an unauthenticated user', async function () {
278 await makePostBodyRequest({
281 fields: { accountName: 'user1' },
282 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
286 it('Should fail with a user without the appropriate rights', async function () {
287 await makePostBodyRequest({
289 token: userAccessToken,
291 fields: { accountName: 'user1' },
292 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
296 it('Should fail with an unknown account', async function () {
297 await makePostBodyRequest({
299 token: server.accessToken,
301 fields: { accountName: 'user2' },
302 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
306 it('Should fail to block ourselves', async function () {
307 await makePostBodyRequest({
309 token: server.accessToken,
311 fields: { accountName: 'root' },
312 statusCodeExpected: HttpStatusCode.CONFLICT_409
316 it('Should succeed with the correct params', async function () {
317 await makePostBodyRequest({
319 token: server.accessToken,
321 fields: { accountName: 'user1' },
322 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
327 describe('When unblocking an account', function () {
328 it('Should fail with an unauthenticated user', async function () {
329 await makeDeleteRequest({
331 path: path + '/user1',
332 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
336 it('Should fail with a user without the appropriate rights', async function () {
337 await makeDeleteRequest({
339 path: path + '/user1',
340 token: userAccessToken,
341 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
345 it('Should fail with an unknown account block', async function () {
346 await makeDeleteRequest({
348 path: path + '/user2',
349 token: server.accessToken,
350 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
354 it('Should succeed with the correct params', async function () {
355 await makeDeleteRequest({
357 path: path + '/user1',
358 token: server.accessToken,
359 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
365 describe('When managing server servers blocklist', function () {
366 const path = '/api/v1/server/blocklist/servers'
368 describe('When listing blocked servers', function () {
369 it('Should fail with an unauthenticated user', async function () {
370 await makeGetRequest({
373 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
377 it('Should fail with a user without the appropriate rights', async function () {
378 await makeGetRequest({
380 token: userAccessToken,
382 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
386 it('Should fail with a bad start pagination', async function () {
387 await checkBadStartPagination(server.url, path, server.accessToken)
390 it('Should fail with a bad count pagination', async function () {
391 await checkBadCountPagination(server.url, path, server.accessToken)
394 it('Should fail with an incorrect sort', async function () {
395 await checkBadSortPagination(server.url, path, server.accessToken)
399 describe('When blocking a server', function () {
400 it('Should fail with an unauthenticated user', async function () {
401 await makePostBodyRequest({
404 fields: { host: 'localhost:' + servers[1].port },
405 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
409 it('Should fail with a user without the appropriate rights', async function () {
410 await makePostBodyRequest({
412 token: userAccessToken,
414 fields: { host: 'localhost:' + servers[1].port },
415 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
419 it('Should succeed with an unknown server', async function () {
420 await makePostBodyRequest({
422 token: server.accessToken,
424 fields: { host: 'localhost:9003' },
425 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
429 it('Should fail with our own server', async function () {
430 await makePostBodyRequest({
432 token: server.accessToken,
434 fields: { host: 'localhost:' + server.port },
435 statusCodeExpected: HttpStatusCode.CONFLICT_409
439 it('Should succeed with the correct params', async function () {
440 await makePostBodyRequest({
442 token: server.accessToken,
444 fields: { host: 'localhost:' + servers[1].port },
445 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
450 describe('When unblocking a server', function () {
451 it('Should fail with an unauthenticated user', async function () {
452 await makeDeleteRequest({
454 path: path + '/localhost:' + servers[1].port,
455 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
459 it('Should fail with a user without the appropriate rights', async function () {
460 await makeDeleteRequest({
462 path: path + '/localhost:' + servers[1].port,
463 token: userAccessToken,
464 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
468 it('Should fail with an unknown server block', async function () {
469 await makeDeleteRequest({
471 path: path + '/localhost:9004',
472 token: server.accessToken,
473 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
477 it('Should succeed with the correct params', async function () {
478 await makeDeleteRequest({
480 path: path + '/localhost:' + servers[1].port,
481 token: server.accessToken,
482 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
489 after(async function () {
490 await cleanupTests(servers)