]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/moderation/blocklist.ts
b90d8c16c0df94b3664afabf61304aa502d196e1
[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 { expect } from 'chai'
4 import { UserNotificationType } from '@shared/models'
5 import {
6 BlocklistCommand,
7 cleanupTests,
8 CommentsCommand,
9 createMultipleServers,
10 doubleFollow,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 waitJobs
15 } from '@shared/server-commands'
16
17 async function checkAllVideos (server: PeerTubeServer, token: string) {
18 {
19 const { data } = await server.videos.listWithToken({ token })
20 expect(data).to.have.lengthOf(5)
21 }
22
23 {
24 const { data } = await server.videos.list()
25 expect(data).to.have.lengthOf(5)
26 }
27 }
28
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 })
31
32 const threads = data.filter(t => t.isDeleted === false)
33 expect(threads).to.have.lengthOf(2)
34
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)
38 }
39 }
40
41 async function checkCommentNotification (
42 mainServer: PeerTubeServer,
43 comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
44 check: 'presence' | 'absence'
45 ) {
46 const command = comment.server.comments
47
48 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
49
50 await waitJobs([ mainServer, comment.server ])
51
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)
54
55 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
56 else expect(commentNotifications).to.have.lengthOf(0)
57
58 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
59
60 await waitJobs([ mainServer, comment.server ])
61 }
62
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
71
72 let command: BlocklistCommand
73 let commentsCommand: CommentsCommand[]
74
75 before(async function () {
76 this.timeout(120000)
77
78 servers = await createMultipleServers(3)
79 await setAccessTokensToServers(servers)
80 await setDefaultAccountAvatar(servers)
81
82 command = servers[0].blocklist
83 commentsCommand = servers.map(s => s.comments)
84
85 {
86 const user = { username: 'user1', password: 'password' }
87 await servers[0].users.create({ username: user.username, password: user.password })
88
89 userToken1 = await servers[0].login.getAccessToken(user)
90 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
91 }
92
93 {
94 const user = { username: 'moderator', password: 'password' }
95 await servers[0].users.create({ username: user.username, password: user.password })
96
97 userModeratorToken = await servers[0].login.getAccessToken(user)
98 }
99
100 {
101 const user = { username: 'user2', password: 'password' }
102 await servers[1].users.create({ username: user.username, password: user.password })
103
104 userToken2 = await servers[1].login.getAccessToken(user)
105 await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
106 }
107
108 {
109 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
110 videoUUID1 = uuid
111 }
112
113 {
114 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
115 videoUUID2 = uuid
116 }
117
118 {
119 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
120 videoUUID3 = uuid
121 }
122
123 await doubleFollow(servers[0], servers[1])
124 await doubleFollow(servers[0], servers[2])
125
126 {
127 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
128 const reply = await commentsCommand[0].addReply({
129 token: userToken1,
130 videoId: videoUUID1,
131 toCommentId: created.id,
132 text: 'comment user 1'
133 })
134 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
135 }
136
137 {
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' })
140 }
141
142 await waitJobs(servers)
143 })
144
145 describe('User blocklist', function () {
146
147 describe('When managing account blocklist', function () {
148 it('Should list all videos', function () {
149 return checkAllVideos(servers[0], servers[0].accessToken)
150 })
151
152 it('Should list the comments', function () {
153 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
154 })
155
156 it('Should block a remote account', async function () {
157 await command.addToMyBlocklist({ account: 'user2@' + servers[1].host })
158 })
159
160 it('Should hide its videos', async function () {
161 const { data } = await servers[0].videos.listWithToken()
162
163 expect(data).to.have.lengthOf(4)
164
165 const v = data.find(v => v.name === 'video user 2')
166 expect(v).to.be.undefined
167 })
168
169 it('Should block a local account', async function () {
170 await command.addToMyBlocklist({ account: 'user1' })
171 })
172
173 it('Should hide its videos', async function () {
174 const { data } = await servers[0].videos.listWithToken()
175
176 expect(data).to.have.lengthOf(3)
177
178 const v = data.find(v => v.name === 'video user 1')
179 expect(v).to.be.undefined
180 })
181
182 it('Should hide its comments', async function () {
183 const { data } = await commentsCommand[0].listThreads({
184 token: servers[0].accessToken,
185 videoId: videoUUID1,
186 start: 0,
187 count: 25,
188 sort: '-createdAt'
189 })
190
191 expect(data).to.have.lengthOf(1)
192 expect(data[0].totalReplies).to.equal(1)
193
194 const t = data.find(t => t.text === 'comment user 1')
195 expect(t).to.be.undefined
196
197 for (const thread of data) {
198 const tree = await commentsCommand[0].getThread({
199 videoId: videoUUID1,
200 threadId: thread.id,
201 token: servers[0].accessToken
202 })
203 expect(tree.children).to.have.lengthOf(0)
204 }
205 })
206
207 it('Should not have notifications from blocked accounts', async function () {
208 this.timeout(20000)
209
210 {
211 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
212 await checkCommentNotification(servers[0], comment, 'absence')
213 }
214
215 {
216 const comment = {
217 server: servers[0],
218 token: userToken1,
219 videoUUID: videoUUID2,
220 text: 'hello @root@' + servers[0].host
221 }
222 await checkCommentNotification(servers[0], comment, 'absence')
223 }
224 })
225
226 it('Should list all the videos with another user', async function () {
227 return checkAllVideos(servers[0], userToken1)
228 })
229
230 it('Should list blocked accounts', async function () {
231 {
232 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
233 expect(body.total).to.equal(2)
234
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)
241 }
242
243 {
244 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
245 expect(body.total).to.equal(2)
246
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)
253 }
254 })
255
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)
259
260 expect(body.data[0].blockedAccount.name).to.equal('user2')
261 })
262
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
267
268 {
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
273
274 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
275 }
276
277 {
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
282
283 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
284 }
285
286 {
287 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
288 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
289
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
293 }
294
295 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
296 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
297
298 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
299 }
300 })
301
302 it('Should not allow a remote blocked user to comment my videos', async function () {
303 this.timeout(60000)
304
305 {
306 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
307 await waitJobs(servers)
308
309 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
310 await waitJobs(servers)
311
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' })
316
317 await waitJobs(servers)
318 }
319
320 // Server 2 has all the comments
321 {
322 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
323
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')
327
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')
333 }
334
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' })
338
339 expect(data).to.have.lengthOf(1)
340 expect(data[0].text).to.equal('uploader')
341
342 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
343
344 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
345 else expect(tree.children).to.have.lengthOf(1)
346 }
347 })
348
349 it('Should unblock the remote account', async function () {
350 await command.removeFromMyBlocklist({ account: 'user2@' + servers[1].host })
351 })
352
353 it('Should display its videos', async function () {
354 const { data } = await servers[0].videos.listWithToken()
355 expect(data).to.have.lengthOf(4)
356
357 const v = data.find(v => v.name === 'video user 2')
358 expect(v).not.to.be.undefined
359 })
360
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' })
364
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)
368 continue
369 }
370
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')
374
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')
380 }
381 })
382
383 it('Should unblock the local account', async function () {
384 await command.removeFromMyBlocklist({ account: 'user1' })
385 })
386
387 it('Should display its comments', function () {
388 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
389 })
390
391 it('Should have a notification from a non blocked account', async function () {
392 this.timeout(20000)
393
394 {
395 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
396 await checkCommentNotification(servers[0], comment, 'presence')
397 }
398
399 {
400 const comment = {
401 server: servers[0],
402 token: userToken1,
403 videoUUID: videoUUID2,
404 text: 'hello @root@' + servers[0].host
405 }
406 await checkCommentNotification(servers[0], comment, 'presence')
407 }
408 })
409 })
410
411 describe('When managing server blocklist', function () {
412
413 it('Should list all videos', function () {
414 return checkAllVideos(servers[0], servers[0].accessToken)
415 })
416
417 it('Should list the comments', function () {
418 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
419 })
420
421 it('Should block a remote server', async function () {
422 await command.addToMyBlocklist({ server: '' + servers[1].host })
423 })
424
425 it('Should hide its videos', async function () {
426 const { data } = await servers[0].videos.listWithToken()
427
428 expect(data).to.have.lengthOf(3)
429
430 const v1 = data.find(v => v.name === 'video user 2')
431 const v2 = data.find(v => v.name === 'video server 2')
432
433 expect(v1).to.be.undefined
434 expect(v2).to.be.undefined
435 })
436
437 it('Should list all the videos with another user', async function () {
438 return checkAllVideos(servers[0], userToken1)
439 })
440
441 it('Should hide its comments', async function () {
442 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
443
444 await waitJobs(servers)
445
446 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
447
448 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
449 })
450
451 it('Should not have notifications from blocked server', async function () {
452 this.timeout(20000)
453
454 {
455 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
456 await checkCommentNotification(servers[0], comment, 'absence')
457 }
458
459 {
460 const comment = {
461 server: servers[1],
462 token: userToken2,
463 videoUUID: videoUUID1,
464 text: 'hello @root@' + servers[0].host
465 }
466 await checkCommentNotification(servers[0], comment, 'absence')
467 }
468 })
469
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)
473
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)
478 })
479
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)
483
484 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
485 })
486
487 it('Should get blocklist status', async function () {
488 const blockedServer = servers[1].host
489 const notBlockedServer = 'example.com'
490
491 {
492 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
493 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
494
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
498
499 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
500 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
501 }
502
503 {
504 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
505 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
506
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
510
511 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
512 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
513 }
514 })
515
516 it('Should unblock the remote server', async function () {
517 await command.removeFromMyBlocklist({ server: '' + servers[1].host })
518 })
519
520 it('Should display its videos', function () {
521 return checkAllVideos(servers[0], servers[0].accessToken)
522 })
523
524 it('Should display its comments', function () {
525 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
526 })
527
528 it('Should have notification from unblocked server', async function () {
529 this.timeout(20000)
530
531 {
532 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
533 await checkCommentNotification(servers[0], comment, 'presence')
534 }
535
536 {
537 const comment = {
538 server: servers[1],
539 token: userToken2,
540 videoUUID: videoUUID1,
541 text: 'hello @root@' + servers[0].host
542 }
543 await checkCommentNotification(servers[0], comment, 'presence')
544 }
545 })
546 })
547 })
548
549 describe('Server blocklist', function () {
550
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)
555 }
556 })
557
558 it('Should list the comments', async function () {
559 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
560 await checkAllComments(servers[0], token, videoUUID1)
561 }
562 })
563
564 it('Should block a remote account', async function () {
565 await command.addToServerBlocklist({ account: 'user2@' + servers[1].host })
566 })
567
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 })
571
572 expect(data).to.have.lengthOf(4)
573
574 const v = data.find(v => v.name === 'video user 2')
575 expect(v).to.be.undefined
576 }
577 })
578
579 it('Should block a local account', async function () {
580 await command.addToServerBlocklist({ account: 'user1' })
581 })
582
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 })
586
587 expect(data).to.have.lengthOf(3)
588
589 const v = data.find(v => v.name === 'video user 1')
590 expect(v).to.be.undefined
591 }
592 })
593
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)
598
599 expect(threads).to.have.lengthOf(1)
600 expect(threads[0].totalReplies).to.equal(1)
601
602 const t = threads.find(t => t.text === 'comment user 1')
603 expect(t).to.be.undefined
604
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)
608 }
609 }
610 })
611
612 it('Should not have notification from blocked accounts by instance', async function () {
613 this.timeout(20000)
614
615 {
616 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
617 await checkCommentNotification(servers[0], comment, 'absence')
618 }
619
620 {
621 const comment = {
622 server: servers[1],
623 token: userToken2,
624 videoUUID: videoUUID1,
625 text: 'hello @root@' + servers[0].host
626 }
627 await checkCommentNotification(servers[0], comment, 'absence')
628 }
629 })
630
631 it('Should list blocked accounts', async function () {
632 {
633 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
634 expect(body.total).to.equal(2)
635
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)
642 }
643
644 {
645 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
646 expect(body.total).to.equal(2)
647
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)
654 }
655 })
656
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)
660
661 expect(body.data[0].blockedAccount.name).to.equal('user2')
662 })
663
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
668
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)
672
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
676 }
677
678 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
679 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
680
681 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
682 }
683 })
684
685 it('Should unblock the remote account', async function () {
686 await command.removeFromServerBlocklist({ account: 'user2@' + servers[1].host })
687 })
688
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)
693
694 const v = data.find(v => v.name === 'video user 2')
695 expect(v).not.to.be.undefined
696 }
697 })
698
699 it('Should unblock the local account', async function () {
700 await command.removeFromServerBlocklist({ account: 'user1' })
701 })
702
703 it('Should display its comments', async function () {
704 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
705 await checkAllComments(servers[0], token, videoUUID1)
706 }
707 })
708
709 it('Should have notifications from unblocked accounts', async function () {
710 this.timeout(20000)
711
712 {
713 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
714 await checkCommentNotification(servers[0], comment, 'presence')
715 }
716
717 {
718 const comment = {
719 server: servers[1],
720 token: userToken2,
721 videoUUID: videoUUID1,
722 text: 'hello @root@' + servers[0].host
723 }
724 await checkCommentNotification(servers[0], comment, 'presence')
725 }
726 })
727 })
728
729 describe('When managing server blocklist', function () {
730
731 it('Should list all videos', async function () {
732 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
733 await checkAllVideos(servers[0], token)
734 }
735 })
736
737 it('Should list the comments', async function () {
738 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
739 await checkAllComments(servers[0], token, videoUUID1)
740 }
741 })
742
743 it('Should block a remote server', async function () {
744 await command.addToServerBlocklist({ server: '' + servers[1].host })
745 })
746
747 it('Should hide its videos', async function () {
748 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
749 const requests = [
750 servers[0].videos.list(),
751 servers[0].videos.listWithToken({ token })
752 ]
753
754 for (const req of requests) {
755 const { data } = await req
756 expect(data).to.have.lengthOf(3)
757
758 const v1 = data.find(v => v.name === 'video user 2')
759 const v2 = data.find(v => v.name === 'video server 2')
760
761 expect(v1).to.be.undefined
762 expect(v2).to.be.undefined
763 }
764 }
765 })
766
767 it('Should hide its comments', async function () {
768 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
769
770 await waitJobs(servers)
771
772 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
773
774 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
775 })
776
777 it('Should not have notification from blocked instances by instance', async function () {
778 this.timeout(50000)
779
780 {
781 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
782 await checkCommentNotification(servers[0], comment, 'absence')
783 }
784
785 {
786 const comment = {
787 server: servers[1],
788 token: userToken2,
789 videoUUID: videoUUID1,
790 text: 'hello @root@' + servers[0].host
791 }
792 await checkCommentNotification(servers[0], comment, 'absence')
793 }
794
795 {
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 ] })
800
801 await waitJobs(servers)
802
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()
806 })
807
808 expect(commentNotifications).to.have.lengthOf(0)
809 }
810 })
811
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)
815
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)
820 })
821
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)
825
826 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
827 })
828
829 it('Should get blocklist status', async function () {
830 const blockedServer = servers[1].host
831 const notBlockedServer = 'example.com'
832
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)
836
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
840
841 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
842 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
843 }
844 })
845
846 it('Should unblock the remote server', async function () {
847 await command.removeFromServerBlocklist({ server: '' + servers[1].host })
848 })
849
850 it('Should list all videos', async function () {
851 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
852 await checkAllVideos(servers[0], token)
853 }
854 })
855
856 it('Should list the comments', async function () {
857 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
858 await checkAllComments(servers[0], token, videoUUID1)
859 }
860 })
861
862 it('Should have notification from unblocked instances', async function () {
863 this.timeout(50000)
864
865 {
866 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
867 await checkCommentNotification(servers[0], comment, 'presence')
868 }
869
870 {
871 const comment = {
872 server: servers[1],
873 token: userToken2,
874 videoUUID: videoUUID1,
875 text: 'hello @root@' + servers[0].host
876 }
877 await checkCommentNotification(servers[0], comment, 'presence')
878 }
879
880 {
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 ] })
885
886 await waitJobs(servers)
887
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()
891 })
892
893 expect(commentNotifications).to.have.lengthOf(1)
894 }
895 })
896 })
897 })
898
899 after(async function () {
900 await cleanupTests(servers)
901 })
902 })