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