]>
Commit | Line | Data |
---|---|---|
8eb07b01 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import { v4 as uuidv4 } from 'uuid' | |
5 | import { | |
310b5219 | 6 | addVideoCommentThread, |
8eb07b01 C |
7 | addVideoToBlacklist, |
8 | cleanupTests, | |
310b5219 | 9 | createUser, |
8eb07b01 | 10 | follow, |
310b5219 C |
11 | generateUserAccessToken, |
12 | getAccount, | |
8eb07b01 | 13 | getCustomConfig, |
310b5219 C |
14 | getVideoCommentThreads, |
15 | getVideoIdFromUUID, | |
8eb07b01 C |
16 | immutableAssign, |
17 | MockInstancesIndex, | |
18 | registerUser, | |
19 | removeVideoFromBlacklist, | |
4f32032f | 20 | reportAbuse, |
8eb07b01 C |
21 | unfollow, |
22 | updateCustomConfig, | |
23 | updateCustomSubConfig, | |
24 | wait | |
25 | } from '../../../../shared/extra-utils' | |
26 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | |
27 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | |
28 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
29 | import { | |
30 | checkAutoInstanceFollowing, | |
31 | CheckerBaseParams, | |
310b5219 | 32 | checkNewAccountAbuseForModerators, |
8eb07b01 | 33 | checkNewBlacklistOnMyVideo, |
310b5219 | 34 | checkNewCommentAbuseForModerators, |
8eb07b01 C |
35 | checkNewInstanceFollower, |
36 | checkNewVideoAbuseForModerators, | |
37 | checkNewVideoFromSubscription, | |
38 | checkUserRegistered, | |
39 | checkVideoAutoBlacklistForModerators, | |
40 | checkVideoIsPublished, | |
41 | prepareNotificationsTest | |
42 | } from '../../../../shared/extra-utils/users/user-notifications' | |
43 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' | |
44 | import { CustomConfig } from '../../../../shared/models/server' | |
45 | import { UserNotification } from '../../../../shared/models/users' | |
46 | import { VideoPrivacy } from '../../../../shared/models/videos' | |
47 | ||
48 | describe('Test moderation notifications', function () { | |
49 | let servers: ServerInfo[] = [] | |
50 | let userAccessToken: string | |
51 | let userNotifications: UserNotification[] = [] | |
52 | let adminNotifications: UserNotification[] = [] | |
53 | let adminNotificationsServer2: UserNotification[] = [] | |
54 | let emails: object[] = [] | |
55 | ||
56 | before(async function () { | |
57 | this.timeout(120000) | |
58 | ||
59 | const res = await prepareNotificationsTest(3) | |
60 | emails = res.emails | |
61 | userAccessToken = res.userAccessToken | |
62 | servers = res.servers | |
63 | userNotifications = res.userNotifications | |
64 | adminNotifications = res.adminNotifications | |
65 | adminNotificationsServer2 = res.adminNotificationsServer2 | |
66 | }) | |
67 | ||
68 | describe('Video abuse for moderators notification', function () { | |
69 | let baseParams: CheckerBaseParams | |
70 | ||
71 | before(() => { | |
72 | baseParams = { | |
73 | server: servers[0], | |
74 | emails, | |
75 | socketNotifications: adminNotifications, | |
76 | token: servers[0].accessToken | |
77 | } | |
78 | }) | |
79 | ||
80 | it('Should send a notification to moderators on local video abuse', async function () { | |
81 | this.timeout(10000) | |
82 | ||
83 | const name = 'video for abuse ' + uuidv4() | |
84 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
4f32032f | 85 | const video = resVideo.body.video |
8eb07b01 | 86 | |
4f32032f | 87 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' }) |
8eb07b01 C |
88 | |
89 | await waitJobs(servers) | |
4f32032f | 90 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') |
8eb07b01 C |
91 | }) |
92 | ||
93 | it('Should send a notification to moderators on remote video abuse', async function () { | |
94 | this.timeout(10000) | |
95 | ||
96 | const name = 'video for abuse ' + uuidv4() | |
97 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
4f32032f | 98 | const video = resVideo.body.video |
8eb07b01 C |
99 | |
100 | await waitJobs(servers) | |
101 | ||
310b5219 C |
102 | const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) |
103 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'super reason' }) | |
8eb07b01 C |
104 | |
105 | await waitJobs(servers) | |
4f32032f | 106 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') |
8eb07b01 | 107 | }) |
310b5219 C |
108 | |
109 | it('Should send a notification to moderators on local comment abuse', async function () { | |
110 | this.timeout(10000) | |
111 | ||
112 | const name = 'video for abuse ' + uuidv4() | |
113 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
114 | const video = resVideo.body.video | |
115 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + uuidv4()) | |
116 | const comment = resComment.body.comment | |
117 | ||
118 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) | |
119 | ||
120 | await waitJobs(servers) | |
121 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | |
122 | }) | |
123 | ||
124 | it('Should send a notification to moderators on remote comment abuse', async function () { | |
125 | this.timeout(10000) | |
126 | ||
127 | const name = 'video for abuse ' + uuidv4() | |
128 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
129 | const video = resVideo.body.video | |
130 | await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + uuidv4()) | |
131 | ||
132 | await waitJobs(servers) | |
133 | ||
134 | const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) | |
135 | const commentId = resComments.body.data[0].id | |
136 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, commentId, reason: 'super reason' }) | |
137 | ||
138 | await waitJobs(servers) | |
139 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | |
140 | }) | |
141 | ||
142 | it('Should send a notification to moderators on local account abuse', async function () { | |
143 | this.timeout(10000) | |
144 | ||
145 | const username = 'user' + new Date().getTime() | |
146 | const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) | |
147 | const accountId = resUser.body.user.account.id | |
148 | ||
149 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId, reason: 'super reason' }) | |
150 | ||
151 | await waitJobs(servers) | |
152 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | |
153 | }) | |
154 | ||
155 | it('Should send a notification to moderators on remote account abuse', async function () { | |
156 | this.timeout(10000) | |
157 | ||
158 | const username = 'user' + new Date().getTime() | |
159 | const tmpToken = await generateUserAccessToken(servers[0], username) | |
160 | await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) | |
161 | ||
162 | await waitJobs(servers) | |
163 | ||
164 | const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) | |
165 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, accountId: resAccount.body.id, reason: 'super reason' }) | |
166 | ||
167 | await waitJobs(servers) | |
168 | await checkNewAccountAbuseForModerators(baseParams, username, 'presence') | |
169 | }) | |
8eb07b01 C |
170 | }) |
171 | ||
172 | describe('Video blacklist on my video', function () { | |
173 | let baseParams: CheckerBaseParams | |
174 | ||
175 | before(() => { | |
176 | baseParams = { | |
177 | server: servers[0], | |
178 | emails, | |
179 | socketNotifications: userNotifications, | |
180 | token: userAccessToken | |
181 | } | |
182 | }) | |
183 | ||
184 | it('Should send a notification to video owner on blacklist', async function () { | |
185 | this.timeout(10000) | |
186 | ||
187 | const name = 'video for abuse ' + uuidv4() | |
188 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
189 | const uuid = resVideo.body.video.uuid | |
190 | ||
191 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
192 | ||
193 | await waitJobs(servers) | |
194 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') | |
195 | }) | |
196 | ||
197 | it('Should send a notification to video owner on unblacklist', async function () { | |
198 | this.timeout(10000) | |
199 | ||
200 | const name = 'video for abuse ' + uuidv4() | |
201 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | |
202 | const uuid = resVideo.body.video.uuid | |
203 | ||
204 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
205 | ||
206 | await waitJobs(servers) | |
207 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
208 | await waitJobs(servers) | |
209 | ||
210 | await wait(500) | |
211 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') | |
212 | }) | |
213 | }) | |
214 | ||
215 | describe('New registration', function () { | |
216 | let baseParams: CheckerBaseParams | |
217 | ||
218 | before(() => { | |
219 | baseParams = { | |
220 | server: servers[0], | |
221 | emails, | |
222 | socketNotifications: adminNotifications, | |
223 | token: servers[0].accessToken | |
224 | } | |
225 | }) | |
226 | ||
227 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | |
228 | this.timeout(10000) | |
229 | ||
230 | await registerUser(servers[0].url, 'user_45', 'password') | |
231 | ||
232 | await waitJobs(servers) | |
233 | ||
234 | await checkUserRegistered(baseParams, 'user_45', 'presence') | |
235 | ||
236 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | |
237 | await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') | |
238 | }) | |
239 | }) | |
240 | ||
241 | describe('New instance follows', function () { | |
242 | const instanceIndexServer = new MockInstancesIndex() | |
243 | const config = { | |
244 | followings: { | |
245 | instance: { | |
246 | autoFollowIndex: { | |
247 | indexUrl: 'http://localhost:42101/api/v1/instances/hosts', | |
248 | enabled: true | |
249 | } | |
250 | } | |
251 | } | |
252 | } | |
253 | let baseParams: CheckerBaseParams | |
254 | ||
255 | before(async () => { | |
256 | baseParams = { | |
257 | server: servers[0], | |
258 | emails, | |
259 | socketNotifications: adminNotifications, | |
260 | token: servers[0].accessToken | |
261 | } | |
262 | ||
263 | await instanceIndexServer.initialize() | |
264 | instanceIndexServer.addInstance(servers[1].host) | |
265 | }) | |
266 | ||
267 | it('Should send a notification only to admin when there is a new instance follower', async function () { | |
268 | this.timeout(20000) | |
269 | ||
270 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | |
271 | ||
272 | await waitJobs(servers) | |
273 | ||
274 | await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') | |
275 | ||
276 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | |
277 | await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') | |
278 | }) | |
279 | ||
280 | it('Should send a notification on auto follow back', async function () { | |
281 | this.timeout(40000) | |
282 | ||
283 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | |
284 | await waitJobs(servers) | |
285 | ||
286 | const config = { | |
287 | followings: { | |
288 | instance: { | |
289 | autoFollowBack: { enabled: true } | |
290 | } | |
291 | } | |
292 | } | |
293 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | |
294 | ||
295 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | |
296 | ||
297 | await waitJobs(servers) | |
298 | ||
299 | const followerHost = servers[0].host | |
300 | const followingHost = servers[2].host | |
301 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | |
302 | ||
303 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | |
304 | await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') | |
305 | ||
306 | config.followings.instance.autoFollowBack.enabled = false | |
307 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | |
308 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | |
309 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | |
310 | }) | |
311 | ||
312 | it('Should send a notification on auto instances index follow', async function () { | |
313 | this.timeout(30000) | |
314 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | |
315 | ||
316 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | |
317 | ||
318 | await wait(5000) | |
319 | await waitJobs(servers) | |
320 | ||
321 | const followerHost = servers[0].host | |
322 | const followingHost = servers[1].host | |
323 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | |
324 | ||
325 | config.followings.instance.autoFollowIndex.enabled = false | |
326 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | |
327 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | |
328 | }) | |
329 | }) | |
330 | ||
331 | describe('Video-related notifications when video auto-blacklist is enabled', function () { | |
332 | let userBaseParams: CheckerBaseParams | |
333 | let adminBaseParamsServer1: CheckerBaseParams | |
334 | let adminBaseParamsServer2: CheckerBaseParams | |
335 | let videoUUID: string | |
336 | let videoName: string | |
337 | let currentCustomConfig: CustomConfig | |
338 | ||
339 | before(async () => { | |
340 | ||
341 | adminBaseParamsServer1 = { | |
342 | server: servers[0], | |
343 | emails, | |
344 | socketNotifications: adminNotifications, | |
345 | token: servers[0].accessToken | |
346 | } | |
347 | ||
348 | adminBaseParamsServer2 = { | |
349 | server: servers[1], | |
350 | emails, | |
351 | socketNotifications: adminNotificationsServer2, | |
352 | token: servers[1].accessToken | |
353 | } | |
354 | ||
355 | userBaseParams = { | |
356 | server: servers[0], | |
357 | emails, | |
358 | socketNotifications: userNotifications, | |
359 | token: userAccessToken | |
360 | } | |
361 | ||
362 | const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) | |
363 | currentCustomConfig = resCustomConfig.body | |
364 | const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { | |
365 | autoBlacklist: { | |
366 | videos: { | |
367 | ofUsers: { | |
368 | enabled: true | |
369 | } | |
370 | } | |
371 | } | |
372 | }) | |
373 | // enable transcoding otherwise own publish notification after transcoding not expected | |
374 | autoBlacklistTestsCustomConfig.transcoding.enabled = true | |
375 | await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) | |
376 | ||
377 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
378 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
379 | ||
380 | }) | |
381 | ||
382 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | |
383 | this.timeout(20000) | |
384 | ||
385 | videoName = 'video with auto-blacklist ' + uuidv4() | |
386 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) | |
387 | videoUUID = resVideo.body.video.uuid | |
388 | ||
389 | await waitJobs(servers) | |
390 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') | |
391 | }) | |
392 | ||
393 | it('Should not send video publish notification if auto-blacklisted', async function () { | |
394 | await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') | |
395 | }) | |
396 | ||
397 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | |
398 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') | |
399 | }) | |
400 | ||
401 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | |
402 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') | |
403 | }) | |
404 | ||
405 | it('Should send video published and unblacklist after video unblacklisted', async function () { | |
406 | this.timeout(20000) | |
407 | ||
408 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) | |
409 | ||
410 | await waitJobs(servers) | |
411 | ||
412 | // FIXME: Can't test as two notifications sent to same user and util only checks last one | |
413 | // One notification might be better anyways | |
414 | // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist') | |
415 | // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence') | |
416 | }) | |
417 | ||
418 | it('Should send a local user subscription notification after removed from blacklist', async function () { | |
419 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') | |
420 | }) | |
421 | ||
422 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | |
423 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') | |
424 | }) | |
425 | ||
426 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | |
427 | this.timeout(20000) | |
428 | ||
429 | const updateAt = new Date(new Date().getTime() + 1000000) | |
430 | ||
431 | const name = 'video with auto-blacklist and future schedule ' + uuidv4() | |
432 | ||
433 | const data = { | |
434 | name, | |
435 | privacy: VideoPrivacy.PRIVATE, | |
436 | scheduleUpdate: { | |
437 | updateAt: updateAt.toISOString(), | |
438 | privacy: VideoPrivacy.PUBLIC | |
439 | } | |
440 | } | |
441 | ||
442 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | |
443 | const uuid = resVideo.body.video.uuid | |
444 | ||
445 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | |
446 | ||
447 | await waitJobs(servers) | |
448 | await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') | |
449 | ||
450 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | |
451 | // One notification might be better anyways | |
452 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | |
453 | ||
454 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | |
455 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | |
456 | }) | |
457 | ||
458 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | |
459 | this.timeout(20000) | |
460 | ||
461 | // In 2 seconds | |
462 | const updateAt = new Date(new Date().getTime() + 2000) | |
463 | ||
464 | const name = 'video with schedule done and still auto-blacklisted ' + uuidv4() | |
465 | ||
466 | const data = { | |
467 | name, | |
468 | privacy: VideoPrivacy.PRIVATE, | |
469 | scheduleUpdate: { | |
470 | updateAt: updateAt.toISOString(), | |
471 | privacy: VideoPrivacy.PUBLIC | |
472 | } | |
473 | } | |
474 | ||
475 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | |
476 | const uuid = resVideo.body.video.uuid | |
477 | ||
478 | await wait(6000) | |
479 | await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | |
480 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | |
481 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | |
482 | }) | |
483 | ||
484 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | |
485 | this.timeout(20000) | |
486 | ||
487 | const name = 'video without auto-blacklist ' + uuidv4() | |
488 | ||
489 | // admin with blacklist right will not be auto-blacklisted | |
490 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) | |
491 | const uuid = resVideo.body.video.uuid | |
492 | ||
493 | await waitJobs(servers) | |
494 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') | |
495 | }) | |
496 | ||
497 | after(async () => { | |
498 | await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) | |
499 | ||
500 | await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
501 | await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | |
502 | }) | |
503 | }) | |
504 | ||
505 | after(async function () { | |
506 | MockSmtpServer.Instance.kill() | |
507 | ||
508 | await cleanupTests(servers) | |
509 | }) | |
510 | }) |