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