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