1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
12 setAccessTokensToServers,
14 } from '@shared/server-commands'
15 import { UserNotificationType } from '@shared/models'
17 const expect = chai.expect
19 async function checkAllVideos (server: PeerTubeServer, token: string) {
21 const { data } = await server.videos.listWithToken({ token })
22 expect(data).to.have.lengthOf(5)
26 const { data } = await server.videos.list()
27 expect(data).to.have.lengthOf(5)
31 async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
32 const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
34 const threads = data.filter(t => t.isDeleted === false)
35 expect(threads).to.have.lengthOf(2)
37 for (const thread of threads) {
38 const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
39 expect(tree.children).to.have.lengthOf(1)
43 async function checkCommentNotification (
44 mainServer: PeerTubeServer,
45 comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
46 check: 'presence' | 'absence'
48 const command = comment.server.comments
50 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
52 await waitJobs([ mainServer, comment.server ])
54 const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
55 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
57 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
58 else expect(commentNotifications).to.have.lengthOf(0)
60 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
62 await waitJobs([ mainServer, comment.server ])
65 describe('Test blocklist', function () {
66 let servers: PeerTubeServer[]
67 let videoUUID1: string
68 let videoUUID2: string
69 let videoUUID3: string
70 let userToken1: string
71 let userModeratorToken: string
72 let userToken2: string
74 let command: BlocklistCommand
75 let commentsCommand: CommentsCommand[]
77 before(async function () {
80 servers = await createMultipleServers(3)
81 await setAccessTokensToServers(servers)
83 command = servers[0].blocklist
84 commentsCommand = servers.map(s => s.comments)
87 const user = { username: 'user1', password: 'password' }
88 await servers[0].users.create({ username: user.username, password: user.password })
90 userToken1 = await servers[0].login.getAccessToken(user)
91 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
95 const user = { username: 'moderator', password: 'password' }
96 await servers[0].users.create({ username: user.username, password: user.password })
98 userModeratorToken = await servers[0].login.getAccessToken(user)
102 const user = { username: 'user2', password: 'password' }
103 await servers[1].users.create({ username: user.username, password: user.password })
105 userToken2 = await servers[1].login.getAccessToken(user)
106 await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
110 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
115 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
120 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
124 await doubleFollow(servers[0], servers[1])
125 await doubleFollow(servers[0], servers[2])
128 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
129 const reply = await commentsCommand[0].addReply({
132 toCommentId: created.id,
133 text: 'comment user 1'
135 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
139 const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
140 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
143 await waitJobs(servers)
146 describe('User blocklist', function () {
148 describe('When managing account blocklist', function () {
149 it('Should list all videos', function () {
150 return checkAllVideos(servers[0], servers[0].accessToken)
153 it('Should list the comments', function () {
154 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
157 it('Should block a remote account', async function () {
158 await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
161 it('Should hide its videos', async function () {
162 const { data } = await servers[0].videos.listWithToken()
164 expect(data).to.have.lengthOf(4)
166 const v = data.find(v => v.name === 'video user 2')
167 expect(v).to.be.undefined
170 it('Should block a local account', async function () {
171 await command.addToMyBlocklist({ account: 'user1' })
174 it('Should hide its videos', async function () {
175 const { data } = await servers[0].videos.listWithToken()
177 expect(data).to.have.lengthOf(3)
179 const v = data.find(v => v.name === 'video user 1')
180 expect(v).to.be.undefined
183 it('Should hide its comments', async function () {
184 const { data } = await commentsCommand[0].listThreads({
185 token: servers[0].accessToken,
192 expect(data).to.have.lengthOf(1)
193 expect(data[0].totalReplies).to.equal(1)
195 const t = data.find(t => t.text === 'comment user 1')
196 expect(t).to.be.undefined
198 for (const thread of data) {
199 const tree = await commentsCommand[0].getThread({
202 token: servers[0].accessToken
204 expect(tree.children).to.have.lengthOf(0)
208 it('Should not have notifications from blocked accounts', async function () {
212 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
213 await checkCommentNotification(servers[0], comment, 'absence')
220 videoUUID: videoUUID2,
221 text: 'hello @root@localhost:' + servers[0].port
223 await checkCommentNotification(servers[0], comment, 'absence')
227 it('Should list all the videos with another user', async function () {
228 return checkAllVideos(servers[0], userToken1)
231 it('Should list blocked accounts', async function () {
233 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
234 expect(body.total).to.equal(2)
236 const block = body.data[0]
237 expect(block.byAccount.displayName).to.equal('root')
238 expect(block.byAccount.name).to.equal('root')
239 expect(block.blockedAccount.displayName).to.equal('user2')
240 expect(block.blockedAccount.name).to.equal('user2')
241 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
245 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
246 expect(body.total).to.equal(2)
248 const block = body.data[0]
249 expect(block.byAccount.displayName).to.equal('root')
250 expect(block.byAccount.name).to.equal('root')
251 expect(block.blockedAccount.displayName).to.equal('user1')
252 expect(block.blockedAccount.name).to.equal('user1')
253 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
257 it('Should get blocked status', async function () {
258 const remoteHandle = 'user2@' + servers[1].host
259 const localHandle = 'user1@' + servers[0].host
260 const unknownHandle = 'user5@' + servers[0].host
263 const status = await command.getStatus({ accounts: [ remoteHandle ] })
264 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
265 expect(status.accounts[remoteHandle].blockedByUser).to.be.false
266 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
268 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
272 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] })
273 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
274 expect(status.accounts[remoteHandle].blockedByUser).to.be.true
275 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
277 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
281 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
282 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
284 for (const handle of [ localHandle, remoteHandle ]) {
285 expect(status.accounts[handle].blockedByUser).to.be.true
286 expect(status.accounts[handle].blockedByServer).to.be.false
289 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
290 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
292 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
296 it('Should not allow a remote blocked user to comment my videos', async function () {
300 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
301 await waitJobs(servers)
303 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
304 await waitJobs(servers)
306 const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
307 const message = 'reply by user 2'
308 const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
309 await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
311 await waitJobs(servers)
314 // Server 2 has all the comments
316 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
318 expect(data).to.have.lengthOf(2)
319 expect(data[0].text).to.equal('uploader')
320 expect(data[1].text).to.equal('comment user 2')
322 const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
323 expect(tree.children).to.have.lengthOf(1)
324 expect(tree.children[0].comment.text).to.equal('reply by user 2')
325 expect(tree.children[0].children).to.have.lengthOf(1)
326 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
329 // Server 1 and 3 should only have uploader comments
330 for (const server of [ servers[0], servers[2] ]) {
331 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
333 expect(data).to.have.lengthOf(1)
334 expect(data[0].text).to.equal('uploader')
336 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
338 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
339 else expect(tree.children).to.have.lengthOf(1)
343 it('Should unblock the remote account', async function () {
344 await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
347 it('Should display its videos', async function () {
348 const { data } = await servers[0].videos.listWithToken()
349 expect(data).to.have.lengthOf(4)
351 const v = data.find(v => v.name === 'video user 2')
352 expect(v).not.to.be.undefined
355 it('Should display its comments on my video', async function () {
356 for (const server of servers) {
357 const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
359 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
360 if (server.serverNumber === 3) {
361 expect(data).to.have.lengthOf(1)
365 expect(data).to.have.lengthOf(2)
366 expect(data[0].text).to.equal('uploader')
367 expect(data[1].text).to.equal('comment user 2')
369 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
370 expect(tree.children).to.have.lengthOf(1)
371 expect(tree.children[0].comment.text).to.equal('reply by user 2')
372 expect(tree.children[0].children).to.have.lengthOf(1)
373 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
377 it('Should unblock the local account', async function () {
378 await command.removeFromMyBlocklist({ account: 'user1' })
381 it('Should display its comments', function () {
382 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
385 it('Should have a notification from a non blocked account', async function () {
389 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
390 await checkCommentNotification(servers[0], comment, 'presence')
397 videoUUID: videoUUID2,
398 text: 'hello @root@localhost:' + servers[0].port
400 await checkCommentNotification(servers[0], comment, 'presence')
405 describe('When managing server blocklist', function () {
407 it('Should list all videos', function () {
408 return checkAllVideos(servers[0], servers[0].accessToken)
411 it('Should list the comments', function () {
412 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
415 it('Should block a remote server', async function () {
416 await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
419 it('Should hide its videos', async function () {
420 const { data } = await servers[0].videos.listWithToken()
422 expect(data).to.have.lengthOf(3)
424 const v1 = data.find(v => v.name === 'video user 2')
425 const v2 = data.find(v => v.name === 'video server 2')
427 expect(v1).to.be.undefined
428 expect(v2).to.be.undefined
431 it('Should list all the videos with another user', async function () {
432 return checkAllVideos(servers[0], userToken1)
435 it('Should hide its comments', async function () {
438 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
440 await waitJobs(servers)
442 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
444 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
447 it('Should not have notifications from blocked server', async function () {
451 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
452 await checkCommentNotification(servers[0], comment, 'absence')
459 videoUUID: videoUUID1,
460 text: 'hello @root@localhost:' + servers[0].port
462 await checkCommentNotification(servers[0], comment, 'absence')
466 it('Should list blocked servers', async function () {
467 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
468 expect(body.total).to.equal(1)
470 const block = body.data[0]
471 expect(block.byAccount.displayName).to.equal('root')
472 expect(block.byAccount.name).to.equal('root')
473 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
476 it('Should get blocklist status', async function () {
477 const blockedServer = servers[1].host
478 const notBlockedServer = 'example.com'
481 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
482 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
484 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
485 expect(status.hosts[blockedServer].blockedByUser).to.be.false
486 expect(status.hosts[blockedServer].blockedByServer).to.be.false
488 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
489 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
493 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
494 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
496 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
497 expect(status.hosts[blockedServer].blockedByUser).to.be.true
498 expect(status.hosts[blockedServer].blockedByServer).to.be.false
500 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
501 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
505 it('Should unblock the remote server', async function () {
506 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
509 it('Should display its videos', function () {
510 return checkAllVideos(servers[0], servers[0].accessToken)
513 it('Should display its comments', function () {
514 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
517 it('Should have notification from unblocked server', async function () {
521 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
522 await checkCommentNotification(servers[0], comment, 'presence')
529 videoUUID: videoUUID1,
530 text: 'hello @root@localhost:' + servers[0].port
532 await checkCommentNotification(servers[0], comment, 'presence')
538 describe('Server blocklist', function () {
540 describe('When managing account blocklist', function () {
541 it('Should list all videos', async function () {
542 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
543 await checkAllVideos(servers[0], token)
547 it('Should list the comments', async function () {
548 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
549 await checkAllComments(servers[0], token, videoUUID1)
553 it('Should block a remote account', async function () {
554 await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
557 it('Should hide its videos', async function () {
558 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
559 const { data } = await servers[0].videos.listWithToken({ token })
561 expect(data).to.have.lengthOf(4)
563 const v = data.find(v => v.name === 'video user 2')
564 expect(v).to.be.undefined
568 it('Should block a local account', async function () {
569 await command.addToServerBlocklist({ account: 'user1' })
572 it('Should hide its videos', async function () {
573 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
574 const { data } = await servers[0].videos.listWithToken({ token })
576 expect(data).to.have.lengthOf(3)
578 const v = data.find(v => v.name === 'video user 1')
579 expect(v).to.be.undefined
583 it('Should hide its comments', async function () {
584 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
585 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
586 const threads = data.filter(t => t.isDeleted === false)
588 expect(threads).to.have.lengthOf(1)
589 expect(threads[0].totalReplies).to.equal(1)
591 const t = threads.find(t => t.text === 'comment user 1')
592 expect(t).to.be.undefined
594 for (const thread of threads) {
595 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
596 expect(tree.children).to.have.lengthOf(0)
601 it('Should not have notification from blocked accounts by instance', async function () {
605 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
606 await checkCommentNotification(servers[0], comment, 'absence')
613 videoUUID: videoUUID1,
614 text: 'hello @root@localhost:' + servers[0].port
616 await checkCommentNotification(servers[0], comment, 'absence')
620 it('Should list blocked accounts', async function () {
622 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
623 expect(body.total).to.equal(2)
625 const block = body.data[0]
626 expect(block.byAccount.displayName).to.equal('peertube')
627 expect(block.byAccount.name).to.equal('peertube')
628 expect(block.blockedAccount.displayName).to.equal('user2')
629 expect(block.blockedAccount.name).to.equal('user2')
630 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
634 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
635 expect(body.total).to.equal(2)
637 const block = body.data[0]
638 expect(block.byAccount.displayName).to.equal('peertube')
639 expect(block.byAccount.name).to.equal('peertube')
640 expect(block.blockedAccount.displayName).to.equal('user1')
641 expect(block.blockedAccount.name).to.equal('user1')
642 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
646 it('Should get blocked status', async function () {
647 const remoteHandle = 'user2@' + servers[1].host
648 const localHandle = 'user1@' + servers[0].host
649 const unknownHandle = 'user5@' + servers[0].host
651 for (const token of [ undefined, servers[0].accessToken ]) {
652 const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
653 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
655 for (const handle of [ localHandle, remoteHandle ]) {
656 expect(status.accounts[handle].blockedByUser).to.be.false
657 expect(status.accounts[handle].blockedByServer).to.be.true
660 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
661 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
663 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
667 it('Should unblock the remote account', async function () {
668 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
671 it('Should display its videos', async function () {
672 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
673 const { data } = await servers[0].videos.listWithToken({ token })
674 expect(data).to.have.lengthOf(4)
676 const v = data.find(v => v.name === 'video user 2')
677 expect(v).not.to.be.undefined
681 it('Should unblock the local account', async function () {
682 await command.removeFromServerBlocklist({ account: 'user1' })
685 it('Should display its comments', async function () {
686 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
687 await checkAllComments(servers[0], token, videoUUID1)
691 it('Should have notifications from unblocked accounts', async function () {
695 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
696 await checkCommentNotification(servers[0], comment, 'presence')
703 videoUUID: videoUUID1,
704 text: 'hello @root@localhost:' + servers[0].port
706 await checkCommentNotification(servers[0], comment, 'presence')
711 describe('When managing server blocklist', function () {
713 it('Should list all videos', async function () {
714 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
715 await checkAllVideos(servers[0], token)
719 it('Should list the comments', async function () {
720 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
721 await checkAllComments(servers[0], token, videoUUID1)
725 it('Should block a remote server', async function () {
726 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
729 it('Should hide its videos', async function () {
730 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
732 servers[0].videos.list(),
733 servers[0].videos.listWithToken({ token })
736 for (const req of requests) {
737 const { data } = await req
738 expect(data).to.have.lengthOf(3)
740 const v1 = data.find(v => v.name === 'video user 2')
741 const v2 = data.find(v => v.name === 'video server 2')
743 expect(v1).to.be.undefined
744 expect(v2).to.be.undefined
749 it('Should hide its comments', async function () {
752 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
754 await waitJobs(servers)
756 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
758 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
761 it('Should not have notification from blocked instances by instance', async function () {
765 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
766 await checkCommentNotification(servers[0], comment, 'absence')
773 videoUUID: videoUUID1,
774 text: 'hello @root@localhost:' + servers[0].port
776 await checkCommentNotification(servers[0], comment, 'absence')
780 const now = new Date()
781 await servers[1].follows.unfollow({ target: servers[0] })
782 await waitJobs(servers)
783 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
785 await waitJobs(servers)
787 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
788 const commentNotifications = data.filter(n => {
789 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
792 expect(commentNotifications).to.have.lengthOf(0)
796 it('Should list blocked servers', async function () {
797 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
798 expect(body.total).to.equal(1)
800 const block = body.data[0]
801 expect(block.byAccount.displayName).to.equal('peertube')
802 expect(block.byAccount.name).to.equal('peertube')
803 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
806 it('Should get blocklist status', async function () {
807 const blockedServer = servers[1].host
808 const notBlockedServer = 'example.com'
810 for (const token of [ undefined, servers[0].accessToken ]) {
811 const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
812 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
814 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
815 expect(status.hosts[blockedServer].blockedByUser).to.be.false
816 expect(status.hosts[blockedServer].blockedByServer).to.be.true
818 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
819 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
823 it('Should unblock the remote server', async function () {
824 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
827 it('Should list all videos', async function () {
828 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
829 await checkAllVideos(servers[0], token)
833 it('Should list the comments', async function () {
834 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
835 await checkAllComments(servers[0], token, videoUUID1)
839 it('Should have notification from unblocked instances', async function () {
843 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
844 await checkCommentNotification(servers[0], comment, 'presence')
851 videoUUID: videoUUID1,
852 text: 'hello @root@localhost:' + servers[0].port
854 await checkCommentNotification(servers[0], comment, 'presence')
858 const now = new Date()
859 await servers[1].follows.unfollow({ target: servers[0] })
860 await waitJobs(servers)
861 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
863 await waitJobs(servers)
865 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
866 const commentNotifications = data.filter(n => {
867 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
870 expect(commentNotifications).to.have.lengthOf(1)
876 after(async function () {
877 await cleanupTests(servers)