1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { UserNotificationType } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
15 } from '@shared/server-commands'
17 async function checkAllVideos (server: PeerTubeServer, token: string) {
19 const { data } = await server.videos.listWithToken({ token })
20 expect(data).to.have.lengthOf(5)
24 const { data } = await server.videos.list()
25 expect(data).to.have.lengthOf(5)
29 async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
30 const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
32 const threads = data.filter(t => t.isDeleted === false)
33 expect(threads).to.have.lengthOf(2)
35 for (const thread of threads) {
36 const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
37 expect(tree.children).to.have.lengthOf(1)
41 async function checkCommentNotification (
42 mainServer: PeerTubeServer,
43 comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
44 check: 'presence' | 'absence'
46 const command = comment.server.comments
48 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
50 await waitJobs([ mainServer, comment.server ])
52 const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
53 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
55 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
56 else expect(commentNotifications).to.have.lengthOf(0)
58 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
60 await waitJobs([ mainServer, comment.server ])
63 describe('Test blocklist', function () {
64 let servers: PeerTubeServer[]
65 let videoUUID1: string
66 let videoUUID2: string
67 let videoUUID3: string
68 let userToken1: string
69 let userModeratorToken: string
70 let userToken2: string
72 let command: BlocklistCommand
73 let commentsCommand: CommentsCommand[]
75 before(async function () {
78 servers = await createMultipleServers(3)
79 await setAccessTokensToServers(servers)
80 await setDefaultAccountAvatar(servers)
82 command = servers[0].blocklist
83 commentsCommand = servers.map(s => s.comments)
86 const user = { username: 'user1', password: 'password' }
87 await servers[0].users.create({ username: user.username, password: user.password })
89 userToken1 = await servers[0].login.getAccessToken(user)
90 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
94 const user = { username: 'moderator', password: 'password' }
95 await servers[0].users.create({ username: user.username, password: user.password })
97 userModeratorToken = await servers[0].login.getAccessToken(user)
101 const user = { username: 'user2', password: 'password' }
102 await servers[1].users.create({ username: user.username, password: user.password })
104 userToken2 = await servers[1].login.getAccessToken(user)
105 await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
109 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
114 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
119 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
123 await doubleFollow(servers[0], servers[1])
124 await doubleFollow(servers[0], servers[2])
127 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
128 const reply = await commentsCommand[0].addReply({
131 toCommentId: created.id,
132 text: 'comment user 1'
134 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
138 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
139 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
142 await waitJobs(servers)
145 describe('User blocklist', function () {
147 describe('When managing account blocklist', function () {
148 it('Should list all videos', function () {
149 return checkAllVideos(servers[0], servers[0].accessToken)
152 it('Should list the comments', function () {
153 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
156 it('Should block a remote account', async function () {
157 await command.addToMyBlocklist({ account: 'user2@' + servers[1].host })
160 it('Should hide its videos', async function () {
161 const { data } = await servers[0].videos.listWithToken()
163 expect(data).to.have.lengthOf(4)
165 const v = data.find(v => v.name === 'video user 2')
166 expect(v).to.be.undefined
169 it('Should block a local account', async function () {
170 await command.addToMyBlocklist({ account: 'user1' })
173 it('Should hide its videos', async function () {
174 const { data } = await servers[0].videos.listWithToken()
176 expect(data).to.have.lengthOf(3)
178 const v = data.find(v => v.name === 'video user 1')
179 expect(v).to.be.undefined
182 it('Should hide its comments', async function () {
183 const { data } = await commentsCommand[0].listThreads({
184 token: servers[0].accessToken,
191 expect(data).to.have.lengthOf(1)
192 expect(data[0].totalReplies).to.equal(1)
194 const t = data.find(t => t.text === 'comment user 1')
195 expect(t).to.be.undefined
197 for (const thread of data) {
198 const tree = await commentsCommand[0].getThread({
201 token: servers[0].accessToken
203 expect(tree.children).to.have.lengthOf(0)
207 it('Should not have notifications from blocked accounts', async function () {
211 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
212 await checkCommentNotification(servers[0], comment, 'absence')
219 videoUUID: videoUUID2,
220 text: 'hello @root@' + servers[0].host
222 await checkCommentNotification(servers[0], comment, 'absence')
226 it('Should list all the videos with another user', async function () {
227 return checkAllVideos(servers[0], userToken1)
230 it('Should list blocked accounts', async function () {
232 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
233 expect(body.total).to.equal(2)
235 const block = body.data[0]
236 expect(block.byAccount.displayName).to.equal('root')
237 expect(block.byAccount.name).to.equal('root')
238 expect(block.blockedAccount.displayName).to.equal('user2')
239 expect(block.blockedAccount.name).to.equal('user2')
240 expect(block.blockedAccount.host).to.equal('' + servers[1].host)
244 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
245 expect(body.total).to.equal(2)
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('user1')
251 expect(block.blockedAccount.name).to.equal('user1')
252 expect(block.blockedAccount.host).to.equal('' + servers[0].host)
256 it('Should search blocked accounts', async function () {
257 const body = await command.listMyAccountBlocklist({ start: 0, count: 10, search: 'user2' })
258 expect(body.total).to.equal(1)
260 expect(body.data[0].blockedAccount.name).to.equal('user2')
263 it('Should get blocked status', async function () {
264 const remoteHandle = 'user2@' + servers[1].host
265 const localHandle = 'user1@' + servers[0].host
266 const unknownHandle = 'user5@' + servers[0].host
269 const status = await command.getStatus({ accounts: [ remoteHandle ] })
270 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
271 expect(status.accounts[remoteHandle].blockedByUser).to.be.false
272 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
274 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
278 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] })
279 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
280 expect(status.accounts[remoteHandle].blockedByUser).to.be.true
281 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
283 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
287 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
288 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
290 for (const handle of [ localHandle, remoteHandle ]) {
291 expect(status.accounts[handle].blockedByUser).to.be.true
292 expect(status.accounts[handle].blockedByServer).to.be.false
295 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
296 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
298 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
302 it('Should not allow a remote blocked user to comment my videos', async function () {
306 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
307 await waitJobs(servers)
309 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
310 await waitJobs(servers)
312 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
313 const message = 'reply by user 2'
314 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
315 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
317 await waitJobs(servers)
320 // Server 2 has all the comments
322 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
324 expect(data).to.have.lengthOf(2)
325 expect(data[0].text).to.equal('uploader')
326 expect(data[1].text).to.equal('comment user 2')
328 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
329 expect(tree.children).to.have.lengthOf(1)
330 expect(tree.children[0].comment.text).to.equal('reply by user 2')
331 expect(tree.children[0].children).to.have.lengthOf(1)
332 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
335 // Server 1 and 3 should only have uploader comments
336 for (const server of [ servers[0], servers[2] ]) {
337 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
339 expect(data).to.have.lengthOf(1)
340 expect(data[0].text).to.equal('uploader')
342 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
344 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
345 else expect(tree.children).to.have.lengthOf(1)
349 it('Should unblock the remote account', async function () {
350 await command.removeFromMyBlocklist({ account: 'user2@' + servers[1].host })
353 it('Should display its videos', async function () {
354 const { data } = await servers[0].videos.listWithToken()
355 expect(data).to.have.lengthOf(4)
357 const v = data.find(v => v.name === 'video user 2')
358 expect(v).not.to.be.undefined
361 it('Should display its comments on my video', async function () {
362 for (const server of servers) {
363 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
365 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
366 if (server.serverNumber === 3) {
367 expect(data).to.have.lengthOf(1)
371 expect(data).to.have.lengthOf(2)
372 expect(data[0].text).to.equal('uploader')
373 expect(data[1].text).to.equal('comment user 2')
375 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
376 expect(tree.children).to.have.lengthOf(1)
377 expect(tree.children[0].comment.text).to.equal('reply by user 2')
378 expect(tree.children[0].children).to.have.lengthOf(1)
379 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
383 it('Should unblock the local account', async function () {
384 await command.removeFromMyBlocklist({ account: 'user1' })
387 it('Should display its comments', function () {
388 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
391 it('Should have a notification from a non blocked account', async function () {
395 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
396 await checkCommentNotification(servers[0], comment, 'presence')
403 videoUUID: videoUUID2,
404 text: 'hello @root@' + servers[0].host
406 await checkCommentNotification(servers[0], comment, 'presence')
411 describe('When managing server blocklist', function () {
413 it('Should list all videos', function () {
414 return checkAllVideos(servers[0], servers[0].accessToken)
417 it('Should list the comments', function () {
418 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
421 it('Should block a remote server', async function () {
422 await command.addToMyBlocklist({ server: '' + servers[1].host })
425 it('Should hide its videos', async function () {
426 const { data } = await servers[0].videos.listWithToken()
428 expect(data).to.have.lengthOf(3)
430 const v1 = data.find(v => v.name === 'video user 2')
431 const v2 = data.find(v => v.name === 'video server 2')
433 expect(v1).to.be.undefined
434 expect(v2).to.be.undefined
437 it('Should list all the videos with another user', async function () {
438 return checkAllVideos(servers[0], userToken1)
441 it('Should hide its comments', async function () {
442 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
444 await waitJobs(servers)
446 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
448 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
451 it('Should not have notifications from blocked server', async function () {
455 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
456 await checkCommentNotification(servers[0], comment, 'absence')
463 videoUUID: videoUUID1,
464 text: 'hello @root@' + servers[0].host
466 await checkCommentNotification(servers[0], comment, 'absence')
470 it('Should list blocked servers', async function () {
471 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
472 expect(body.total).to.equal(1)
474 const block = body.data[0]
475 expect(block.byAccount.displayName).to.equal('root')
476 expect(block.byAccount.name).to.equal('root')
477 expect(block.blockedServer.host).to.equal('' + servers[1].host)
480 it('Should search blocked servers', async function () {
481 const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host })
482 expect(body.total).to.equal(1)
484 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
487 it('Should get blocklist status', async function () {
488 const blockedServer = servers[1].host
489 const notBlockedServer = 'example.com'
492 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
493 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
495 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
496 expect(status.hosts[blockedServer].blockedByUser).to.be.false
497 expect(status.hosts[blockedServer].blockedByServer).to.be.false
499 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
500 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
504 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
505 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
507 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
508 expect(status.hosts[blockedServer].blockedByUser).to.be.true
509 expect(status.hosts[blockedServer].blockedByServer).to.be.false
511 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
512 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
516 it('Should unblock the remote server', async function () {
517 await command.removeFromMyBlocklist({ server: '' + servers[1].host })
520 it('Should display its videos', function () {
521 return checkAllVideos(servers[0], servers[0].accessToken)
524 it('Should display its comments', function () {
525 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
528 it('Should have notification from unblocked server', async function () {
532 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
533 await checkCommentNotification(servers[0], comment, 'presence')
540 videoUUID: videoUUID1,
541 text: 'hello @root@' + servers[0].host
543 await checkCommentNotification(servers[0], comment, 'presence')
549 describe('Server blocklist', function () {
551 describe('When managing account blocklist', function () {
552 it('Should list all videos', async function () {
553 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
554 await checkAllVideos(servers[0], token)
558 it('Should list the comments', async function () {
559 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
560 await checkAllComments(servers[0], token, videoUUID1)
564 it('Should block a remote account', async function () {
565 await command.addToServerBlocklist({ account: 'user2@' + servers[1].host })
568 it('Should hide its videos', async function () {
569 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
570 const { data } = await servers[0].videos.listWithToken({ token })
572 expect(data).to.have.lengthOf(4)
574 const v = data.find(v => v.name === 'video user 2')
575 expect(v).to.be.undefined
579 it('Should block a local account', async function () {
580 await command.addToServerBlocklist({ account: 'user1' })
583 it('Should hide its videos', async function () {
584 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
585 const { data } = await servers[0].videos.listWithToken({ token })
587 expect(data).to.have.lengthOf(3)
589 const v = data.find(v => v.name === 'video user 1')
590 expect(v).to.be.undefined
594 it('Should hide its comments', async function () {
595 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
596 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
597 const threads = data.filter(t => t.isDeleted === false)
599 expect(threads).to.have.lengthOf(1)
600 expect(threads[0].totalReplies).to.equal(1)
602 const t = threads.find(t => t.text === 'comment user 1')
603 expect(t).to.be.undefined
605 for (const thread of threads) {
606 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
607 expect(tree.children).to.have.lengthOf(0)
612 it('Should not have notification from blocked accounts by instance', async function () {
616 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
617 await checkCommentNotification(servers[0], comment, 'absence')
624 videoUUID: videoUUID1,
625 text: 'hello @root@' + servers[0].host
627 await checkCommentNotification(servers[0], comment, 'absence')
631 it('Should list blocked accounts', async function () {
633 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
634 expect(body.total).to.equal(2)
636 const block = body.data[0]
637 expect(block.byAccount.displayName).to.equal('peertube')
638 expect(block.byAccount.name).to.equal('peertube')
639 expect(block.blockedAccount.displayName).to.equal('user2')
640 expect(block.blockedAccount.name).to.equal('user2')
641 expect(block.blockedAccount.host).to.equal('' + servers[1].host)
645 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
646 expect(body.total).to.equal(2)
648 const block = body.data[0]
649 expect(block.byAccount.displayName).to.equal('peertube')
650 expect(block.byAccount.name).to.equal('peertube')
651 expect(block.blockedAccount.displayName).to.equal('user1')
652 expect(block.blockedAccount.name).to.equal('user1')
653 expect(block.blockedAccount.host).to.equal('' + servers[0].host)
657 it('Should search blocked accounts', async function () {
658 const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' })
659 expect(body.total).to.equal(1)
661 expect(body.data[0].blockedAccount.name).to.equal('user2')
664 it('Should get blocked status', async function () {
665 const remoteHandle = 'user2@' + servers[1].host
666 const localHandle = 'user1@' + servers[0].host
667 const unknownHandle = 'user5@' + servers[0].host
669 for (const token of [ undefined, servers[0].accessToken ]) {
670 const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
671 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
673 for (const handle of [ localHandle, remoteHandle ]) {
674 expect(status.accounts[handle].blockedByUser).to.be.false
675 expect(status.accounts[handle].blockedByServer).to.be.true
678 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
679 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
681 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
685 it('Should unblock the remote account', async function () {
686 await command.removeFromServerBlocklist({ account: 'user2@' + servers[1].host })
689 it('Should display its videos', async function () {
690 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
691 const { data } = await servers[0].videos.listWithToken({ token })
692 expect(data).to.have.lengthOf(4)
694 const v = data.find(v => v.name === 'video user 2')
695 expect(v).not.to.be.undefined
699 it('Should unblock the local account', async function () {
700 await command.removeFromServerBlocklist({ account: 'user1' })
703 it('Should display its comments', async function () {
704 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
705 await checkAllComments(servers[0], token, videoUUID1)
709 it('Should have notifications from unblocked accounts', async function () {
713 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
714 await checkCommentNotification(servers[0], comment, 'presence')
721 videoUUID: videoUUID1,
722 text: 'hello @root@' + servers[0].host
724 await checkCommentNotification(servers[0], comment, 'presence')
729 describe('When managing server blocklist', function () {
731 it('Should list all videos', async function () {
732 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
733 await checkAllVideos(servers[0], token)
737 it('Should list the comments', async function () {
738 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
739 await checkAllComments(servers[0], token, videoUUID1)
743 it('Should block a remote server', async function () {
744 await command.addToServerBlocklist({ server: '' + servers[1].host })
747 it('Should hide its videos', async function () {
748 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
750 servers[0].videos.list(),
751 servers[0].videos.listWithToken({ token })
754 for (const req of requests) {
755 const { data } = await req
756 expect(data).to.have.lengthOf(3)
758 const v1 = data.find(v => v.name === 'video user 2')
759 const v2 = data.find(v => v.name === 'video server 2')
761 expect(v1).to.be.undefined
762 expect(v2).to.be.undefined
767 it('Should hide its comments', async function () {
768 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
770 await waitJobs(servers)
772 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
774 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
777 it('Should not have notification from blocked instances by instance', async function () {
781 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
782 await checkCommentNotification(servers[0], comment, 'absence')
789 videoUUID: videoUUID1,
790 text: 'hello @root@' + servers[0].host
792 await checkCommentNotification(servers[0], comment, 'absence')
796 const now = new Date()
797 await servers[1].follows.unfollow({ target: servers[0] })
798 await waitJobs(servers)
799 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
801 await waitJobs(servers)
803 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
804 const commentNotifications = data.filter(n => {
805 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
808 expect(commentNotifications).to.have.lengthOf(0)
812 it('Should list blocked servers', async function () {
813 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
814 expect(body.total).to.equal(1)
816 const block = body.data[0]
817 expect(block.byAccount.displayName).to.equal('peertube')
818 expect(block.byAccount.name).to.equal('peertube')
819 expect(block.blockedServer.host).to.equal('' + servers[1].host)
822 it('Should search blocked servers', async function () {
823 const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host })
824 expect(body.total).to.equal(1)
826 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
829 it('Should get blocklist status', async function () {
830 const blockedServer = servers[1].host
831 const notBlockedServer = 'example.com'
833 for (const token of [ undefined, servers[0].accessToken ]) {
834 const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
835 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
837 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
838 expect(status.hosts[blockedServer].blockedByUser).to.be.false
839 expect(status.hosts[blockedServer].blockedByServer).to.be.true
841 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
842 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
846 it('Should unblock the remote server', async function () {
847 await command.removeFromServerBlocklist({ server: '' + servers[1].host })
850 it('Should list all videos', async function () {
851 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
852 await checkAllVideos(servers[0], token)
856 it('Should list the comments', async function () {
857 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
858 await checkAllComments(servers[0], token, videoUUID1)
862 it('Should have notification from unblocked instances', async function () {
866 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
867 await checkCommentNotification(servers[0], comment, 'presence')
874 videoUUID: videoUUID1,
875 text: 'hello @root@' + servers[0].host
877 await checkCommentNotification(servers[0], comment, 'presence')
881 const now = new Date()
882 await servers[1].follows.unfollow({ target: servers[0] })
883 await waitJobs(servers)
884 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
886 await waitJobs(servers)
888 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
889 const commentNotifications = data.filter(n => {
890 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
893 expect(commentNotifications).to.have.lengthOf(1)
899 after(async function () {
900 await cleanupTests(servers)