]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/moderation/blocklist.ts
00cb6c65ce77ca26cd460abb6f5576509de5df3d
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 BlocklistCommand,
7 cleanupTests,
8 CommentsCommand,
9 createUser,
10 doubleFollow,
11 flushAndRunMultipleServers,
12 getUserNotifications,
13 getVideosList,
14 getVideosListWithToken,
15 ServerInfo,
16 setAccessTokensToServers,
17 uploadVideo,
18 userLogin,
19 waitJobs
20 } from '@shared/extra-utils'
21 import { UserNotification, UserNotificationType, Video } from '@shared/models'
22
23 const expect = chai.expect
24
25 async function checkAllVideos (server: ServerInfo, token: string) {
26 {
27 const res = await getVideosListWithToken(server.url, token)
28
29 expect(res.body.data).to.have.lengthOf(5)
30 }
31
32 {
33 const res = await getVideosList(server.url)
34
35 expect(res.body.data).to.have.lengthOf(5)
36 }
37 }
38
39 async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) {
40 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
41
42 const threads = data.filter(t => t.isDeleted === false)
43 expect(threads).to.have.lengthOf(2)
44
45 for (const thread of threads) {
46 const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token })
47 expect(tree.children).to.have.lengthOf(1)
48 }
49 }
50
51 async function checkCommentNotification (
52 mainServer: ServerInfo,
53 comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
54 check: 'presence' | 'absence'
55 ) {
56 const command = comment.server.commentsCommand
57
58 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
59
60 await waitJobs([ mainServer, comment.server ])
61
62 const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30)
63 const commentNotifications = (res.body.data as UserNotification[])
64 .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
65
66 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
67 else expect(commentNotifications).to.have.lengthOf(0)
68
69 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
70
71 await waitJobs([ mainServer, comment.server ])
72 }
73
74 describe('Test blocklist', function () {
75 let servers: ServerInfo[]
76 let videoUUID1: string
77 let videoUUID2: string
78 let videoUUID3: string
79 let userToken1: string
80 let userModeratorToken: string
81 let userToken2: string
82
83 let command: BlocklistCommand
84 let commentsCommand: CommentsCommand[]
85
86 before(async function () {
87 this.timeout(120000)
88
89 servers = await flushAndRunMultipleServers(3)
90 await setAccessTokensToServers(servers)
91
92 command = servers[0].blocklistCommand
93 commentsCommand = servers.map(s => s.commentsCommand)
94
95 {
96 const user = { username: 'user1', password: 'password' }
97 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
98
99 userToken1 = await userLogin(servers[0], user)
100 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
101 }
102
103 {
104 const user = { username: 'moderator', password: 'password' }
105 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
106
107 userModeratorToken = await userLogin(servers[0], user)
108 }
109
110 {
111 const user = { username: 'user2', password: 'password' }
112 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
113
114 userToken2 = await userLogin(servers[1], user)
115 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
116 }
117
118 {
119 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
120 videoUUID1 = res.body.video.uuid
121 }
122
123 {
124 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
125 videoUUID2 = res.body.video.uuid
126 }
127
128 {
129 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
130 videoUUID3 = res.body.video.uuid
131 }
132
133 await doubleFollow(servers[0], servers[1])
134 await doubleFollow(servers[0], servers[2])
135
136 {
137 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
138 const reply = await commentsCommand[0].addReply({
139 token: userToken1,
140 videoId: videoUUID1,
141 toCommentId: created.id,
142 text: 'comment user 1'
143 })
144 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
145 }
146
147 {
148 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
149 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
150 }
151
152 await waitJobs(servers)
153 })
154
155 describe('User blocklist', function () {
156
157 describe('When managing account blocklist', function () {
158 it('Should list all videos', function () {
159 return checkAllVideos(servers[0], servers[0].accessToken)
160 })
161
162 it('Should list the comments', function () {
163 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
164 })
165
166 it('Should block a remote account', async function () {
167 await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
168 })
169
170 it('Should hide its videos', async function () {
171 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
172
173 const videos: Video[] = res.body.data
174 expect(videos).to.have.lengthOf(4)
175
176 const v = videos.find(v => v.name === 'video user 2')
177 expect(v).to.be.undefined
178 })
179
180 it('Should block a local account', async function () {
181 await command.addToMyBlocklist({ account: 'user1' })
182 })
183
184 it('Should hide its videos', async function () {
185 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
186
187 const videos: Video[] = res.body.data
188 expect(videos).to.have.lengthOf(3)
189
190 const v = videos.find(v => v.name === 'video user 1')
191 expect(v).to.be.undefined
192 })
193
194 it('Should hide its comments', async function () {
195 const { data } = await commentsCommand[0].listThreads({
196 token: servers[0].accessToken,
197 videoId: videoUUID1,
198 start: 0,
199 count: 25,
200 sort: '-createdAt'
201 })
202
203 expect(data).to.have.lengthOf(1)
204 expect(data[0].totalReplies).to.equal(1)
205
206 const t = data.find(t => t.text === 'comment user 1')
207 expect(t).to.be.undefined
208
209 for (const thread of data) {
210 const tree = await commentsCommand[0].getThread({
211 videoId: videoUUID1,
212 threadId: thread.id,
213 token: servers[0].accessToken
214 })
215 expect(tree.children).to.have.lengthOf(0)
216 }
217 })
218
219 it('Should not have notifications from blocked accounts', async function () {
220 this.timeout(20000)
221
222 {
223 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
224 await checkCommentNotification(servers[0], comment, 'absence')
225 }
226
227 {
228 const comment = {
229 server: servers[0],
230 token: userToken1,
231 videoUUID: videoUUID2,
232 text: 'hello @root@localhost:' + servers[0].port
233 }
234 await checkCommentNotification(servers[0], comment, 'absence')
235 }
236 })
237
238 it('Should list all the videos with another user', async function () {
239 return checkAllVideos(servers[0], userToken1)
240 })
241
242 it('Should list blocked accounts', async function () {
243 {
244 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
245 expect(body.total).to.equal(2)
246
247 const block = body.data[0]
248 expect(block.byAccount.displayName).to.equal('root')
249 expect(block.byAccount.name).to.equal('root')
250 expect(block.blockedAccount.displayName).to.equal('user2')
251 expect(block.blockedAccount.name).to.equal('user2')
252 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
253 }
254
255 {
256 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
257 expect(body.total).to.equal(2)
258
259 const block = body.data[0]
260 expect(block.byAccount.displayName).to.equal('root')
261 expect(block.byAccount.name).to.equal('root')
262 expect(block.blockedAccount.displayName).to.equal('user1')
263 expect(block.blockedAccount.name).to.equal('user1')
264 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
265 }
266 })
267
268 it('Should not allow a remote blocked user to comment my videos', async function () {
269 this.timeout(60000)
270
271 {
272 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
273 await waitJobs(servers)
274
275 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
276 await waitJobs(servers)
277
278 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
279 const message = 'reply by user 2'
280 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
281 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
282
283 await waitJobs(servers)
284 }
285
286 // Server 2 has all the comments
287 {
288 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
289
290 expect(data).to.have.lengthOf(2)
291 expect(data[0].text).to.equal('uploader')
292 expect(data[1].text).to.equal('comment user 2')
293
294 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
295 expect(tree.children).to.have.lengthOf(1)
296 expect(tree.children[0].comment.text).to.equal('reply by user 2')
297 expect(tree.children[0].children).to.have.lengthOf(1)
298 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
299 }
300
301 // Server 1 and 3 should only have uploader comments
302 for (const server of [ servers[0], servers[2] ]) {
303 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
304
305 expect(data).to.have.lengthOf(1)
306 expect(data[0].text).to.equal('uploader')
307
308 const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
309
310 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
311 else expect(tree.children).to.have.lengthOf(1)
312 }
313 })
314
315 it('Should unblock the remote account', async function () {
316 await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
317 })
318
319 it('Should display its videos', async function () {
320 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
321
322 const videos: Video[] = res.body.data
323 expect(videos).to.have.lengthOf(4)
324
325 const v = videos.find(v => v.name === 'video user 2')
326 expect(v).not.to.be.undefined
327 })
328
329 it('Should display its comments on my video', async function () {
330 for (const server of servers) {
331 const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
332
333 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
334 if (server.serverNumber === 3) {
335 expect(data).to.have.lengthOf(1)
336 continue
337 }
338
339 expect(data).to.have.lengthOf(2)
340 expect(data[0].text).to.equal('uploader')
341 expect(data[1].text).to.equal('comment user 2')
342
343 const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
344 expect(tree.children).to.have.lengthOf(1)
345 expect(tree.children[0].comment.text).to.equal('reply by user 2')
346 expect(tree.children[0].children).to.have.lengthOf(1)
347 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
348 }
349 })
350
351 it('Should unblock the local account', async function () {
352 await command.removeFromMyBlocklist({ account: 'user1' })
353 })
354
355 it('Should display its comments', function () {
356 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
357 })
358
359 it('Should have a notification from a non blocked account', async function () {
360 this.timeout(20000)
361
362 {
363 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
364 await checkCommentNotification(servers[0], comment, 'presence')
365 }
366
367 {
368 const comment = {
369 server: servers[0],
370 token: userToken1,
371 videoUUID: videoUUID2,
372 text: 'hello @root@localhost:' + servers[0].port
373 }
374 await checkCommentNotification(servers[0], comment, 'presence')
375 }
376 })
377 })
378
379 describe('When managing server blocklist', function () {
380
381 it('Should list all videos', function () {
382 return checkAllVideos(servers[0], servers[0].accessToken)
383 })
384
385 it('Should list the comments', function () {
386 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
387 })
388
389 it('Should block a remote server', async function () {
390 await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
391 })
392
393 it('Should hide its videos', async function () {
394 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
395
396 const videos: Video[] = res.body.data
397 expect(videos).to.have.lengthOf(3)
398
399 const v1 = videos.find(v => v.name === 'video user 2')
400 const v2 = videos.find(v => v.name === 'video server 2')
401
402 expect(v1).to.be.undefined
403 expect(v2).to.be.undefined
404 })
405
406 it('Should list all the videos with another user', async function () {
407 return checkAllVideos(servers[0], userToken1)
408 })
409
410 it('Should hide its comments', async function () {
411 this.timeout(10000)
412
413 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
414
415 await waitJobs(servers)
416
417 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
418
419 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
420 })
421
422 it('Should not have notifications from blocked server', async function () {
423 this.timeout(20000)
424
425 {
426 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
427 await checkCommentNotification(servers[0], comment, 'absence')
428 }
429
430 {
431 const comment = {
432 server: servers[1],
433 token: userToken2,
434 videoUUID: videoUUID1,
435 text: 'hello @root@localhost:' + servers[0].port
436 }
437 await checkCommentNotification(servers[0], comment, 'absence')
438 }
439 })
440
441 it('Should list blocked servers', async function () {
442 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
443 expect(body.total).to.equal(1)
444
445 const block = body.data[0]
446 expect(block.byAccount.displayName).to.equal('root')
447 expect(block.byAccount.name).to.equal('root')
448 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
449 })
450
451 it('Should unblock the remote server', async function () {
452 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
453 })
454
455 it('Should display its videos', function () {
456 return checkAllVideos(servers[0], servers[0].accessToken)
457 })
458
459 it('Should display its comments', function () {
460 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
461 })
462
463 it('Should have notification from unblocked server', async function () {
464 this.timeout(20000)
465
466 {
467 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
468 await checkCommentNotification(servers[0], comment, 'presence')
469 }
470
471 {
472 const comment = {
473 server: servers[1],
474 token: userToken2,
475 videoUUID: videoUUID1,
476 text: 'hello @root@localhost:' + servers[0].port
477 }
478 await checkCommentNotification(servers[0], comment, 'presence')
479 }
480 })
481 })
482 })
483
484 describe('Server blocklist', function () {
485
486 describe('When managing account blocklist', function () {
487 it('Should list all videos', async function () {
488 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
489 await checkAllVideos(servers[0], token)
490 }
491 })
492
493 it('Should list the comments', async function () {
494 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
495 await checkAllComments(servers[0], token, videoUUID1)
496 }
497 })
498
499 it('Should block a remote account', async function () {
500 await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
501 })
502
503 it('Should hide its videos', async function () {
504 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
505 const res = await getVideosListWithToken(servers[0].url, token)
506
507 const videos: Video[] = res.body.data
508 expect(videos).to.have.lengthOf(4)
509
510 const v = videos.find(v => v.name === 'video user 2')
511 expect(v).to.be.undefined
512 }
513 })
514
515 it('Should block a local account', async function () {
516 await command.addToServerBlocklist({ account: 'user1' })
517 })
518
519 it('Should hide its videos', async function () {
520 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
521 const res = await getVideosListWithToken(servers[0].url, token)
522
523 const videos: Video[] = res.body.data
524 expect(videos).to.have.lengthOf(3)
525
526 const v = videos.find(v => v.name === 'video user 1')
527 expect(v).to.be.undefined
528 }
529 })
530
531 it('Should hide its comments', async function () {
532 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
533 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
534 const threads = data.filter(t => t.isDeleted === false)
535
536 expect(threads).to.have.lengthOf(1)
537 expect(threads[0].totalReplies).to.equal(1)
538
539 const t = threads.find(t => t.text === 'comment user 1')
540 expect(t).to.be.undefined
541
542 for (const thread of threads) {
543 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
544 expect(tree.children).to.have.lengthOf(0)
545 }
546 }
547 })
548
549 it('Should not have notification from blocked accounts by instance', async function () {
550 this.timeout(20000)
551
552 {
553 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
554 await checkCommentNotification(servers[0], comment, 'absence')
555 }
556
557 {
558 const comment = {
559 server: servers[1],
560 token: userToken2,
561 videoUUID: videoUUID1,
562 text: 'hello @root@localhost:' + servers[0].port
563 }
564 await checkCommentNotification(servers[0], comment, 'absence')
565 }
566 })
567
568 it('Should list blocked accounts', async function () {
569 {
570 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
571 expect(body.total).to.equal(2)
572
573 const block = body.data[0]
574 expect(block.byAccount.displayName).to.equal('peertube')
575 expect(block.byAccount.name).to.equal('peertube')
576 expect(block.blockedAccount.displayName).to.equal('user2')
577 expect(block.blockedAccount.name).to.equal('user2')
578 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
579 }
580
581 {
582 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
583 expect(body.total).to.equal(2)
584
585 const block = body.data[0]
586 expect(block.byAccount.displayName).to.equal('peertube')
587 expect(block.byAccount.name).to.equal('peertube')
588 expect(block.blockedAccount.displayName).to.equal('user1')
589 expect(block.blockedAccount.name).to.equal('user1')
590 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
591 }
592 })
593
594 it('Should unblock the remote account', async function () {
595 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
596 })
597
598 it('Should display its videos', async function () {
599 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
600 const res = await getVideosListWithToken(servers[0].url, token)
601
602 const videos: Video[] = res.body.data
603 expect(videos).to.have.lengthOf(4)
604
605 const v = videos.find(v => v.name === 'video user 2')
606 expect(v).not.to.be.undefined
607 }
608 })
609
610 it('Should unblock the local account', async function () {
611 await command.removeFromServerBlocklist({ account: 'user1' })
612 })
613
614 it('Should display its comments', async function () {
615 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
616 await checkAllComments(servers[0], token, videoUUID1)
617 }
618 })
619
620 it('Should have notifications from unblocked accounts', async function () {
621 this.timeout(20000)
622
623 {
624 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
625 await checkCommentNotification(servers[0], comment, 'presence')
626 }
627
628 {
629 const comment = {
630 server: servers[1],
631 token: userToken2,
632 videoUUID: videoUUID1,
633 text: 'hello @root@localhost:' + servers[0].port
634 }
635 await checkCommentNotification(servers[0], comment, 'presence')
636 }
637 })
638 })
639
640 describe('When managing server blocklist', function () {
641 it('Should list all videos', async function () {
642 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
643 await checkAllVideos(servers[0], token)
644 }
645 })
646
647 it('Should list the comments', async function () {
648 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
649 await checkAllComments(servers[0], token, videoUUID1)
650 }
651 })
652
653 it('Should block a remote server', async function () {
654 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
655 })
656
657 it('Should hide its videos', async function () {
658 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
659 const res1 = await getVideosList(servers[0].url)
660 const res2 = await getVideosListWithToken(servers[0].url, token)
661
662 for (const res of [ res1, res2 ]) {
663 const videos: Video[] = res.body.data
664 expect(videos).to.have.lengthOf(3)
665
666 const v1 = videos.find(v => v.name === 'video user 2')
667 const v2 = videos.find(v => v.name === 'video server 2')
668
669 expect(v1).to.be.undefined
670 expect(v2).to.be.undefined
671 }
672 }
673 })
674
675 it('Should hide its comments', async function () {
676 this.timeout(10000)
677
678 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
679
680 await waitJobs(servers)
681
682 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
683
684 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
685 })
686
687 it('Should not have notification from blocked instances by instance', async function () {
688 this.timeout(50000)
689
690 {
691 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
692 await checkCommentNotification(servers[0], comment, 'absence')
693 }
694
695 {
696 const comment = {
697 server: servers[1],
698 token: userToken2,
699 videoUUID: videoUUID1,
700 text: 'hello @root@localhost:' + servers[0].port
701 }
702 await checkCommentNotification(servers[0], comment, 'absence')
703 }
704
705 {
706 const now = new Date()
707 await servers[1].followsCommand.unfollow({ target: servers[0] })
708 await waitJobs(servers)
709 await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
710
711 await waitJobs(servers)
712
713 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30)
714 const commentNotifications = (res.body.data as UserNotification[])
715 .filter(n => {
716 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER &&
717 n.createdAt >= now.toISOString()
718 })
719
720 expect(commentNotifications).to.have.lengthOf(0)
721 }
722 })
723
724 it('Should list blocked servers', async function () {
725 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
726 expect(body.total).to.equal(1)
727
728 const block = body.data[0]
729 expect(block.byAccount.displayName).to.equal('peertube')
730 expect(block.byAccount.name).to.equal('peertube')
731 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
732 })
733
734 it('Should unblock the remote server', async function () {
735 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
736 })
737
738 it('Should list all videos', async function () {
739 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
740 await checkAllVideos(servers[0], token)
741 }
742 })
743
744 it('Should list the comments', async function () {
745 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
746 await checkAllComments(servers[0], token, videoUUID1)
747 }
748 })
749
750 it('Should have notification from unblocked instances', async function () {
751 this.timeout(50000)
752
753 {
754 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
755 await checkCommentNotification(servers[0], comment, 'presence')
756 }
757
758 {
759 const comment = {
760 server: servers[1],
761 token: userToken2,
762 videoUUID: videoUUID1,
763 text: 'hello @root@localhost:' + servers[0].port
764 }
765 await checkCommentNotification(servers[0], comment, 'presence')
766 }
767
768 {
769 const now = new Date()
770 await servers[1].followsCommand.unfollow({ target: servers[0] })
771 await waitJobs(servers)
772 await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
773
774 await waitJobs(servers)
775
776 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30)
777 const commentNotifications = (res.body.data as UserNotification[])
778 .filter(n => {
779 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER &&
780 n.createdAt >= now.toISOString()
781 })
782
783 expect(commentNotifications).to.have.lengthOf(1)
784 }
785 })
786 })
787 })
788
789 after(async function () {
790 await cleanupTests(servers)
791 })
792 })