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