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