aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/blocklist.ts
blob: 21b9ae4f801b8b70b307eef763bce01cfe57a456 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import * as chai from 'chai'
import 'mocha'
import { AccountBlock, ServerBlock, Video } from '../../../../shared/index'
import {
  cleanupTests,
  createUser,
  deleteVideoComment,
  doubleFollow,
  flushAndRunMultipleServers,
  ServerInfo,
  uploadVideo,
  userLogin
} from '../../../../shared/extra-utils/index'
import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
import { getVideosList, getVideosListWithToken } from '../../../../shared/extra-utils/videos/videos'
import {
  addVideoCommentReply,
  addVideoCommentThread,
  getVideoCommentThreads,
  getVideoThreadComments
} from '../../../../shared/extra-utils/videos/video-comments'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
import {
  addAccountToAccountBlocklist,
  addAccountToServerBlocklist,
  addServerToAccountBlocklist,
  addServerToServerBlocklist,
  getAccountBlocklistByAccount,
  getAccountBlocklistByServer,
  getServerBlocklistByAccount,
  getServerBlocklistByServer,
  removeAccountFromAccountBlocklist,
  removeAccountFromServerBlocklist,
  removeServerFromAccountBlocklist,
  removeServerFromServerBlocklist
} from '../../../../shared/extra-utils/users/blocklist'
import { getUserNotifications } from '../../../../shared/extra-utils/users/user-notifications'

const expect = chai.expect

async function checkAllVideos (url: string, token: string) {
  {
    const res = await getVideosListWithToken(url, token)

    expect(res.body.data).to.have.lengthOf(4)
  }

  {
    const res = await getVideosList(url)

    expect(res.body.data).to.have.lengthOf(4)
  }
}

async function checkAllComments (url: string, token: string, videoUUID: string) {
  const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token)

  const allThreads: VideoComment[] = resThreads.body.data
  const threads = allThreads.filter(t => t.isDeleted === false)
  expect(threads).to.have.lengthOf(2)

  for (const thread of threads) {
    const res = await getVideoThreadComments(url, videoUUID, thread.id, token)

    const tree: VideoCommentThreadTree = res.body
    expect(tree.children).to.have.lengthOf(1)
  }
}

async function checkCommentNotification (
  mainServer: ServerInfo,
  comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
  check: 'presence' | 'absence'
) {
  const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text)
  const threadId = resComment.body.comment.id

  await waitJobs([ mainServer, comment.server ])

  const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30)
  const commentNotifications = res.body.data
                                  .filter(n => n.comment && n.comment.id === threadId)

  if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
  else expect(commentNotifications).to.have.lengthOf(0)

  await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId)

  await waitJobs([ mainServer, comment.server ])
}

