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