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