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