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