]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
b44164bb C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
a1587156 | 5 | import { AccountBlock, ServerBlock, Video } from '../../../../shared/index' |
b44164bb | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
a1587156 C |
8 | createUser, |
9 | deleteVideoComment, | |
b44164bb C |
10 | doubleFollow, |
11 | flushAndRunMultipleServers, | |
b44164bb C |
12 | ServerInfo, |
13 | uploadVideo, | |
14 | userLogin | |
94565d52 C |
15 | } from '../../../../shared/extra-utils/index' |
16 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | |
a1587156 | 17 | import { getVideosList, getVideosListWithToken } from '../../../../shared/extra-utils/videos/videos' |
b44164bb C |
18 | import { |
19 | addVideoCommentReply, | |
20 | addVideoCommentThread, | |
21 | getVideoCommentThreads, | |
22 | getVideoThreadComments | |
94565d52 C |
23 | } from '../../../../shared/extra-utils/videos/video-comments' |
24 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
b44164bb C |
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 | |
94565d52 | 39 | } from '../../../../shared/extra-utils/users/blocklist' |
32c68d67 | 40 | import { getUserNotifications } from '../../../../shared/extra-utils/users/user-notifications' |
b44164bb C |
41 | |
42 | const expect = chai.expect | |
43 | ||
44 | async function checkAllVideos (url: string, token: string) { | |
65b21c96 C |
45 | { |
46 | const res = await getVideosListWithToken(url, token) | |
b44164bb | 47 | |
65b21c96 C |
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 | } | |
b44164bb C |
56 | } |
57 | ||
58 | async function checkAllComments (url: string, token: string, videoUUID: string) { | |
dddc8b1f | 59 | const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) |
b44164bb | 60 | |
dddc8b1f C |
61 | const allThreads: VideoComment[] = resThreads.body.data |
62 | const threads = allThreads.filter(t => t.isDeleted === false) | |
b44164bb C |
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 | ||
dddc8b1f C |
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 | ||
a1587156 | 81 | await waitJobs([ mainServer, comment.server ]) |
dddc8b1f C |
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 | ||
a1587156 | 92 | await waitJobs([ mainServer, comment.server ]) |
dddc8b1f C |
93 | } |
94 | ||
b44164bb C |
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 | ||
b44164bb C |
106 | servers = await flushAndRunMultipleServers(2) |
107 | await setAccessTokensToServers(servers) | |
108 | ||
109 | { | |
110 | const user = { username: 'user1', password: 'password' } | |
a1587156 | 111 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
b44164bb C |
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' } | |
a1587156 | 119 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
b44164bb C |
120 | |
121 | userModeratorToken = await userLogin(servers[0], user) | |
122 | } | |
123 | ||
124 | { | |
125 | const user = { username: 'user2', password: 'password' } | |
a1587156 | 126 | await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) |
b44164bb C |
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 | { | |
a1587156 C |
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') | |
b44164bb C |
148 | } |
149 | ||
150 | { | |
a1587156 C |
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') | |
b44164bb C |
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 () { | |
a1587156 | 162 | return checkAllVideos(servers[0].url, servers[0].accessToken) |
b44164bb C |
163 | }) |
164 | ||
165 | it('Should list the comments', function () { | |
a1587156 | 166 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) |
b44164bb C |
167 | }) |
168 | ||
169 | it('Should block a remote account', async function () { | |
a1587156 | 170 | await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) |
b44164bb C |
171 | }) |
172 | ||
173 | it('Should hide its videos', async function () { | |
a1587156 | 174 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) |
b44164bb C |
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 () { | |
a1587156 | 184 | await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') |
b44164bb C |
185 | }) |
186 | ||
187 | it('Should hide its videos', async function () { | |
a1587156 | 188 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) |
b44164bb C |
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 () { | |
a1587156 | 198 | const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', servers[0].accessToken) |
b44164bb C |
199 | |
200 | const threads: VideoComment[] = resThreads.body.data | |
201 | expect(threads).to.have.lengthOf(1) | |
a1587156 | 202 | expect(threads[0].totalReplies).to.equal(0) |
b44164bb C |
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) { | |
a1587156 | 208 | const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) |
b44164bb C |
209 | |
210 | const tree: VideoCommentThreadTree = res.body | |
211 | expect(tree.children).to.have.lengthOf(0) | |
212 | } | |
213 | }) | |
214 | ||
dddc8b1f C |
215 | it('Should not have notifications from blocked accounts', async function () { |
216 | this.timeout(20000) | |
217 | ||
218 | { | |
a1587156 C |
219 | const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } |
220 | await checkCommentNotification(servers[0], comment, 'absence') | |
dddc8b1f C |
221 | } |
222 | ||
223 | { | |
224 | const comment = { | |
a1587156 | 225 | server: servers[0], |
dddc8b1f C |
226 | token: userToken1, |
227 | videoUUID: videoUUID2, | |
a1587156 | 228 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 229 | } |
a1587156 | 230 | await checkCommentNotification(servers[0], comment, 'absence') |
dddc8b1f C |
231 | } |
232 | }) | |
233 | ||
b44164bb | 234 | it('Should list all the videos with another user', async function () { |
a1587156 | 235 | return checkAllVideos(servers[0].url, userToken1) |
b44164bb C |
236 | }) |
237 | ||
238 | it('Should list all the comments with another user', async function () { | |
a1587156 | 239 | return checkAllComments(servers[0].url, userToken1, videoUUID1) |
b44164bb C |
240 | }) |
241 | ||
242 | it('Should list blocked accounts', async function () { | |
243 | { | |
a1587156 | 244 | const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') |
b44164bb C |
245 | const blocks: AccountBlock[] = res.body.data |
246 | ||
247 | expect(res.body.total).to.equal(2) | |
248 | ||
a1587156 | 249 | const block = blocks[0] |
b44164bb C |
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') | |
7243f84d | 254 | expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) |
b44164bb C |
255 | } |
256 | ||
257 | { | |
a1587156 | 258 | const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') |
b44164bb C |
259 | const blocks: AccountBlock[] = res.body.data |
260 | ||
261 | expect(res.body.total).to.equal(2) | |
262 | ||
a1587156 | 263 | const block = blocks[0] |
b44164bb C |
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') | |
7243f84d | 268 | expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) |
b44164bb C |
269 | } |
270 | }) | |
271 | ||
272 | it('Should unblock the remote account', async function () { | |
a1587156 | 273 | await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) |
b44164bb C |
274 | }) |
275 | ||
276 | it('Should display its videos', async function () { | |
a1587156 | 277 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) |
b44164bb C |
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 () { | |
a1587156 | 287 | await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') |
b44164bb C |
288 | }) |
289 | ||
290 | it('Should display its comments', function () { | |
a1587156 | 291 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) |
b44164bb | 292 | }) |
dddc8b1f C |
293 | |
294 | it('Should have a notification from a non blocked account', async function () { | |
295 | this.timeout(20000) | |
296 | ||
297 | { | |
a1587156 C |
298 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } |
299 | await checkCommentNotification(servers[0], comment, 'presence') | |
dddc8b1f C |
300 | } |
301 | ||
302 | { | |
303 | const comment = { | |
a1587156 | 304 | server: servers[0], |
dddc8b1f C |
305 | token: userToken1, |
306 | videoUUID: videoUUID2, | |
a1587156 | 307 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 308 | } |
a1587156 | 309 | await checkCommentNotification(servers[0], comment, 'presence') |
dddc8b1f C |
310 | } |
311 | }) | |
b44164bb C |
312 | }) |
313 | ||
314 | describe('When managing server blocklist', function () { | |
315 | it('Should list all videos', function () { | |
a1587156 | 316 | return checkAllVideos(servers[0].url, servers[0].accessToken) |
b44164bb C |
317 | }) |
318 | ||
319 | it('Should list the comments', function () { | |
a1587156 | 320 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) |
b44164bb C |
321 | }) |
322 | ||
323 | it('Should block a remote server', async function () { | |
a1587156 | 324 | await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) |
b44164bb C |
325 | }) |
326 | ||
327 | it('Should hide its videos', async function () { | |
a1587156 | 328 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) |
b44164bb C |
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 () { | |
a1587156 | 341 | return checkAllVideos(servers[0].url, userToken1) |
b44164bb C |
342 | }) |
343 | ||
dddc8b1f C |
344 | it('Should hide its comments', async function () { |
345 | this.timeout(10000) | |
346 | ||
a1587156 | 347 | const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') |
dddc8b1f C |
348 | const threadId = resThreads.body.comment.id |
349 | ||
350 | await waitJobs(servers) | |
351 | ||
a1587156 | 352 | await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) |
dddc8b1f | 353 | |
a1587156 | 354 | await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) |
dddc8b1f C |
355 | }) |
356 | ||
357 | it('Should not have notifications from blocked server', async function () { | |
358 | this.timeout(20000) | |
359 | ||
360 | { | |
a1587156 C |
361 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } |
362 | await checkCommentNotification(servers[0], comment, 'absence') | |
dddc8b1f C |
363 | } |
364 | ||
365 | { | |
366 | const comment = { | |
a1587156 | 367 | server: servers[1], |
dddc8b1f C |
368 | token: userToken2, |
369 | videoUUID: videoUUID1, | |
a1587156 | 370 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 371 | } |
a1587156 | 372 | await checkCommentNotification(servers[0], comment, 'absence') |
dddc8b1f C |
373 | } |
374 | }) | |
b44164bb C |
375 | |
376 | it('Should list blocked servers', async function () { | |
a1587156 | 377 | const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') |
b44164bb C |
378 | const blocks: ServerBlock[] = res.body.data |
379 | ||
380 | expect(res.body.total).to.equal(1) | |
381 | ||
a1587156 | 382 | const block = blocks[0] |
b44164bb C |
383 | expect(block.byAccount.displayName).to.equal('root') |
384 | expect(block.byAccount.name).to.equal('root') | |
7243f84d | 385 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) |
b44164bb C |
386 | }) |
387 | ||
388 | it('Should unblock the remote server', async function () { | |
a1587156 | 389 | await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) |
b44164bb C |
390 | }) |
391 | ||
392 | it('Should display its videos', function () { | |
a1587156 | 393 | return checkAllVideos(servers[0].url, servers[0].accessToken) |
b44164bb C |
394 | }) |
395 | ||
396 | it('Should display its comments', function () { | |
a1587156 | 397 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) |
b44164bb | 398 | }) |
dddc8b1f C |
399 | |
400 | it('Should have notification from unblocked server', async function () { | |
401 | this.timeout(20000) | |
402 | ||
403 | { | |
a1587156 C |
404 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } |
405 | await checkCommentNotification(servers[0], comment, 'presence') | |
dddc8b1f C |
406 | } |
407 | ||
408 | { | |
409 | const comment = { | |
a1587156 | 410 | server: servers[1], |
dddc8b1f C |
411 | token: userToken2, |
412 | videoUUID: videoUUID1, | |
a1587156 | 413 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 414 | } |
a1587156 | 415 | await checkCommentNotification(servers[0], comment, 'presence') |
dddc8b1f C |
416 | } |
417 | }) | |
b44164bb C |
418 | }) |
419 | }) | |
420 | ||
421 | describe('Server blocklist', function () { | |
422 | ||
423 | describe('When managing account blocklist', function () { | |
424 | it('Should list all videos', async function () { | |
a1587156 C |
425 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
426 | await checkAllVideos(servers[0].url, token) | |
b44164bb C |
427 | } |
428 | }) | |
429 | ||
430 | it('Should list the comments', async function () { | |
a1587156 C |
431 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
432 | await checkAllComments(servers[0].url, token, videoUUID1) | |
b44164bb C |
433 | } |
434 | }) | |
435 | ||
436 | it('Should block a remote account', async function () { | |
a1587156 | 437 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) |
b44164bb C |
438 | }) |
439 | ||
440 | it('Should hide its videos', async function () { | |
a1587156 C |
441 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
442 | const res = await getVideosListWithToken(servers[0].url, token) | |
b44164bb C |
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 () { | |
a1587156 | 453 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') |
b44164bb C |
454 | }) |
455 | ||
456 | it('Should hide its videos', async function () { | |
a1587156 C |
457 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
458 | const res = await getVideosListWithToken(servers[0].url, token) | |
b44164bb C |
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 () { | |
a1587156 C |
469 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
470 | const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', token) | |
b44164bb C |
471 | |
472 | const threads: VideoComment[] = resThreads.body.data | |
473 | expect(threads).to.have.lengthOf(1) | |
a1587156 | 474 | expect(threads[0].totalReplies).to.equal(0) |
b44164bb C |
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) { | |
a1587156 | 480 | const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token) |
b44164bb C |
481 | |
482 | const tree: VideoCommentThreadTree = res.body | |
483 | expect(tree.children).to.have.lengthOf(0) | |
484 | } | |
485 | } | |
486 | }) | |
487 | ||
dddc8b1f C |
488 | it('Should not have notification from blocked accounts by instance', async function () { |
489 | this.timeout(20000) | |
490 | ||
491 | { | |
a1587156 C |
492 | const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } |
493 | await checkCommentNotification(servers[0], comment, 'absence') | |
dddc8b1f C |
494 | } |
495 | ||
496 | { | |
497 | const comment = { | |
a1587156 | 498 | server: servers[1], |
dddc8b1f C |
499 | token: userToken2, |
500 | videoUUID: videoUUID1, | |
a1587156 | 501 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 502 | } |
a1587156 | 503 | await checkCommentNotification(servers[0], comment, 'absence') |
dddc8b1f C |
504 | } |
505 | }) | |
506 | ||
b44164bb C |
507 | it('Should list blocked accounts', async function () { |
508 | { | |
a1587156 | 509 | const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') |
b44164bb C |
510 | const blocks: AccountBlock[] = res.body.data |
511 | ||
512 | expect(res.body.total).to.equal(2) | |
513 | ||
a1587156 | 514 | const block = blocks[0] |
b44164bb C |
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') | |
7243f84d | 519 | expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) |
b44164bb C |
520 | } |
521 | ||
522 | { | |
a1587156 | 523 | const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') |
b44164bb C |
524 | const blocks: AccountBlock[] = res.body.data |
525 | ||
526 | expect(res.body.total).to.equal(2) | |
527 | ||
a1587156 | 528 | const block = blocks[0] |
b44164bb C |
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') | |
7243f84d | 533 | expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) |
b44164bb C |
534 | } |
535 | }) | |
536 | ||
537 | it('Should unblock the remote account', async function () { | |
a1587156 | 538 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) |
b44164bb C |
539 | }) |
540 | ||
541 | it('Should display its videos', async function () { | |
a1587156 C |
542 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
543 | const res = await getVideosListWithToken(servers[0].url, token) | |
b44164bb C |
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 () { | |
a1587156 | 554 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') |
b44164bb C |
555 | }) |
556 | ||
557 | it('Should display its comments', async function () { | |
a1587156 C |
558 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
559 | await checkAllComments(servers[0].url, token, videoUUID1) | |
b44164bb C |
560 | } |
561 | }) | |
dddc8b1f C |
562 | |
563 | it('Should have notifications from unblocked accounts', async function () { | |
564 | this.timeout(20000) | |
565 | ||
566 | { | |
a1587156 C |
567 | const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' } |
568 | await checkCommentNotification(servers[0], comment, 'presence') | |
dddc8b1f C |
569 | } |
570 | ||
571 | { | |
572 | const comment = { | |
a1587156 | 573 | server: servers[1], |
dddc8b1f C |
574 | token: userToken2, |
575 | videoUUID: videoUUID1, | |
a1587156 | 576 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 577 | } |
a1587156 | 578 | await checkCommentNotification(servers[0], comment, 'presence') |
dddc8b1f C |
579 | } |
580 | }) | |
b44164bb C |
581 | }) |
582 | ||
583 | describe('When managing server blocklist', function () { | |
584 | it('Should list all videos', async function () { | |
a1587156 C |
585 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
586 | await checkAllVideos(servers[0].url, token) | |
b44164bb C |
587 | } |
588 | }) | |
589 | ||
590 | it('Should list the comments', async function () { | |
a1587156 C |
591 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
592 | await checkAllComments(servers[0].url, token, videoUUID1) | |
b44164bb C |
593 | } |
594 | }) | |
595 | ||
596 | it('Should block a remote server', async function () { | |
a1587156 | 597 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) |
b44164bb C |
598 | }) |
599 | ||
600 | it('Should hide its videos', async function () { | |
a1587156 C |
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) | |
b44164bb | 604 | |
65b21c96 C |
605 | for (const res of [ res1, res2 ]) { |
606 | const videos: Video[] = res.body.data | |
607 | expect(videos).to.have.lengthOf(2) | |
b44164bb | 608 | |
65b21c96 C |
609 | const v1 = videos.find(v => v.name === 'video user 2') |
610 | const v2 = videos.find(v => v.name === 'video server 2') | |
b44164bb | 611 | |
65b21c96 C |
612 | expect(v1).to.be.undefined |
613 | expect(v2).to.be.undefined | |
614 | } | |
b44164bb C |
615 | } |
616 | }) | |
617 | ||
dddc8b1f C |
618 | it('Should hide its comments', async function () { |
619 | this.timeout(10000) | |
620 | ||
a1587156 | 621 | const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') |
dddc8b1f C |
622 | const threadId = resThreads.body.comment.id |
623 | ||
624 | await waitJobs(servers) | |
625 | ||
a1587156 | 626 | await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) |
dddc8b1f | 627 | |
a1587156 | 628 | await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) |
dddc8b1f C |
629 | }) |
630 | ||
631 | it('Should not have notification from blocked instances by instance', async function () { | |
632 | this.timeout(20000) | |
633 | ||
634 | { | |
a1587156 C |
635 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } |
636 | await checkCommentNotification(servers[0], comment, 'absence') | |
dddc8b1f C |
637 | } |
638 | ||
639 | { | |
640 | const comment = { | |
a1587156 | 641 | server: servers[1], |
dddc8b1f C |
642 | token: userToken2, |
643 | videoUUID: videoUUID1, | |
a1587156 | 644 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 645 | } |
a1587156 | 646 | await checkCommentNotification(servers[0], comment, 'absence') |
dddc8b1f C |
647 | } |
648 | }) | |
b44164bb C |
649 | |
650 | it('Should list blocked servers', async function () { | |
a1587156 | 651 | const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') |
b44164bb C |
652 | const blocks: ServerBlock[] = res.body.data |
653 | ||
654 | expect(res.body.total).to.equal(1) | |
655 | ||
a1587156 | 656 | const block = blocks[0] |
b44164bb C |
657 | expect(block.byAccount.displayName).to.equal('peertube') |
658 | expect(block.byAccount.name).to.equal('peertube') | |
7243f84d | 659 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) |
b44164bb C |
660 | }) |
661 | ||
662 | it('Should unblock the remote server', async function () { | |
a1587156 | 663 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) |
b44164bb C |
664 | }) |
665 | ||
666 | it('Should list all videos', async function () { | |
a1587156 C |
667 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
668 | await checkAllVideos(servers[0].url, token) | |
b44164bb C |
669 | } |
670 | }) | |
671 | ||
672 | it('Should list the comments', async function () { | |
a1587156 C |
673 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
674 | await checkAllComments(servers[0].url, token, videoUUID1) | |
b44164bb C |
675 | } |
676 | }) | |
dddc8b1f C |
677 | |
678 | it('Should have notification from unblocked instances', async function () { | |
679 | this.timeout(20000) | |
680 | ||
681 | { | |
a1587156 C |
682 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } |
683 | await checkCommentNotification(servers[0], comment, 'presence') | |
dddc8b1f C |
684 | } |
685 | ||
686 | { | |
687 | const comment = { | |
a1587156 | 688 | server: servers[1], |
dddc8b1f C |
689 | token: userToken2, |
690 | videoUUID: videoUUID1, | |
a1587156 | 691 | text: 'hello @root@localhost:' + servers[0].port |
dddc8b1f | 692 | } |
a1587156 | 693 | await checkCommentNotification(servers[0], comment, 'presence') |
dddc8b1f C |
694 | } |
695 | }) | |
b44164bb C |
696 | }) |
697 | }) | |
698 | ||
7c3b7976 C |
699 | after(async function () { |
700 | await cleanupTests(servers) | |
b44164bb C |
701 | }) |
702 | }) |