describe('Test blocklist', function () {
  let servers: ServerInfo[]
  let videoUUID1: string
  let videoUUID2: string
  let userToken1: string
  let userModeratorToken: string
  let userToken2: string

  before(async function () {
    this.timeout(60000)

    servers = await flushAndRunMultipleServers(2)
    await setAccessTokensToServers(servers)

    {
      const user = { username: 'user1', password: 'password' }
      await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })

      userToken1 = await userLogin(servers[0], user)
      await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
    }

    {
      const user = { username: 'moderator', password: 'password' }
      await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })

      userModeratorToken = await userLogin(servers[0], user)
    }

    {
      const user = { username: 'user2', password: 'password' }
      await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })

      userToken2 = await userLogin(servers[1], user)
      await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
    }

    {
      const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
      videoUUID1 = res.body.video.uuid
    }

    {
      const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
      videoUUID2 = res.body.video.uuid
    }

    await doubleFollow(servers[0], servers[1])

    {
      const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1')
      const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1')
      await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1')
    }

    {
      const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1')
      await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1')
    }

    await waitJobs(servers)
  })

  describe('User blocklist', function () {

    describe('When managing account blocklist', function () {
      it('Should list all videos', function () {
        return checkAllVideos(servers[0].url, servers[0].accessToken)
      })

      it('Should list the comments', function () {
        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
      })

      it('Should block a remote account', async function () {
        await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
      })

      it('Should hide its videos', async function () {
        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)

        const videos: Video[] = res.body.data
        expect(videos).to.have.lengthOf(3)

        const v = videos.find(v => v.name === 'video user 2')
        expect(v).to.be.undefined
      })

      it('Should block a local account', async function () {
        await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
      })

      it('Should hide its videos', async function () {
        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)

        const videos: Video[] = res.body.data
        expect(videos).to.have.lengthOf(2)

        const v = videos.find(v => v.name === 'video user 1')
        expect(v).to.be.undefined
      })

      it('Should hide its comments', async function () {
        const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', servers[0].accessToken)

        const threads: VideoComment[] = resThreads.body.data
        expect(threads).to.have.lengthOf(1)
        expect(threads[0].totalReplies).to.equal(0)

        const t = threads.find(t => t.text === 'comment user 1')
        expect(t).to.be.undefined

        for (const thread of threads) {
          const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken)

          const tree: VideoCommentThreadTree = res.body
          expect(tree.children).to.have.lengthOf(0)
        }
      })

      it('Should not have notifications from blocked accounts', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
          await checkCommentNotification(servers[0], comment, 'absence')
        }

        {
          const comment = {
            server: servers[0],
            token: userToken1,
            videoUUID: videoUUID2,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'absence')
        }
      })

      it('Should list all the videos with another user', async function () {
        return checkAllVideos(servers[0].url, userToken1)
      })

      it('Should list all the comments with another user', async function () {
        return checkAllComments(servers[0].url, userToken1, videoUUID1)
      })

      it('Should list blocked accounts', async function () {
        {
          const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
          const blocks: AccountBlock[] = res.body.data

          expect(res.body.total).to.equal(2)

          const block = blocks[0]
          expect(block.byAccount.displayName).to.equal('root')
          expect(block.byAccount.name).to.equal('root')
          expect(block.blockedAccount.displayName).to.equal('user2')
          expect(block.blockedAccount.name).to.equal('user2')
          expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
        }

        {
          const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
          const blocks: AccountBlock[] = res.body.data

          expect(res.body.total).to.equal(2)

          const block = blocks[0]
          expect(block.byAccount.displayName).to.equal('root')
          expect(block.byAccount.name).to.equal('root')
          expect(block.blockedAccount.displayName).to.equal('user1')
          expect(block.blockedAccount.name).to.equal('user1')
          expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
        }
      })

      it('Should unblock the remote account', async function () {
        await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
      })

      it('Should display its videos', async function () {
        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)

        const videos: Video[] = res.body.data
        expect(videos).to.have.lengthOf(3)

        const v = videos.find(v => v.name === 'video user 2')
        expect(v).not.to.be.undefined
      })

      it('Should unblock the local account', async function () {
        await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
      })

      it('Should display its comments', function () {
        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
      })

      it('Should have a notification from a non blocked account', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
          await checkCommentNotification(servers[0], comment, 'presence')
        }

        {
          const comment = {
            server: servers[0],
            token: userToken1,
            videoUUID: videoUUID2,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'presence')
        }
      })
    })

    describe('When managing server blocklist', function () {
      it('Should list all videos', function () {
        return checkAllVideos(servers[0].url, servers[0].accessToken)
      })

      it('Should list the comments', function () {
        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
      })

      it('Should block a remote server', async function () {
        await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
      })

      it('Should hide its videos', async function () {
        const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)

        const videos: Video[] = res.body.data
        expect(videos).to.have.lengthOf(2)

        const v1 = videos.find(v => v.name === 'video user 2')
        const v2 = videos.find(v => v.name === 'video server 2')

        expect(v1).to.be.undefined
        expect(v2).to.be.undefined
      })

      it('Should list all the videos with another user', async function () {
        return checkAllVideos(servers[0].url, userToken1)
      })

      it('Should hide its comments', async function () {
        this.timeout(10000)

        const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
        const threadId = resThreads.body.comment.id

        await waitJobs(servers)

        await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)

        await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
      })

      it('Should not have notifications from blocked server', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
          await checkCommentNotification(servers[0], comment, 'absence')
        }

        {
          const comment = {
            server: servers[1],
            token: userToken2,
            videoUUID: videoUUID1,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'absence')
        }
      })

      it('Should list blocked servers', async function () {
        const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
        const blocks: ServerBlock[] = res.body.data

        expect(res.body.total).to.equal(1)

        const block = blocks[0]
        expect(block.byAccount.displayName).to.equal('root')
        expect(block.byAccount.name).to.equal('root')
        expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
      })

      it('Should unblock the remote server', async function () {
        await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
      })

      it('Should display its videos', function () {
        return checkAllVideos(servers[0].url, servers[0].accessToken)
      })

      it('Should display its comments', function () {
        return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
      })

      it('Should have notification from unblocked server', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
          await checkCommentNotification(servers[0], comment, 'presence')
        }

        {
          const comment = {
            server: servers[1],
            token: userToken2,
            videoUUID: videoUUID1,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'presence')
        }
      })
    })
  })

  describe('Server blocklist', function () {

    describe('When managing account blocklist', function () {
      it('Should list all videos', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          await checkAllVideos(servers[0].url, token)
        }
      })

      it('Should list the comments', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          await checkAllComments(servers[0].url, token, videoUUID1)
        }
      })

      it('Should block a remote account', async function () {
        await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
      })

      it('Should hide its videos', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          const res = await getVideosListWithToken(servers[0].url, token)

          const videos: Video[] = res.body.data
          expect(videos).to.have.lengthOf(3)

          const v = videos.find(v => v.name === 'video user 2')
          expect(v).to.be.undefined
        }
      })

      it('Should block a local account', async function () {
        await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
      })

      it('Should hide its videos', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          const res = await getVideosListWithToken(servers[0].url, token)

          const videos: Video[] = res.body.data
          expect(videos).to.have.lengthOf(2)

          const v = videos.find(v => v.name === 'video user 1')
          expect(v).to.be.undefined
        }
      })

      it('Should hide its comments', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', token)

          const threads: VideoComment[] = resThreads.body.data
          expect(threads).to.have.lengthOf(1)
          expect(threads[0].totalReplies).to.equal(0)

          const t = threads.find(t => t.text === 'comment user 1')
          expect(t).to.be.undefined

          for (const thread of threads) {
            const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token)

            const tree: VideoCommentThreadTree = res.body
            expect(tree.children).to.have.lengthOf(0)
          }
        }
      })

      it('Should not have notification from blocked accounts by instance', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
          await checkCommentNotification(servers[0], comment, 'absence')
        }

        {
          const comment = {
            server: servers[1],
            token: userToken2,
            videoUUID: videoUUID1,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'absence')
        }
      })

      it('Should list blocked accounts', async function () {
        {
          const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
          const blocks: AccountBlock[] = res.body.data

          expect(res.body.total).to.equal(2)

          const block = blocks[0]
          expect(block.byAccount.displayName).to.equal('peertube')
          expect(block.byAccount.name).to.equal('peertube')
          expect(block.blockedAccount.displayName).to.equal('user2')
          expect(block.blockedAccount.name).to.equal('user2')
          expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
        }

        {
          const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
          const blocks: AccountBlock[] = res.body.data

          expect(res.body.total).to.equal(2)

          const block = blocks[0]
          expect(block.byAccount.displayName).to.equal('peertube')
          expect(block.byAccount.name).to.equal('peertube')
          expect(block.blockedAccount.displayName).to.equal('user1')
          expect(block.blockedAccount.name).to.equal('user1')
          expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
        }
      })

      it('Should unblock the remote account', async function () {
        await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
      })

      it('Should display its videos', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          const res = await getVideosListWithToken(servers[0].url, token)

          const videos: Video[] = res.body.data
          expect(videos).to.have.lengthOf(3)

          const v = videos.find(v => v.name === 'video user 2')
          expect(v).not.to.be.undefined
        }
      })

      it('Should unblock the local account', async function () {
        await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
      })

      it('Should display its comments', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          await checkAllComments(servers[0].url, token, videoUUID1)
        }
      })

      it('Should have notifications from unblocked accounts', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
          await checkCommentNotification(servers[0], comment, 'presence')
        }

        {
          const comment = {
            server: servers[1],
            token: userToken2,
            videoUUID: videoUUID1,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'presence')
        }
      })
    })

    describe('When managing server blocklist', function () {
      it('Should list all videos', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          await checkAllVideos(servers[0].url, token)
        }
      })

      it('Should list the comments', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          await checkAllComments(servers[0].url, token, videoUUID1)
        }
      })

      it('Should block a remote server', async function () {
        await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
      })

      it('Should hide its videos', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          const res1 = await getVideosList(servers[0].url)
          const res2 = await getVideosListWithToken(servers[0].url, token)

          for (const res of [ res1, res2 ]) {
            const videos: Video[] = res.body.data
            expect(videos).to.have.lengthOf(2)

            const v1 = videos.find(v => v.name === 'video user 2')
            const v2 = videos.find(v => v.name === 'video server 2')

            expect(v1).to.be.undefined
            expect(v2).to.be.undefined
          }
        }
      })

      it('Should hide its comments', async function () {
        this.timeout(10000)

        const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
        const threadId = resThreads.body.comment.id

        await waitJobs(servers)

        await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)

        await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
      })

      it('Should not have notification from blocked instances by instance', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
          await checkCommentNotification(servers[0], comment, 'absence')
        }

        {
          const comment = {
            server: servers[1],
            token: userToken2,
            videoUUID: videoUUID1,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'absence')
        }
      })

      it('Should list blocked servers', async function () {
        const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
        const blocks: ServerBlock[] = res.body.data

        expect(res.body.total).to.equal(1)

        const block = blocks[0]
        expect(block.byAccount.displayName).to.equal('peertube')
        expect(block.byAccount.name).to.equal('peertube')
        expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
      })

      it('Should unblock the remote server', async function () {
        await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
      })

      it('Should list all videos', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          await checkAllVideos(servers[0].url, token)
        }
      })

      it('Should list the comments', async function () {
        for (const token of [ userModeratorToken, servers[0].accessToken ]) {
          await checkAllComments(servers[0].url, token, videoUUID1)
        }
      })

      it('Should have notification from unblocked instances', async function () {
        this.timeout(20000)

        {
          const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
          await checkCommentNotification(servers[0], comment, 'presence')
        }

        {
          const comment = {
            server: servers[1],
            token: userToken2,
            videoUUID: videoUUID1,
            text: 'hello @root@localhost:' + servers[0].port
          }
          await checkCommentNotification(servers[0], comment, 'presence')
        }
      })
    })
  })

  after(async function () {
    await cleanupTests(servers)
  })
})