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