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