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