]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/users/blocklist.ts
Block comments from muted accounts/servers
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / blocklist.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
b44164bb
C
2
3import * as chai from 'chai'
4import 'mocha'
696d83fd 5import { AccountBlock, ServerBlock, Video, UserNotification, UserNotificationType } from '../../../../shared/index'
b44164bb 6import {
7c3b7976 7 cleanupTests,
a1587156
C
8 createUser,
9 deleteVideoComment,
b44164bb
C
10 doubleFollow,
11 flushAndRunMultipleServers,
b44164bb
C
12 ServerInfo,
13 uploadVideo,
696d83fd
C
14 userLogin,
15 follow,
16 unfollow
94565d52
C
17} from '../../../../shared/extra-utils/index'
18import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
a1587156 19import { getVideosList, getVideosListWithToken } from '../../../../shared/extra-utils/videos/videos'
b44164bb
C
20import {
21 addVideoCommentReply,
22 addVideoCommentThread,
23 getVideoCommentThreads,
696d83fd
C
24 getVideoThreadComments,
25 findCommentId
94565d52
C
26} from '../../../../shared/extra-utils/videos/video-comments'
27import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
b44164bb
C
28import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
29import {
30 addAccountToAccountBlocklist,
31 addAccountToServerBlocklist,
32 addServerToAccountBlocklist,
33 addServerToServerBlocklist,
34 getAccountBlocklistByAccount,
35 getAccountBlocklistByServer,
36 getServerBlocklistByAccount,
37 getServerBlocklistByServer,
38 removeAccountFromAccountBlocklist,
39 removeAccountFromServerBlocklist,
40 removeServerFromAccountBlocklist,
41 removeServerFromServerBlocklist
94565d52 42} from '../../../../shared/extra-utils/users/blocklist'
32c68d67 43import { getUserNotifications } from '../../../../shared/extra-utils/users/user-notifications'
b44164bb
C
44
45const expect = chai.expect
46
47async function checkAllVideos (url: string, token: string) {
65b21c96
C
48 {
49 const res = await getVideosListWithToken(url, token)
b44164bb 50
696d83fd 51 expect(res.body.data).to.have.lengthOf(5)
65b21c96
C
52 }
53
54 {
55 const res = await getVideosList(url)
56
696d83fd 57 expect(res.body.data).to.have.lengthOf(5)
65b21c96 58 }
b44164bb
C
59}
60
61async function checkAllComments (url: string, token: string, videoUUID: string) {
dddc8b1f 62 const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token)
b44164bb 63
dddc8b1f
C
64 const allThreads: VideoComment[] = resThreads.body.data
65 const threads = allThreads.filter(t => t.isDeleted === false)
b44164bb
C
66 expect(threads).to.have.lengthOf(2)
67
68 for (const thread of threads) {
69 const res = await getVideoThreadComments(url, videoUUID, thread.id, token)
70
71 const tree: VideoCommentThreadTree = res.body
72 expect(tree.children).to.have.lengthOf(1)
73 }
74}
75
dddc8b1f
C
76async function checkCommentNotification (
77 mainServer: ServerInfo,
78 comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
79 check: 'presence' | 'absence'
80) {
81 const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text)
696d83fd
C
82 const created = resComment.body.comment as VideoComment
83 const threadId = created.id
84 const createdAt = created.createdAt
dddc8b1f 85
a1587156 86 await waitJobs([ mainServer, comment.server ])
dddc8b1f
C
87
88 const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30)
696d83fd
C
89 const commentNotifications = (res.body.data as UserNotification[])
90 .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
dddc8b1f
C
91
92 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
93 else expect(commentNotifications).to.have.lengthOf(0)
94
95 await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId)
96
a1587156 97 await waitJobs([ mainServer, comment.server ])
dddc8b1f
C
98}
99
b44164bb
C
100describe('Test blocklist', function () {
101 let servers: ServerInfo[]
102 let videoUUID1: string
103 let videoUUID2: string
696d83fd 104 let videoUUID3: string
b44164bb
C
105 let userToken1: string
106 let userModeratorToken: string
107 let userToken2: string
108
109 before(async function () {
110 this.timeout(60000)
111
696d83fd 112 servers = await flushAndRunMultipleServers(3)
b44164bb
C
113 await setAccessTokensToServers(servers)
114
115 {
116 const user = { username: 'user1', password: 'password' }
a1587156 117 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
b44164bb
C
118
119 userToken1 = await userLogin(servers[0], user)
120 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
121 }
122
123 {
124 const user = { username: 'moderator', password: 'password' }
a1587156 125 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
b44164bb
C
126
127 userModeratorToken = await userLogin(servers[0], user)
128 }
129
130 {
131 const user = { username: 'user2', password: 'password' }
a1587156 132 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
b44164bb
C
133
134 userToken2 = await userLogin(servers[1], user)
135 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
136 }
137
138 {
139 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
140 videoUUID1 = res.body.video.uuid
141 }
142
143 {
144 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
145 videoUUID2 = res.body.video.uuid
146 }
147
696d83fd
C
148 {
149 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
150 videoUUID3 = res.body.video.uuid
151 }
152
b44164bb 153 await doubleFollow(servers[0], servers[1])
696d83fd 154 await doubleFollow(servers[0], servers[2])
b44164bb
C
155
156 {
a1587156
C
157 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1')
158 const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1')
159 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1')
b44164bb
C
160 }
161
162 {
a1587156
C
163 const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1')
164 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1')
b44164bb
C
165 }
166
167 await waitJobs(servers)
168 })
169
170 describe('User blocklist', function () {
171
172 describe('When managing account blocklist', function () {
173 it('Should list all videos', function () {
a1587156 174 return checkAllVideos(servers[0].url, servers[0].accessToken)
b44164bb
C
175 })
176
177 it('Should list the comments', function () {
a1587156 178 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
b44164bb
C
179 })
180
181 it('Should block a remote account', async function () {
a1587156 182 await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
b44164bb
C
183 })
184
185 it('Should hide its videos', async function () {
a1587156 186 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
b44164bb
C
187
188 const videos: Video[] = res.body.data
696d83fd 189 expect(videos).to.have.lengthOf(4)
b44164bb
C
190
191 const v = videos.find(v => v.name === 'video user 2')
192 expect(v).to.be.undefined
193 })
194
195 it('Should block a local account', async function () {
a1587156 196 await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
b44164bb
C
197 })
198
199 it('Should hide its videos', async function () {
a1587156 200 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
b44164bb
C
201
202 const videos: Video[] = res.body.data
696d83fd 203 expect(videos).to.have.lengthOf(3)
b44164bb
C
204
205 const v = videos.find(v => v.name === 'video user 1')
206 expect(v).to.be.undefined
207 })
208
209 it('Should hide its comments', async function () {
8adf0a76 210 const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken)
b44164bb
C
211
212 const threads: VideoComment[] = resThreads.body.data
213 expect(threads).to.have.lengthOf(1)
a1587156 214 expect(threads[0].totalReplies).to.equal(0)
b44164bb
C
215
216 const t = threads.find(t => t.text === 'comment user 1')
217 expect(t).to.be.undefined
218
219 for (const thread of threads) {
a1587156 220 const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken)
b44164bb
C
221
222 const tree: VideoCommentThreadTree = res.body
223 expect(tree.children).to.have.lengthOf(0)
224 }
225 })
226
dddc8b1f
C
227 it('Should not have notifications from blocked accounts', async function () {
228 this.timeout(20000)
229
230 {
a1587156
C
231 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
232 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f
C
233 }
234
235 {
236 const comment = {
a1587156 237 server: servers[0],
dddc8b1f
C
238 token: userToken1,
239 videoUUID: videoUUID2,
a1587156 240 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 241 }
a1587156 242 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f
C
243 }
244 })
245
b44164bb 246 it('Should list all the videos with another user', async function () {
a1587156 247 return checkAllVideos(servers[0].url, userToken1)
b44164bb
C
248 })
249
b44164bb
C
250 it('Should list blocked accounts', async function () {
251 {
a1587156 252 const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
b44164bb
C
253 const blocks: AccountBlock[] = res.body.data
254
255 expect(res.body.total).to.equal(2)
256
a1587156 257 const block = blocks[0]
b44164bb
C
258 expect(block.byAccount.displayName).to.equal('root')
259 expect(block.byAccount.name).to.equal('root')
260 expect(block.blockedAccount.displayName).to.equal('user2')
261 expect(block.blockedAccount.name).to.equal('user2')
7243f84d 262 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
b44164bb
C
263 }
264
265 {
a1587156 266 const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
b44164bb
C
267 const blocks: AccountBlock[] = res.body.data
268
269 expect(res.body.total).to.equal(2)
270
a1587156 271 const block = blocks[0]
b44164bb
C
272 expect(block.byAccount.displayName).to.equal('root')
273 expect(block.byAccount.name).to.equal('root')
274 expect(block.blockedAccount.displayName).to.equal('user1')
275 expect(block.blockedAccount.name).to.equal('user1')
7243f84d 276 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
b44164bb
C
277 }
278 })
279
696d83fd
C
280 it('Should not allow a remote blocked user to comment my videos', async function () {
281 this.timeout(60000)
282
283 {
284 await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2')
285 await waitJobs(servers)
286
287 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader')
288 await waitJobs(servers)
289
290 const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader')
291 const message = 'reply by user 2'
292 const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message)
293 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply')
294
295 await waitJobs(servers)
296 }
297
298 // Server 2 has all the comments
299 {
300 const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt')
301 const threads: VideoComment[] = resThreads.body.data
302
303 expect(threads).to.have.lengthOf(2)
304 expect(threads[0].text).to.equal('uploader')
305 expect(threads[1].text).to.equal('comment user 2')
306
307 const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id)
308
309 const tree: VideoCommentThreadTree = resReplies.body
310 expect(tree.children).to.have.lengthOf(1)
311 expect(tree.children[0].comment.text).to.equal('reply by user 2')
312 expect(tree.children[0].children).to.have.lengthOf(1)
313 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
314 }
315
316 // Server 1 and 3 should only have uploader comments
317 for (const server of [ servers[0], servers[2] ]) {
318 const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt')
319 const threads: VideoComment[] = resThreads.body.data
320
321 expect(threads).to.have.lengthOf(1)
322 expect(threads[0].text).to.equal('uploader')
323
324 const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id)
325
326 const tree: VideoCommentThreadTree = resReplies.body
327 if (server.serverNumber === 1) {
328 expect(tree.children).to.have.lengthOf(0)
329 } else {
330 expect(tree.children).to.have.lengthOf(1)
331 }
332 }
333 })
334
b44164bb 335 it('Should unblock the remote account', async function () {
a1587156 336 await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
b44164bb
C
337 })
338
339 it('Should display its videos', async function () {
a1587156 340 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
b44164bb
C
341
342 const videos: Video[] = res.body.data
696d83fd 343 expect(videos).to.have.lengthOf(4)
b44164bb
C
344
345 const v = videos.find(v => v.name === 'video user 2')
346 expect(v).not.to.be.undefined
347 })
348
696d83fd
C
349 it('Should display its comments on my video', async function () {
350 for (const server of servers) {
351 const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt')
352 const threads: VideoComment[] = resThreads.body.data
353
354 // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
355 if (server.serverNumber === 3) {
356 expect(threads).to.have.lengthOf(1)
357 continue
358 }
359
360 expect(threads).to.have.lengthOf(2)
361 expect(threads[0].text).to.equal('uploader')
362 expect(threads[1].text).to.equal('comment user 2')
363
364 const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id)
365
366 const tree: VideoCommentThreadTree = resReplies.body
367 expect(tree.children).to.have.lengthOf(1)
368 expect(tree.children[0].comment.text).to.equal('reply by user 2')
369 expect(tree.children[0].children).to.have.lengthOf(1)
370 expect(tree.children[0].children[0].comment.text).to.equal('another reply')
371 }
372 })
373
b44164bb 374 it('Should unblock the local account', async function () {
a1587156 375 await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
b44164bb
C
376 })
377
378 it('Should display its comments', function () {
a1587156 379 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
b44164bb 380 })
dddc8b1f
C
381
382 it('Should have a notification from a non blocked account', async function () {
383 this.timeout(20000)
384
385 {
a1587156
C
386 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
387 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f
C
388 }
389
390 {
391 const comment = {
a1587156 392 server: servers[0],
dddc8b1f
C
393 token: userToken1,
394 videoUUID: videoUUID2,
a1587156 395 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 396 }
a1587156 397 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f
C
398 }
399 })
b44164bb
C
400 })
401
402 describe('When managing server blocklist', function () {
403 it('Should list all videos', function () {
a1587156 404 return checkAllVideos(servers[0].url, servers[0].accessToken)
b44164bb
C
405 })
406
407 it('Should list the comments', function () {
a1587156 408 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
b44164bb
C
409 })
410
411 it('Should block a remote server', async function () {
a1587156 412 await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
b44164bb
C
413 })
414
415 it('Should hide its videos', async function () {
a1587156 416 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
b44164bb
C
417
418 const videos: Video[] = res.body.data
696d83fd 419 expect(videos).to.have.lengthOf(3)
b44164bb
C
420
421 const v1 = videos.find(v => v.name === 'video user 2')
422 const v2 = videos.find(v => v.name === 'video server 2')
423
424 expect(v1).to.be.undefined
425 expect(v2).to.be.undefined
426 })
427
428 it('Should list all the videos with another user', async function () {
a1587156 429 return checkAllVideos(servers[0].url, userToken1)
b44164bb
C
430 })
431
dddc8b1f
C
432 it('Should hide its comments', async function () {
433 this.timeout(10000)
434
a1587156 435 const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
dddc8b1f
C
436 const threadId = resThreads.body.comment.id
437
438 await waitJobs(servers)
439
a1587156 440 await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
dddc8b1f 441
a1587156 442 await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
dddc8b1f
C
443 })
444
445 it('Should not have notifications from blocked server', async function () {
446 this.timeout(20000)
447
448 {
a1587156
C
449 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
450 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f
C
451 }
452
453 {
454 const comment = {
a1587156 455 server: servers[1],
dddc8b1f
C
456 token: userToken2,
457 videoUUID: videoUUID1,
a1587156 458 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 459 }
a1587156 460 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f
C
461 }
462 })
b44164bb
C
463
464 it('Should list blocked servers', async function () {
a1587156 465 const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
b44164bb
C
466 const blocks: ServerBlock[] = res.body.data
467
468 expect(res.body.total).to.equal(1)
469
a1587156 470 const block = blocks[0]
b44164bb
C
471 expect(block.byAccount.displayName).to.equal('root')
472 expect(block.byAccount.name).to.equal('root')
7243f84d 473 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
b44164bb
C
474 })
475
476 it('Should unblock the remote server', async function () {
a1587156 477 await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
b44164bb
C
478 })
479
480 it('Should display its videos', function () {
a1587156 481 return checkAllVideos(servers[0].url, servers[0].accessToken)
b44164bb
C
482 })
483
484 it('Should display its comments', function () {
a1587156 485 return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
b44164bb 486 })
dddc8b1f
C
487
488 it('Should have notification from unblocked server', async function () {
489 this.timeout(20000)
490
491 {
a1587156
C
492 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
493 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f
C
494 }
495
496 {
497 const comment = {
a1587156 498 server: servers[1],
dddc8b1f
C
499 token: userToken2,
500 videoUUID: videoUUID1,
a1587156 501 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 502 }
a1587156 503 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f
C
504 }
505 })
b44164bb
C
506 })
507 })
508
509 describe('Server blocklist', function () {
510
511 describe('When managing account blocklist', function () {
512 it('Should list all videos', async function () {
a1587156
C
513 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
514 await checkAllVideos(servers[0].url, token)
b44164bb
C
515 }
516 })
517
518 it('Should list the comments', async function () {
a1587156
C
519 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
520 await checkAllComments(servers[0].url, token, videoUUID1)
b44164bb
C
521 }
522 })
523
524 it('Should block a remote account', async function () {
a1587156 525 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
b44164bb
C
526 })
527
528 it('Should hide its videos', async function () {
a1587156
C
529 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
530 const res = await getVideosListWithToken(servers[0].url, token)
b44164bb
C
531
532 const videos: Video[] = res.body.data
696d83fd 533 expect(videos).to.have.lengthOf(4)
b44164bb
C
534
535 const v = videos.find(v => v.name === 'video user 2')
536 expect(v).to.be.undefined
537 }
538 })
539
540 it('Should block a local account', async function () {
a1587156 541 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
b44164bb
C
542 })
543
544 it('Should hide its videos', async function () {
a1587156
C
545 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
546 const res = await getVideosListWithToken(servers[0].url, token)
b44164bb
C
547
548 const videos: Video[] = res.body.data
696d83fd 549 expect(videos).to.have.lengthOf(3)
b44164bb
C
550
551 const v = videos.find(v => v.name === 'video user 1')
552 expect(v).to.be.undefined
553 }
554 })
555
556 it('Should hide its comments', async function () {
a1587156 557 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
8adf0a76
C
558 const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token)
559
560 let threads: VideoComment[] = resThreads.body.data
561 threads = threads.filter(t => t.isDeleted === false)
b44164bb 562
b44164bb 563 expect(threads).to.have.lengthOf(1)
a1587156 564 expect(threads[0].totalReplies).to.equal(0)
b44164bb
C
565
566 const t = threads.find(t => t.text === 'comment user 1')
567 expect(t).to.be.undefined
568
569 for (const thread of threads) {
a1587156 570 const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token)
b44164bb
C
571
572 const tree: VideoCommentThreadTree = res.body
573 expect(tree.children).to.have.lengthOf(0)
574 }
575 }
576 })
577
dddc8b1f
C
578 it('Should not have notification from blocked accounts by instance', async function () {
579 this.timeout(20000)
580
581 {
a1587156
C
582 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
583 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f
C
584 }
585
586 {
587 const comment = {
a1587156 588 server: servers[1],
dddc8b1f
C
589 token: userToken2,
590 videoUUID: videoUUID1,
a1587156 591 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 592 }
a1587156 593 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f
C
594 }
595 })
596
b44164bb
C
597 it('Should list blocked accounts', async function () {
598 {
a1587156 599 const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
b44164bb
C
600 const blocks: AccountBlock[] = res.body.data
601
602 expect(res.body.total).to.equal(2)
603
a1587156 604 const block = blocks[0]
b44164bb
C
605 expect(block.byAccount.displayName).to.equal('peertube')
606 expect(block.byAccount.name).to.equal('peertube')
607 expect(block.blockedAccount.displayName).to.equal('user2')
608 expect(block.blockedAccount.name).to.equal('user2')
7243f84d 609 expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
b44164bb
C
610 }
611
612 {
a1587156 613 const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
b44164bb
C
614 const blocks: AccountBlock[] = res.body.data
615
616 expect(res.body.total).to.equal(2)
617
a1587156 618 const block = blocks[0]
b44164bb
C
619 expect(block.byAccount.displayName).to.equal('peertube')
620 expect(block.byAccount.name).to.equal('peertube')
621 expect(block.blockedAccount.displayName).to.equal('user1')
622 expect(block.blockedAccount.name).to.equal('user1')
7243f84d 623 expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
b44164bb
C
624 }
625 })
626
627 it('Should unblock the remote account', async function () {
a1587156 628 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
b44164bb
C
629 })
630
631 it('Should display its videos', async function () {
a1587156
C
632 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
633 const res = await getVideosListWithToken(servers[0].url, token)
b44164bb
C
634
635 const videos: Video[] = res.body.data
696d83fd 636 expect(videos).to.have.lengthOf(4)
b44164bb
C
637
638 const v = videos.find(v => v.name === 'video user 2')
639 expect(v).not.to.be.undefined
640 }
641 })
642
643 it('Should unblock the local account', async function () {
a1587156 644 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
b44164bb
C
645 })
646
647 it('Should display its comments', async function () {
a1587156
C
648 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
649 await checkAllComments(servers[0].url, token, videoUUID1)
b44164bb
C
650 }
651 })
dddc8b1f
C
652
653 it('Should have notifications from unblocked accounts', async function () {
654 this.timeout(20000)
655
656 {
a1587156
C
657 const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
658 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f
C
659 }
660
661 {
662 const comment = {
a1587156 663 server: servers[1],
dddc8b1f
C
664 token: userToken2,
665 videoUUID: videoUUID1,
a1587156 666 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 667 }
a1587156 668 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f
C
669 }
670 })
b44164bb
C
671 })
672
673 describe('When managing server blocklist', function () {
674 it('Should list all videos', async function () {
a1587156
C
675 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
676 await checkAllVideos(servers[0].url, token)
b44164bb
C
677 }
678 })
679
680 it('Should list the comments', async function () {
a1587156
C
681 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
682 await checkAllComments(servers[0].url, token, videoUUID1)
b44164bb
C
683 }
684 })
685
686 it('Should block a remote server', async function () {
a1587156 687 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
b44164bb
C
688 })
689
690 it('Should hide its videos', async function () {
a1587156
C
691 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
692 const res1 = await getVideosList(servers[0].url)
693 const res2 = await getVideosListWithToken(servers[0].url, token)
b44164bb 694
65b21c96
C
695 for (const res of [ res1, res2 ]) {
696 const videos: Video[] = res.body.data
696d83fd 697 expect(videos).to.have.lengthOf(3)
b44164bb 698
65b21c96
C
699 const v1 = videos.find(v => v.name === 'video user 2')
700 const v2 = videos.find(v => v.name === 'video server 2')
b44164bb 701
65b21c96
C
702 expect(v1).to.be.undefined
703 expect(v2).to.be.undefined
704 }
b44164bb
C
705 }
706 })
707
dddc8b1f
C
708 it('Should hide its comments', async function () {
709 this.timeout(10000)
710
a1587156 711 const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
dddc8b1f
C
712 const threadId = resThreads.body.comment.id
713
714 await waitJobs(servers)
715
a1587156 716 await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
dddc8b1f 717
a1587156 718 await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
dddc8b1f
C
719 })
720
721 it('Should not have notification from blocked instances by instance', async function () {
696d83fd 722 this.timeout(50000)
dddc8b1f
C
723
724 {
a1587156
C
725 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
726 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f
C
727 }
728
729 {
730 const comment = {
a1587156 731 server: servers[1],
dddc8b1f
C
732 token: userToken2,
733 videoUUID: videoUUID1,
a1587156 734 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 735 }
a1587156 736 await checkCommentNotification(servers[0], comment, 'absence')
dddc8b1f 737 }
696d83fd
C
738
739 {
740 const now = new Date()
741 await unfollow(servers[1].url, servers[1].accessToken, servers[0])
742 await waitJobs(servers)
743 await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
744
745 await waitJobs(servers)
746
747 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30)
748 const commentNotifications = (res.body.data as UserNotification[])
749 .filter(n => {
750 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER &&
751 n.createdAt >= now.toISOString()
752 })
753
754 expect(commentNotifications).to.have.lengthOf(0)
755 }
dddc8b1f 756 })
b44164bb
C
757
758 it('Should list blocked servers', async function () {
a1587156 759 const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
b44164bb
C
760 const blocks: ServerBlock[] = res.body.data
761
762 expect(res.body.total).to.equal(1)
763
a1587156 764 const block = blocks[0]
b44164bb
C
765 expect(block.byAccount.displayName).to.equal('peertube')
766 expect(block.byAccount.name).to.equal('peertube')
7243f84d 767 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
b44164bb
C
768 })
769
770 it('Should unblock the remote server', async function () {
a1587156 771 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
b44164bb
C
772 })
773
774 it('Should list all videos', async function () {
a1587156
C
775 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
776 await checkAllVideos(servers[0].url, token)
b44164bb
C
777 }
778 })
779
780 it('Should list the comments', async function () {
a1587156
C
781 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
782 await checkAllComments(servers[0].url, token, videoUUID1)
b44164bb
C
783 }
784 })
dddc8b1f
C
785
786 it('Should have notification from unblocked instances', async function () {
696d83fd 787 this.timeout(50000)
dddc8b1f
C
788
789 {
a1587156
C
790 const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
791 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f
C
792 }
793
794 {
795 const comment = {
a1587156 796 server: servers[1],
dddc8b1f
C
797 token: userToken2,
798 videoUUID: videoUUID1,
a1587156 799 text: 'hello @root@localhost:' + servers[0].port
dddc8b1f 800 }
a1587156 801 await checkCommentNotification(servers[0], comment, 'presence')
dddc8b1f 802 }
696d83fd
C
803
804 {
805 const now = new Date()
806 await unfollow(servers[1].url, servers[1].accessToken, servers[0])
807 await waitJobs(servers)
808 await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
809
810 await waitJobs(servers)
811
812 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30)
813 const commentNotifications = (res.body.data as UserNotification[])
814 .filter(n => {
815 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER &&
816 n.createdAt >= now.toISOString()
817 })
818
819 expect(commentNotifications).to.have.lengthOf(1)
820 }
dddc8b1f 821 })
b44164bb
C
822 })
823 })
824
7c3b7976
C
825 after(async function () {
826 await cleanupTests(servers)
b44164bb
C
827 })
828})