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