]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/moderation/blocklist.ts
Also retry when fetching master m3u8 playlist
[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@localhost:' + servers[1].port })
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@localhost:' + servers[0].port
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('localhost:' + servers[1].port)
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('localhost:' + servers[0].port)
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@localhost:' + servers[1].port })
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@localhost:' + servers[0].port
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: 'localhost:' + servers[1].port })
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 this.timeout(10000)
443
444 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
445
446 await waitJobs(servers)
447
448 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
449
450 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
451 })
452
453 it('Should not have notifications from blocked server', async function () {
454 this.timeout(20000)
455
456 {
457 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
458 await checkCommentNotification(servers[0], comment, 'absence')
459 }
460
461 {
462 const comment = {
463 server: servers[1],
464 token: userToken2,
465 videoUUID: videoUUID1,
466 text: 'hello @root@localhost:' + servers[0].port
467 }
468 await checkCommentNotification(servers[0], comment, 'absence')
469 }
470 })
471
472 it('Should list blocked servers', async function () {
473 const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
474 expect(body.total).to.equal(1)
475
476 const block = body.data[0]
477 expect(block.byAccount.displayName).to.equal('root')
478 expect(block.byAccount.name).to.equal('root')
479 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
480 })
481
482 it('Should search blocked servers', async function () {
483 const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host })
484 expect(body.total).to.equal(1)
485
486 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
487 })
488
489 it('Should get blocklist status', async function () {
490 const blockedServer = servers[1].host
491 const notBlockedServer = 'example.com'
492
493 {
494 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
495 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
496
497 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
498 expect(status.hosts[blockedServer].blockedByUser).to.be.false
499 expect(status.hosts[blockedServer].blockedByServer).to.be.false
500
501 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
502 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
503 }
504
505 {
506 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
507 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
508
509 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
510 expect(status.hosts[blockedServer].blockedByUser).to.be.true
511 expect(status.hosts[blockedServer].blockedByServer).to.be.false
512
513 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
514 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
515 }
516 })
517
518 it('Should unblock the remote server', async function () {
519 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
520 })
521
522 it('Should display its videos', function () {
523 return checkAllVideos(servers[0], servers[0].accessToken)
524 })
525
526 it('Should display its comments', function () {
527 return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
528 })
529
530 it('Should have notification from unblocked server', async function () {
531 this.timeout(20000)
532
533 {
534 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
535 await checkCommentNotification(servers[0], comment, 'presence')
536 }
537
538 {
539 const comment = {
540 server: servers[1],
541 token: userToken2,
542 videoUUID: videoUUID1,
543 text: 'hello @root@localhost:' + servers[0].port
544 }
545 await checkCommentNotification(servers[0], comment, 'presence')
546 }
547 })
548 })
549 })
550
551 describe('Server blocklist', function () {
552
553 describe('When managing account blocklist', function () {
554 it('Should list all videos', async function () {
555 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
556 await checkAllVideos(servers[0], token)
557 }
558 })
559
560 it('Should list the comments', async function () {
561 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
562 await checkAllComments(servers[0], token, videoUUID1)
563 }
564 })
565
566 it('Should block a remote account', async function () {
567 await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
568 })
569
570 it('Should hide its videos', async function () {
571 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
572 const { data } = await servers[0].videos.listWithToken({ token })
573
574 expect(data).to.have.lengthOf(4)
575
576 const v = data.find(v => v.name === 'video user 2')
577 expect(v).to.be.undefined
578 }
579 })
580
581 it('Should block a local account', async function () {
582 await command.addToServerBlocklist({ account: 'user1' })
583 })
584
585 it('Should hide its videos', async function () {
586 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
587 const { data } = await servers[0].videos.listWithToken({ token })
588
589 expect(data).to.have.lengthOf(3)
590
591 const v = data.find(v => v.name === 'video user 1')
592 expect(v).to.be.undefined
593 }
594 })
595
596 it('Should hide its comments', async function () {
597 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
598 const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
599 const threads = data.filter(t => t.isDeleted === false)
600
601 expect(threads).to.have.lengthOf(1)
602 expect(threads[0].totalReplies).to.equal(1)
603
604 const t = threads.find(t => t.text === 'comment user 1')
605 expect(t).to.be.undefined
606
607 for (const thread of threads) {
608 const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
609 expect(tree.children).to.have.lengthOf(0)
610 }
611 }
612 })
613
614 it('Should not have notification from blocked accounts by instance', async function () {
615 this.timeout(20000)
616
617 {
618 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
619 await checkCommentNotification(servers[0], comment, 'absence')
620 }
621
622 {
623 const comment = {
624 server: servers[1],
625 token: userToken2,
626 videoUUID: videoUUID1,
627 text: 'hello @root@localhost:' + servers[0].port
628 }
629 await checkCommentNotification(servers[0], comment, 'absence')
630 }
631 })
632
633 it('Should list blocked accounts', async function () {
634 {
635 const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
636 expect(body.total).to.equal(2)
637
638 const block = body.data[0]
639 expect(block.byAccount.displayName).to.equal('peertube')
640 expect(block.byAccount.name).to.equal('peertube')
641 expect(block.blockedAccount.displayName).to.equal('user2')
642 expect(block.blockedAccount.name).to.equal('user2')
643 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
644 }
645
646 {
647 const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
648 expect(body.total).to.equal(2)
649
650 const block = body.data[0]
651 expect(block.byAccount.displayName).to.equal('peertube')
652 expect(block.byAccount.name).to.equal('peertube')
653 expect(block.blockedAccount.displayName).to.equal('user1')
654 expect(block.blockedAccount.name).to.equal('user1')
655 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
656 }
657 })
658
659 it('Should search blocked accounts', async function () {
660 const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' })
661 expect(body.total).to.equal(1)
662
663 expect(body.data[0].blockedAccount.name).to.equal('user2')
664 })
665
666 it('Should get blocked status', async function () {
667 const remoteHandle = 'user2@' + servers[1].host
668 const localHandle = 'user1@' + servers[0].host
669 const unknownHandle = 'user5@' + servers[0].host
670
671 for (const token of [ undefined, servers[0].accessToken ]) {
672 const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
673 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
674
675 for (const handle of [ localHandle, remoteHandle ]) {
676 expect(status.accounts[handle].blockedByUser).to.be.false
677 expect(status.accounts[handle].blockedByServer).to.be.true
678 }
679
680 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
681 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
682
683 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
684 }
685 })
686
687 it('Should unblock the remote account', async function () {
688 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
689 })
690
691 it('Should display its videos', async function () {
692 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
693 const { data } = await servers[0].videos.listWithToken({ token })
694 expect(data).to.have.lengthOf(4)
695
696 const v = data.find(v => v.name === 'video user 2')
697 expect(v).not.to.be.undefined
698 }
699 })
700
701 it('Should unblock the local account', async function () {
702 await command.removeFromServerBlocklist({ account: 'user1' })
703 })
704
705 it('Should display its comments', async function () {
706 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
707 await checkAllComments(servers[0], token, videoUUID1)
708 }
709 })
710
711 it('Should have notifications from unblocked accounts', async function () {
712 this.timeout(20000)
713
714 {
715 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
716 await checkCommentNotification(servers[0], comment, 'presence')
717 }
718
719 {
720 const comment = {
721 server: servers[1],
722 token: userToken2,
723 videoUUID: videoUUID1,
724 text: 'hello @root@localhost:' + servers[0].port
725 }
726 await checkCommentNotification(servers[0], comment, 'presence')
727 }
728 })
729 })
730
731 describe('When managing server blocklist', function () {
732
733 it('Should list all videos', async function () {
734 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
735 await checkAllVideos(servers[0], token)
736 }
737 })
738
739 it('Should list the comments', async function () {
740 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
741 await checkAllComments(servers[0], token, videoUUID1)
742 }
743 })
744
745 it('Should block a remote server', async function () {
746 await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
747 })
748
749 it('Should hide its videos', async function () {
750 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
751 const requests = [
752 servers[0].videos.list(),
753 servers[0].videos.listWithToken({ token })
754 ]
755
756 for (const req of requests) {
757 const { data } = await req
758 expect(data).to.have.lengthOf(3)
759
760 const v1 = data.find(v => v.name === 'video user 2')
761 const v2 = data.find(v => v.name === 'video server 2')
762
763 expect(v1).to.be.undefined
764 expect(v2).to.be.undefined
765 }
766 }
767 })
768
769 it('Should hide its comments', async function () {
770 this.timeout(10000)
771
772 const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
773
774 await waitJobs(servers)
775
776 await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
777
778 await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
779 })
780
781 it('Should not have notification from blocked instances by instance', async function () {
782 this.timeout(50000)
783
784 {
785 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
786 await checkCommentNotification(servers[0], comment, 'absence')
787 }
788
789 {
790 const comment = {
791 server: servers[1],
792 token: userToken2,
793 videoUUID: videoUUID1,
794 text: 'hello @root@localhost:' + servers[0].port
795 }
796 await checkCommentNotification(servers[0], comment, 'absence')
797 }
798
799 {
800 const now = new Date()
801 await servers[1].follows.unfollow({ target: servers[0] })
802 await waitJobs(servers)
803 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
804
805 await waitJobs(servers)
806
807 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
808 const commentNotifications = data.filter(n => {
809 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
810 })
811
812 expect(commentNotifications).to.have.lengthOf(0)
813 }
814 })
815
816 it('Should list blocked servers', async function () {
817 const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
818 expect(body.total).to.equal(1)
819
820 const block = body.data[0]
821 expect(block.byAccount.displayName).to.equal('peertube')
822 expect(block.byAccount.name).to.equal('peertube')
823 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
824 })
825
826 it('Should search blocked servers', async function () {
827 const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host })
828 expect(body.total).to.equal(1)
829
830 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
831 })
832
833 it('Should get blocklist status', async function () {
834 const blockedServer = servers[1].host
835 const notBlockedServer = 'example.com'
836
837 for (const token of [ undefined, servers[0].accessToken ]) {
838 const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
839 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
840
841 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
842 expect(status.hosts[blockedServer].blockedByUser).to.be.false
843 expect(status.hosts[blockedServer].blockedByServer).to.be.true
844
845 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
846 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
847 }
848 })
849
850 it('Should unblock the remote server', async function () {
851 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
852 })
853
854 it('Should list all videos', async function () {
855 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
856 await checkAllVideos(servers[0], token)
857 }
858 })
859
860 it('Should list the comments', async function () {
861 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
862 await checkAllComments(servers[0], token, videoUUID1)
863 }
864 })
865
866 it('Should have notification from unblocked instances', async function () {
867 this.timeout(50000)
868
869 {
870 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
871 await checkCommentNotification(servers[0], comment, 'presence')
872 }
873
874 {
875 const comment = {
876 server: servers[1],
877 token: userToken2,
878 videoUUID: videoUUID1,
879 text: 'hello @root@localhost:' + servers[0].port
880 }
881 await checkCommentNotification(servers[0], comment, 'presence')
882 }
883
884 {
885 const now = new Date()
886 await servers[1].follows.unfollow({ target: servers[0] })
887 await waitJobs(servers)
888 await servers[1].follows.follow({ hosts: [ servers[0].host ] })
889
890 await waitJobs(servers)
891
892 const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
893 const commentNotifications = data.filter(n => {
894 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
895 })
896
897 expect(commentNotifications).to.have.lengthOf(1)
898 }
899 })
900 })
901 })
902
903 after(async function () {
904 await cleanupTests(servers)
905 })
906 })