]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/moderation/blocklist.ts
Merge branch 'release/4.0.0' into develop
[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 BlocklistCommand,
7 cleanupTests,
8 CommentsCommand,
9 createMultipleServers,
10 doubleFollow,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 waitJobs
14 } from '@shared/extra-utils'
15 import { UserNotificationType } from '@shared/models'
16
17 const expect = chai.expect
18
19 async function checkAllVideos (server: PeerTubeServer, token: string) {
20 {
21 const { data } = await server.videos.listWithToken({ token })
22 expect(data).to.have.lengthOf(5)
23 }
24
25 {
26 const { data } = await server.videos.list()
27 expect(data).to.have.lengthOf(5)
28 }
29 }
30
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 })
33
34 const threads = data.filter(t => t.isDeleted === false)
35 expect(threads).to.have.lengthOf(2)
36
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)
40 }
41 }
42
43 async function checkCommentNotification (
44 mainServer: PeerTubeServer,
45 comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
46 check: 'presence' | 'absence'
47 ) {
48 const command = comment.server.comments
49
50 const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
51
52 await waitJobs([ mainServer, comment.server ])
53
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)
56
57 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
58 else expect(commentNotifications).to.have.lengthOf(0)
59
60 await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
61
62 await waitJobs([ mainServer, comment.server ])
63 }
64
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
73
74 let command: BlocklistCommand
75 let commentsCommand: CommentsCommand[]
76
77 before(async function () {
78 this.timeout(120000)
79
80 servers = await createMultipleServers(3)
81 await setAccessTokensToServers(servers)
82
83 command = servers[0].blocklist
84 commentsCommand = servers.map(s => s.comments)
85
86 {
87 const user = { username: 'user1', password: 'password' }
88 await servers[0].users.create({ username: user.username, password: user.password })
89
90 userToken1 = await servers[0].login.getAccessToken(user)
91 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
92 }
93
94 {
95 const user = { username: 'moderator', password: 'password' }
96 await servers[0].users.create({ username: user.username, password: user.password })
97
98 userModeratorToken = await servers[0].login.getAccessToken(user)
99 }
100
101 {
102 const user = { username: 'user2', password: 'password' }
103 await servers[1].users.create({ username: user.username, password: user.password })
104
105 userToken2 = await servers[1].login.getAccessToken(user)
106 await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
107 }
108
109 {
110 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
111 videoUUID1 = uuid
112 }
113
114 {
115 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
116 videoUUID2 = uuid
117 }
118
119 {
120 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
121 videoUUID3 = uuid
122 }
123
124 await doubleFollow(servers[0], servers[1])
125 await doubleFollow(servers[0], servers[2])
126
127 {
128 const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
129 const reply = await commentsCommand[0].addReply({
130 token: userToken1,
131 videoId: videoUUID1,
132 toCommentId: created.id,
133 text: 'comment user 1'
134 })
135 await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
136 }
137
138 {
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' })
141 }
142
143 await waitJobs(servers)
144 })
145
146 describe('User blocklist', function () {
147
148 describe('When managing account blocklist', function () {
149 it('Should list all videos', function () {
150 return checkAllVideos(servers[0], servers[0].accessToken)
151 })
152
153 it('Should list the comments', function () {
154 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
155 })
156
157 it('Should block a remote account', async function () {
158 await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
159 })
160
161 it('Should hide its videos', async function () {
162 const { data } = await servers[0].videos.listWithToken()
163
164 expect(data).to.have.lengthOf(4)
165
166 const v = data.find(v => v.name === 'video user 2')
167 expect(v).to.be.undefined
168 })
169
170 it('Should block a local account', async function () {
171 await command.addToMyBlocklist({ account: 'user1' })
172 })
173
174 it('Should hide its videos', async function () {
175 const { data } = await servers[0].videos.listWithToken()
176
177 expect(data).to.have.lengthOf(3)
178
179 const v = data.find(v => v.name === 'video user 1')
180 expect(v).to.be.undefined
181 })
182
183 it('Should hide its comments', async function () {
184 const { data } = await commentsCommand[0].listThreads({
185 token: servers[0].accessToken,
186 videoId: videoUUID1,
187 start: 0,
188 count: 25,
189 sort: '-createdAt'
190 })
191
192 expect(data).to.have.lengthOf(1)
193 expect(data[0].totalReplies).to.equal(1)
194
195 const t = data.find(t => t.text === 'comment user 1')
196 expect(t).to.be.undefined
197
198 for (const thread of data) {
199 const tree = await commentsCommand[0].getThread({
200 videoId: videoUUID1,
201 threadId: thread.id,
202 token: servers[0].accessToken
203 })
204 expect(tree.children).to.have.lengthOf(0)
205 }
206 })
207
208 it('Should not have notifications from blocked accounts', async function () {
209 this.timeout(20000)
210
211 {
212 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
213 await checkCommentNotification(servers[0], comment, 'absence')
214 }
215
216 {
217 const comment = {
218 server: servers[0],
219 token: userToken1,
220 videoUUID: videoUUID2,
221 text: 'hello @root@localhost:' + servers[0].port
222 }
223 await checkCommentNotification(servers[0], comment, 'absence')
224 }
225 })
226
227 it('Should list all the videos with another user', async function () {
228 return checkAllVideos(servers[0], userToken1)
229 })
230
231 it('Should list blocked accounts', async function () {
232 {
233 const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
234 expect(body.total).to.equal(2)
235
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)
242 }
243
244 {
245 const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
246 expect(body.total).to.equal(2)
247
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)
254 }
255 })
256
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
261
262 {
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
267
268 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
269 }
270
271 {
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
276
277 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
278 }
279
280 {
281 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
282 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
283
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
287 }
288
289 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
290 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
291
292 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
293 }
294 })
295
296 it('Should not allow a remote blocked user to comment my videos', async function () {
297 this.timeout(60000)
298
299 {
300 await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
301 await waitJobs(servers)
302
303 await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
304 await waitJobs(servers)
305
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' })
310
311 await waitJobs(servers)
312 }
313
314 // Server 2 has all the comments
315 {
316 const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
317
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')
321
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')
327 }
328
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' })
332
333 expect(data).to.have.lengthOf(1)
334 expect(data[0].text).to.equal('uploader')
335
336 const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
337
338 if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
339 else expect(tree.children).to.have.lengthOf(1)
340 }
341 })
342
343 it('Should unblock the remote account', async function () {
344 await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
345 })
346
347 it('Should display its videos', async function () {
348 const { data } = await servers[0].videos.listWithToken()
349 expect(data).to.have.lengthOf(4)
350
351 const v = data.find(v => v.name === 'video user 2')
352 expect(v).not.to.be.undefined
353 })
354
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' })
358
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)
362 continue
363 }
364
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')
368
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')
374 }
375 })
376
377 it('Should unblock the local account', async function () {
378 await command.removeFromMyBlocklist({ account: 'user1' })
379 })
380
381 it('Should display its comments', function () {
382 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
383 })
384
385 it('Should have a notification from a non blocked account', async function () {
386 this.timeout(20000)
387
388 {
389 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
390 await checkCommentNotification(servers[0], comment, 'presence')
391 }
392
393 {
394 const comment = {
395 server: servers[0],
396 token: userToken1,
397 videoUUID: videoUUID2,
398 text: 'hello @root@localhost:' + servers[0].port
399 }
400 await checkCommentNotification(servers[0], comment, 'presence')
401 }
402 })
403 })
404
405 describe('When managing server blocklist', function () {
406
407 it('Should list all videos', function () {
408 return checkAllVideos(servers[0], servers[0].accessToken)
409 })
410
411 it('Should list the comments', function () {
412 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
413 })
414
415 it('Should block a remote server', async function () {
416 await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
417 })
418
419 it('Should hide its videos', async function () {
420 const { data } = await servers[0].videos.listWithToken()
421
422 expect(data).to.have.lengthOf(3)
423
424 const v1 = data.find(v => v.name === 'video user 2')
425 const v2 = data.find(v => v.name === 'video server 2')
426
427 expect(v1).to.be.undefined
428 expect(v2).to.be.undefined
429 })
430
431 it('Should list all the videos with another user', async function () {
432 return checkAllVideos(servers[0], userToken1)
433 })
434
435 it('Should hide its comments', async function () {
436 this.timeout(10000)
437
438 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
439
440 await waitJobs(servers)
441
442 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
443
444 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
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 body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
468 expect(body.total).to.equal(1)
469
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)
474 })
475
476 it('Should get blocklist status', async function () {
477 const blockedServer = servers[1].host
478 const notBlockedServer = 'example.com'
479
480 {
481 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
482 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
483
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
487
488 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
489 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
490 }
491
492 {
493 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
494 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
495
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
499
500 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
501 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
502 }
503 })
504
505 it('Should unblock the remote server', async function () {
506 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
507 })
508
509 it('Should display its videos', function () {
510 return checkAllVideos(servers[0], servers[0].accessToken)
511 })
512
513 it('Should display its comments', function () {
514 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
515 })
516
517 it('Should have notification from unblocked server', async function () {
518 this.timeout(20000)
519
520 {
521 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
522 await checkCommentNotification(servers[0], comment, 'presence')
523 }
524
525 {
526 const comment = {
527 server: servers[1],
528 token: userToken2,
529 videoUUID: videoUUID1,
530 text: 'hello @root@localhost:' + servers[0].port
531 }
532 await checkCommentNotification(servers[0], comment, 'presence')
533 }
534 })
535 })
536 })
537
538 describe('Server blocklist', function () {
539
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)
544 }
545 })
546
547 it('Should list the comments', async function () {
548 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
549 await checkAllComments(servers[0], token, videoUUID1)
550 }
551 })
552
553 it('Should block a remote account', async function () {
554 await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
555 })
556
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 })
560
561 expect(data).to.have.lengthOf(4)
562
563 const v = data.find(v => v.name === 'video user 2')
564 expect(v).to.be.undefined
565 }
566 })
567
568 it('Should block a local account', async function () {
569 await command.addToServerBlocklist({ account: 'user1' })
570 })
571
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 })
575
576 expect(data).to.have.lengthOf(3)
577
578 const v = data.find(v => v.name === 'video user 1')
579 expect(v).to.be.undefined
580 }
581 })
582
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)
587
588 expect(threads).to.have.lengthOf(1)
589 expect(threads[0].totalReplies).to.equal(1)
590
591 const t = threads.find(t => t.text === 'comment user 1')
592 expect(t).to.be.undefined
593
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)
597 }
598 }
599 })
600
601 it('Should not have notification from blocked accounts by instance', async function () {
602 this.timeout(20000)
603
604 {
605 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
606 await checkCommentNotification(servers[0], comment, 'absence')
607 }
608
609 {
610 const comment = {
611 server: servers[1],
612 token: userToken2,
613 videoUUID: videoUUID1,
614 text: 'hello @root@localhost:' + servers[0].port
615 }
616 await checkCommentNotification(servers[0], comment, 'absence')
617 }
618 })
619
620 it('Should list blocked accounts', async function () {
621 {
622 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
623 expect(body.total).to.equal(2)
624
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)
631 }
632
633 {
634 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
635 expect(body.total).to.equal(2)
636
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)
643 }
644 })
645
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
650
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)
654
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
658 }
659
660 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
661 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
662
663 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
664 }
665 })
666
667 it('Should unblock the remote account', async function () {
668 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
669 })
670
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)
675
676 const v = data.find(v => v.name === 'video user 2')
677 expect(v).not.to.be.undefined
678 }
679 })
680
681 it('Should unblock the local account', async function () {
682 await command.removeFromServerBlocklist({ account: 'user1' })
683 })
684
685 it('Should display its comments', async function () {
686 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
687 await checkAllComments(servers[0], token, videoUUID1)
688 }
689 })
690
691 it('Should have notifications from unblocked accounts', async function () {
692 this.timeout(20000)
693
694 {
695 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
696 await checkCommentNotification(servers[0], comment, 'presence')
697 }
698
699 {
700 const comment = {
701 server: servers[1],
702 token: userToken2,
703 videoUUID: videoUUID1,
704 text: 'hello @root@localhost:' + servers[0].port
705 }
706 await checkCommentNotification(servers[0], comment, 'presence')
707 }
708 })
709 })
710
711 describe('When managing server blocklist', function () {
712
713 it('Should list all videos', async function () {
714 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
715 await checkAllVideos(servers[0], token)
716 }
717 })
718
719 it('Should list the comments', async function () {
720 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
721 await checkAllComments(servers[0], token, videoUUID1)
722 }
723 })
724
725 it('Should block a remote server', async function () {
726 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
727 })
728
729 it('Should hide its videos', async function () {
730 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
731 const requests = [
732 servers[0].videos.list(),
733 servers[0].videos.listWithToken({ token })
734 ]
735
736 for (const req of requests) {
737 const { data } = await req
738 expect(data).to.have.lengthOf(3)
739
740 const v1 = data.find(v => v.name === 'video user 2')
741 const v2 = data.find(v => v.name === 'video server 2')
742
743 expect(v1).to.be.undefined
744 expect(v2).to.be.undefined
745 }
746 }
747 })
748
749 it('Should hide its comments', async function () {
750 this.timeout(10000)
751
752 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
753
754 await waitJobs(servers)
755
756 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
757
758 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
759 })
760
761 it('Should not have notification from blocked instances by instance', async function () {
762 this.timeout(50000)
763
764 {
765 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
766 await checkCommentNotification(servers[0], comment, 'absence')
767 }
768
769 {
770 const comment = {
771 server: servers[1],
772 token: userToken2,
773 videoUUID: videoUUID1,
774 text: 'hello @root@localhost:' + servers[0].port
775 }
776 await checkCommentNotification(servers[0], comment, 'absence')
777 }
778
779 {
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 ] })
784
785 await waitJobs(servers)
786
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()
790 })
791
792 expect(commentNotifications).to.have.lengthOf(0)
793 }
794 })
795
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)
799
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)
804 })
805
806 it('Should get blocklist status', async function () {
807 const blockedServer = servers[1].host
808 const notBlockedServer = 'example.com'
809
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)
813
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
817
818 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
819 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
820 }
821 })
822
823 it('Should unblock the remote server', async function () {
824 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
825 })
826
827 it('Should list all videos', async function () {
828 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
829 await checkAllVideos(servers[0], token)
830 }
831 })
832
833 it('Should list the comments', async function () {
834 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
835 await checkAllComments(servers[0], token, videoUUID1)
836 }
837 })
838
839 it('Should have notification from unblocked instances', async function () {
840 this.timeout(50000)
841
842 {
843 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
844 await checkCommentNotification(servers[0], comment, 'presence')
845 }
846
847 {
848 const comment = {
849 server: servers[1],
850 token: userToken2,
851 videoUUID: videoUUID1,
852 text: 'hello @root@localhost:' + servers[0].port
853 }
854 await checkCommentNotification(servers[0], comment, 'presence')
855 }
856
857 {
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 ] })
862
863 await waitJobs(servers)
864
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()
868 })
869
870 expect(commentNotifications).to.have.lengthOf(1)
871 }
872 })
873 })
874 })
875
876 after(async function () {
877 await cleanupTests(servers)
878 })
879 })