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