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