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