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