]>
Commit | Line | Data |
---|---|---|
8eb07b01 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
8eb07b01 | 3 | import { |
0c1a77e9 C |
4 | checkAbuseStateChange, |
5 | checkAutoInstanceFollowing, | |
6 | CheckerBaseParams, | |
7 | checkNewAbuseMessage, | |
8 | checkNewAccountAbuseForModerators, | |
9 | checkNewBlacklistOnMyVideo, | |
10 | checkNewCommentAbuseForModerators, | |
11 | checkNewInstanceFollower, | |
12 | checkNewVideoAbuseForModerators, | |
13 | checkNewVideoFromSubscription, | |
14 | checkUserRegistered, | |
15 | checkVideoAutoBlacklistForModerators, | |
16 | checkVideoIsPublished, | |
8eb07b01 | 17 | MockInstancesIndex, |
0c1a77e9 | 18 | MockSmtpServer, |
c55e3d72 C |
19 | prepareNotificationsTest |
20 | } from '@server/tests/shared' | |
0628157f C |
21 | import { wait } from '@shared/core-utils' |
22 | import { buildUUID } from '@shared/extra-utils' | |
9e847c17 | 23 | import { AbuseState, CustomConfig, UserNotification, UserRole, VideoPrivacy } from '@shared/models' |
c55e3d72 | 24 | import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' |
8eb07b01 C |
25 | |
26 | describe('Test moderation notifications', function () { | |
254d3579 | 27 | let servers: PeerTubeServer[] = [] |
9e847c17 C |
28 | let userToken1: string |
29 | let userToken2: string | |
30 | ||
8eb07b01 C |
31 | let userNotifications: UserNotification[] = [] |
32 | let adminNotifications: UserNotification[] = [] | |
33 | let adminNotificationsServer2: UserNotification[] = [] | |
34 | let emails: object[] = [] | |
35 | ||
36 | before(async function () { | |
37 | this.timeout(120000) | |
38 | ||
39 | const res = await prepareNotificationsTest(3) | |
40 | emails = res.emails | |
9e847c17 | 41 | userToken1 = res.userAccessToken |
8eb07b01 C |
42 | servers = res.servers |
43 | userNotifications = res.userNotifications | |
44 | adminNotifications = res.adminNotifications | |
45 | adminNotificationsServer2 = res.adminNotificationsServer2 | |
9e847c17 C |
46 | |
47 | userToken2 = await servers[1].users.generateUserAndToken('user2', UserRole.USER) | |
8eb07b01 C |
48 | }) |
49 | ||
594d3e48 | 50 | describe('Abuse for moderators notification', function () { |
8eb07b01 C |
51 | let baseParams: CheckerBaseParams |
52 | ||
53 | before(() => { | |
54 | baseParams = { | |
55 | server: servers[0], | |
56 | emails, | |
57 | socketNotifications: adminNotifications, | |
58 | token: servers[0].accessToken | |
59 | } | |
60 | }) | |
61 | ||
9e847c17 | 62 | it('Should not send a notification to moderators on local abuse reported by an admin', async function () { |
20516920 | 63 | this.timeout(20000) |
8eb07b01 | 64 | |
d4a8e7a6 | 65 | const name = 'video for abuse ' + buildUUID() |
9e847c17 | 66 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
8eb07b01 | 67 | |
89d241a7 | 68 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) |
8eb07b01 | 69 | |
9e847c17 C |
70 | await waitJobs(servers) |
71 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'absence' }) | |
72 | }) | |
73 | ||
74 | it('Should send a notification to moderators on local video abuse', async function () { | |
75 | this.timeout(20000) | |
76 | ||
77 | const name = 'video for abuse ' + buildUUID() | |
78 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | |
79 | ||
80 | await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) | |
81 | ||
8eb07b01 | 82 | await waitJobs(servers) |
29837f88 | 83 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
8eb07b01 C |
84 | }) |
85 | ||
86 | it('Should send a notification to moderators on remote video abuse', async function () { | |
20516920 | 87 | this.timeout(20000) |
8eb07b01 | 88 | |
d4a8e7a6 | 89 | const name = 'video for abuse ' + buildUUID() |
9e847c17 | 90 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
8eb07b01 C |
91 | |
92 | await waitJobs(servers) | |
93 | ||
89d241a7 | 94 | const videoId = await servers[1].videos.getId({ uuid: video.uuid }) |
9e847c17 | 95 | await servers[1].abuses.report({ token: userToken2, videoId, reason: 'super reason' }) |
8eb07b01 C |
96 | |
97 | await waitJobs(servers) | |
29837f88 | 98 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
8eb07b01 | 99 | }) |
310b5219 C |
100 | |
101 | it('Should send a notification to moderators on local comment abuse', async function () { | |
20516920 | 102 | this.timeout(20000) |
310b5219 | 103 | |
d4a8e7a6 | 104 | const name = 'video for abuse ' + buildUUID() |
9e847c17 | 105 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
89d241a7 | 106 | const comment = await servers[0].comments.createThread({ |
9e847c17 | 107 | token: userToken1, |
12edc149 C |
108 | videoId: video.id, |
109 | text: 'comment abuse ' + buildUUID() | |
110 | }) | |
310b5219 | 111 | |
15bedeeb C |
112 | await waitJobs(servers) |
113 | ||
9e847c17 | 114 | await servers[0].abuses.report({ token: userToken1, commentId: comment.id, reason: 'super reason' }) |
310b5219 C |
115 | |
116 | await waitJobs(servers) | |
29837f88 | 117 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
310b5219 C |
118 | }) |
119 | ||
120 | it('Should send a notification to moderators on remote comment abuse', async function () { | |
20516920 | 121 | this.timeout(20000) |
310b5219 | 122 | |
d4a8e7a6 | 123 | const name = 'video for abuse ' + buildUUID() |
9e847c17 | 124 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
12edc149 | 125 | |
89d241a7 | 126 | await servers[0].comments.createThread({ |
9e847c17 | 127 | token: userToken1, |
12edc149 C |
128 | videoId: video.id, |
129 | text: 'comment abuse ' + buildUUID() | |
130 | }) | |
310b5219 C |
131 | |
132 | await waitJobs(servers) | |
133 | ||
89d241a7 | 134 | const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) |
12edc149 | 135 | const commentId = data[0].id |
9e847c17 | 136 | await servers[1].abuses.report({ token: userToken2, commentId, reason: 'super reason' }) |
310b5219 C |
137 | |
138 | await waitJobs(servers) | |
29837f88 | 139 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
310b5219 C |
140 | }) |
141 | ||
142 | it('Should send a notification to moderators on local account abuse', async function () { | |
20516920 | 143 | this.timeout(20000) |
310b5219 C |
144 | |
145 | const username = 'user' + new Date().getTime() | |
89d241a7 | 146 | const { account } = await servers[0].users.create({ username, password: 'donald' }) |
7926c5f9 | 147 | const accountId = account.id |
310b5219 | 148 | |
9e847c17 | 149 | await servers[0].abuses.report({ token: userToken1, accountId, reason: 'super reason' }) |
310b5219 C |
150 | |
151 | await waitJobs(servers) | |
29837f88 | 152 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
310b5219 C |
153 | }) |
154 | ||
155 | it('Should send a notification to moderators on remote account abuse', async function () { | |
20516920 | 156 | this.timeout(20000) |
310b5219 C |
157 | |
158 | const username = 'user' + new Date().getTime() | |
89d241a7 C |
159 | const tmpToken = await servers[0].users.generateUserAndToken(username) |
160 | await servers[0].videos.upload({ token: tmpToken, attributes: { name: 'super video' } }) | |
310b5219 C |
161 | |
162 | await waitJobs(servers) | |
163 | ||
89d241a7 | 164 | const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) |
9e847c17 | 165 | await servers[1].abuses.report({ token: userToken2, accountId: account.id, reason: 'super reason' }) |
310b5219 C |
166 | |
167 | await waitJobs(servers) | |
29837f88 | 168 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
310b5219 | 169 | }) |
8eb07b01 C |
170 | }) |
171 | ||
594d3e48 C |
172 | describe('Abuse state change notification', function () { |
173 | let baseParams: CheckerBaseParams | |
174 | let abuseId: number | |
175 | ||
176 | before(async function () { | |
177 | baseParams = { | |
178 | server: servers[0], | |
179 | emails, | |
180 | socketNotifications: userNotifications, | |
9e847c17 | 181 | token: userToken1 |
594d3e48 C |
182 | } |
183 | ||
d4a8e7a6 | 184 | const name = 'abuse ' + buildUUID() |
9e847c17 | 185 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
594d3e48 | 186 | |
9e847c17 | 187 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) |
0c1a77e9 | 188 | abuseId = body.abuse.id |
594d3e48 C |
189 | }) |
190 | ||
191 | it('Should send a notification to reporter if the abuse has been accepted', async function () { | |
192 | this.timeout(10000) | |
193 | ||
89d241a7 | 194 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
594d3e48 C |
195 | await waitJobs(servers) |
196 | ||
29837f88 | 197 | await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.ACCEPTED, checkType: 'presence' }) |
594d3e48 C |
198 | }) |
199 | ||
200 | it('Should send a notification to reporter if the abuse has been rejected', async function () { | |
201 | this.timeout(10000) | |
202 | ||
89d241a7 | 203 | await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } }) |
594d3e48 C |
204 | await waitJobs(servers) |
205 | ||
29837f88 | 206 | await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.REJECTED, checkType: 'presence' }) |
594d3e48 C |
207 | }) |
208 | }) | |
209 | ||
210 | describe('New abuse message notification', function () { | |
211 | let baseParamsUser: CheckerBaseParams | |
212 | let baseParamsAdmin: CheckerBaseParams | |
213 | let abuseId: number | |
214 | let abuseId2: number | |
215 | ||
216 | before(async function () { | |
217 | baseParamsUser = { | |
218 | server: servers[0], | |
219 | emails, | |
220 | socketNotifications: userNotifications, | |
9e847c17 | 221 | token: userToken1 |
594d3e48 C |
222 | } |
223 | ||
224 | baseParamsAdmin = { | |
225 | server: servers[0], | |
226 | emails, | |
227 | socketNotifications: adminNotifications, | |
228 | token: servers[0].accessToken | |
229 | } | |
230 | ||
d4a8e7a6 | 231 | const name = 'abuse ' + buildUUID() |
9e847c17 | 232 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
594d3e48 C |
233 | |
234 | { | |
9e847c17 | 235 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) |
0c1a77e9 | 236 | abuseId = body.abuse.id |
594d3e48 C |
237 | } |
238 | ||
239 | { | |
9e847c17 | 240 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason 2' }) |
0c1a77e9 | 241 | abuseId2 = body.abuse.id |
594d3e48 C |
242 | } |
243 | }) | |
244 | ||
245 | it('Should send a notification to reporter on new message', async function () { | |
246 | this.timeout(10000) | |
247 | ||
248 | const message = 'my super message to users' | |
89d241a7 | 249 | await servers[0].abuses.addMessage({ abuseId, message }) |
594d3e48 C |
250 | await waitJobs(servers) |
251 | ||
29837f88 | 252 | await checkNewAbuseMessage({ ...baseParamsUser, abuseId, message, toEmail: 'user_1@example.com', checkType: 'presence' }) |
594d3e48 C |
253 | }) |
254 | ||
255 | it('Should not send a notification to the admin if sent by the admin', async function () { | |
256 | this.timeout(10000) | |
257 | ||
258 | const message = 'my super message that should not be sent to the admin' | |
89d241a7 | 259 | await servers[0].abuses.addMessage({ abuseId, message }) |
594d3e48 C |
260 | await waitJobs(servers) |
261 | ||
29837f88 C |
262 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
263 | await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId, message, toEmail, checkType: 'absence' }) | |
594d3e48 C |
264 | }) |
265 | ||
266 | it('Should send a notification to moderators', async function () { | |
267 | this.timeout(10000) | |
268 | ||
269 | const message = 'my super message to moderators' | |
9e847c17 | 270 | await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message }) |
594d3e48 C |
271 | await waitJobs(servers) |
272 | ||
29837f88 C |
273 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
274 | await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId: abuseId2, message, toEmail, checkType: 'presence' }) | |
594d3e48 C |
275 | }) |
276 | ||
277 | it('Should not send a notification to reporter if sent by the reporter', async function () { | |
278 | this.timeout(10000) | |
279 | ||
280 | const message = 'my super message that should not be sent to reporter' | |
9e847c17 | 281 | await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message }) |
594d3e48 C |
282 | await waitJobs(servers) |
283 | ||
29837f88 C |
284 | const toEmail = 'user_1@example.com' |
285 | await checkNewAbuseMessage({ ...baseParamsUser, abuseId: abuseId2, message, toEmail, checkType: 'absence' }) | |
594d3e48 C |
286 | }) |
287 | }) | |
288 | ||
8eb07b01 C |
289 | describe('Video blacklist on my video', function () { |
290 | let baseParams: CheckerBaseParams | |
291 | ||
292 | before(() => { | |
293 | baseParams = { | |
294 | server: servers[0], | |
295 | emails, | |
296 | socketNotifications: userNotifications, | |
9e847c17 | 297 | token: userToken1 |
8eb07b01 C |
298 | } |
299 | }) | |
300 | ||
301 | it('Should send a notification to video owner on blacklist', async function () { | |
302 | this.timeout(10000) | |
303 | ||
d4a8e7a6 | 304 | const name = 'video for abuse ' + buildUUID() |
9e847c17 | 305 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
8eb07b01 | 306 | |
89d241a7 | 307 | await servers[0].blacklist.add({ videoId: uuid }) |
8eb07b01 C |
308 | |
309 | await waitJobs(servers) | |
29837f88 | 310 | await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'blacklist' }) |
8eb07b01 C |
311 | }) |
312 | ||
313 | it('Should send a notification to video owner on unblacklist', async function () { | |
314 | this.timeout(10000) | |
315 | ||
d4a8e7a6 | 316 | const name = 'video for abuse ' + buildUUID() |
9e847c17 | 317 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
8eb07b01 | 318 | |
89d241a7 | 319 | await servers[0].blacklist.add({ videoId: uuid }) |
8eb07b01 C |
320 | |
321 | await waitJobs(servers) | |
89d241a7 | 322 | await servers[0].blacklist.remove({ videoId: uuid }) |
8eb07b01 C |
323 | await waitJobs(servers) |
324 | ||
325 | await wait(500) | |
29837f88 | 326 | await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) |
8eb07b01 C |
327 | }) |
328 | }) | |
329 | ||
330 | describe('New registration', function () { | |
331 | let baseParams: CheckerBaseParams | |
332 | ||
333 | before(() => { | |
334 | baseParams = { | |
335 | server: servers[0], | |
336 | emails, | |
337 | socketNotifications: adminNotifications, | |
338 | token: servers[0].accessToken | |
339 | } | |
340 | }) | |
341 | ||
342 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | |
343 | this.timeout(10000) | |
344 | ||
89d241a7 | 345 | await servers[0].users.register({ username: 'user_45' }) |
8eb07b01 C |
346 | |
347 | await waitJobs(servers) | |
348 | ||
29837f88 | 349 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) |
8eb07b01 | 350 | |
9e847c17 | 351 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
29837f88 | 352 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) |
8eb07b01 C |
353 | }) |
354 | }) | |
355 | ||
356 | describe('New instance follows', function () { | |
357 | const instanceIndexServer = new MockInstancesIndex() | |
f6500729 | 358 | let config: any |
8eb07b01 C |
359 | let baseParams: CheckerBaseParams |
360 | ||
361 | before(async () => { | |
362 | baseParams = { | |
363 | server: servers[0], | |
364 | emails, | |
365 | socketNotifications: adminNotifications, | |
366 | token: servers[0].accessToken | |
367 | } | |
368 | ||
f6500729 | 369 | const port = await instanceIndexServer.initialize() |
8eb07b01 | 370 | instanceIndexServer.addInstance(servers[1].host) |
f6500729 C |
371 | |
372 | config = { | |
373 | followings: { | |
374 | instance: { | |
375 | autoFollowIndex: { | |
376 | indexUrl: `http://localhost:${port}/api/v1/instances/hosts`, | |
377 | enabled: true | |
378 | } | |
379 | } | |
380 | } | |
381 | } | |
8eb07b01 C |
382 | }) |
383 | ||
384 | it('Should send a notification only to admin when there is a new instance follower', async function () { | |
3097acc7 | 385 | this.timeout(60000) |
8eb07b01 | 386 | |
4d029ef8 | 387 | await servers[2].follows.follow({ hosts: [ servers[0].url ] }) |
8eb07b01 C |
388 | |
389 | await waitJobs(servers) | |
390 | ||
29837f88 | 391 | await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) |
8eb07b01 | 392 | |
9e847c17 | 393 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
29837f88 | 394 | await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) |
8eb07b01 C |
395 | }) |
396 | ||
397 | it('Should send a notification on auto follow back', async function () { | |
398 | this.timeout(40000) | |
399 | ||
89d241a7 | 400 | await servers[2].follows.unfollow({ target: servers[0] }) |
8eb07b01 C |
401 | await waitJobs(servers) |
402 | ||
403 | const config = { | |
404 | followings: { | |
405 | instance: { | |
406 | autoFollowBack: { enabled: true } | |
407 | } | |
408 | } | |
409 | } | |
89d241a7 | 410 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
8eb07b01 | 411 | |
4d029ef8 | 412 | await servers[2].follows.follow({ hosts: [ servers[0].url ] }) |
8eb07b01 C |
413 | |
414 | await waitJobs(servers) | |
415 | ||
416 | const followerHost = servers[0].host | |
417 | const followingHost = servers[2].host | |
29837f88 | 418 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
8eb07b01 | 419 | |
9e847c17 | 420 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
29837f88 | 421 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) |
8eb07b01 C |
422 | |
423 | config.followings.instance.autoFollowBack.enabled = false | |
89d241a7 C |
424 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
425 | await servers[0].follows.unfollow({ target: servers[2] }) | |
426 | await servers[2].follows.unfollow({ target: servers[0] }) | |
8eb07b01 C |
427 | }) |
428 | ||
429 | it('Should send a notification on auto instances index follow', async function () { | |
430 | this.timeout(30000) | |
89d241a7 | 431 | await servers[0].follows.unfollow({ target: servers[1] }) |
8eb07b01 | 432 | |
89d241a7 | 433 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
8eb07b01 C |
434 | |
435 | await wait(5000) | |
436 | await waitJobs(servers) | |
437 | ||
438 | const followerHost = servers[0].host | |
439 | const followingHost = servers[1].host | |
29837f88 | 440 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
8eb07b01 C |
441 | |
442 | config.followings.instance.autoFollowIndex.enabled = false | |
89d241a7 C |
443 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
444 | await servers[0].follows.unfollow({ target: servers[1] }) | |
8eb07b01 C |
445 | }) |
446 | }) | |
447 | ||
448 | describe('Video-related notifications when video auto-blacklist is enabled', function () { | |
449 | let userBaseParams: CheckerBaseParams | |
450 | let adminBaseParamsServer1: CheckerBaseParams | |
451 | let adminBaseParamsServer2: CheckerBaseParams | |
29837f88 C |
452 | let uuid: string |
453 | let shortUUID: string | |
8eb07b01 C |
454 | let videoName: string |
455 | let currentCustomConfig: CustomConfig | |
456 | ||
457 | before(async () => { | |
458 | ||
459 | adminBaseParamsServer1 = { | |
460 | server: servers[0], | |
461 | emails, | |
462 | socketNotifications: adminNotifications, | |
463 | token: servers[0].accessToken | |
464 | } | |
465 | ||
466 | adminBaseParamsServer2 = { | |
467 | server: servers[1], | |
468 | emails, | |
469 | socketNotifications: adminNotificationsServer2, | |
470 | token: servers[1].accessToken | |
471 | } | |
472 | ||
473 | userBaseParams = { | |
474 | server: servers[0], | |
475 | emails, | |
476 | socketNotifications: userNotifications, | |
9e847c17 | 477 | token: userToken1 |
8eb07b01 C |
478 | } |
479 | ||
89d241a7 | 480 | currentCustomConfig = await servers[0].config.getCustomConfig() |
65e6e260 | 481 | |
6c5065a0 C |
482 | const autoBlacklistTestsCustomConfig = { |
483 | ...currentCustomConfig, | |
484 | ||
8eb07b01 C |
485 | autoBlacklist: { |
486 | videos: { | |
487 | ofUsers: { | |
488 | enabled: true | |
489 | } | |
490 | } | |
491 | } | |
6c5065a0 | 492 | } |
65e6e260 | 493 | |
8eb07b01 C |
494 | // enable transcoding otherwise own publish notification after transcoding not expected |
495 | autoBlacklistTestsCustomConfig.transcoding.enabled = true | |
89d241a7 | 496 | await servers[0].config.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) |
8eb07b01 | 497 | |
89d241a7 C |
498 | await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
499 | await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | |
8eb07b01 C |
500 | }) |
501 | ||
502 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | |
27c3c945 | 503 | this.timeout(120000) |
8eb07b01 | 504 | |
d4a8e7a6 | 505 | videoName = 'video with auto-blacklist ' + buildUUID() |
9e847c17 | 506 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name: videoName } }) |
29837f88 C |
507 | shortUUID = video.shortUUID |
508 | uuid = video.uuid | |
8eb07b01 C |
509 | |
510 | await waitJobs(servers) | |
29837f88 | 511 | await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName, checkType: 'presence' }) |
8eb07b01 C |
512 | }) |
513 | ||
514 | it('Should not send video publish notification if auto-blacklisted', async function () { | |
29837f88 | 515 | await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' }) |
8eb07b01 C |
516 | }) |
517 | ||
518 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | |
29837f88 | 519 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' }) |
8eb07b01 C |
520 | }) |
521 | ||
522 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | |
29837f88 | 523 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'absence' }) |
8eb07b01 C |
524 | }) |
525 | ||
526 | it('Should send video published and unblacklist after video unblacklisted', async function () { | |
34caef7f | 527 | this.timeout(40000) |
8eb07b01 | 528 | |
29837f88 | 529 | await servers[0].blacklist.remove({ videoId: uuid }) |
8eb07b01 C |
530 | |
531 | await waitJobs(servers) | |
532 | ||
533 | // FIXME: Can't test as two notifications sent to same user and util only checks last one | |
534 | // One notification might be better anyways | |
535 | // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist') | |
536 | // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence') | |
537 | }) | |
538 | ||
539 | it('Should send a local user subscription notification after removed from blacklist', async function () { | |
29837f88 | 540 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' }) |
8eb07b01 C |
541 | }) |
542 | ||
543 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | |
29837f88 | 544 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' }) |
8eb07b01 C |
545 | }) |
546 | ||
547 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | |
59fd824c | 548 | this.timeout(40000) |
8eb07b01 C |
549 | |
550 | const updateAt = new Date(new Date().getTime() + 1000000) | |
551 | ||
d4a8e7a6 | 552 | const name = 'video with auto-blacklist and future schedule ' + buildUUID() |
8eb07b01 | 553 | |
d23dd9fb | 554 | const attributes = { |
8eb07b01 C |
555 | name, |
556 | privacy: VideoPrivacy.PRIVATE, | |
557 | scheduleUpdate: { | |
558 | updateAt: updateAt.toISOString(), | |
d23dd9fb | 559 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
8eb07b01 C |
560 | } |
561 | } | |
562 | ||
9e847c17 | 563 | const { shortUUID, uuid } = await servers[0].videos.upload({ token: userToken1, attributes }) |
8eb07b01 | 564 | |
89d241a7 | 565 | await servers[0].blacklist.remove({ videoId: uuid }) |
8eb07b01 C |
566 | |
567 | await waitJobs(servers) | |
29837f88 | 568 | await checkNewBlacklistOnMyVideo({ ...userBaseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' }) |
8eb07b01 C |
569 | |
570 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | |
571 | // One notification might be better anyways | |
572 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | |
573 | ||
29837f88 C |
574 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) |
575 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) | |
8eb07b01 C |
576 | }) |
577 | ||
578 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | |
59fd824c | 579 | this.timeout(40000) |
8eb07b01 C |
580 | |
581 | // In 2 seconds | |
582 | const updateAt = new Date(new Date().getTime() + 2000) | |
583 | ||
d4a8e7a6 | 584 | const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() |
8eb07b01 | 585 | |
d23dd9fb | 586 | const attributes = { |
8eb07b01 C |
587 | name, |
588 | privacy: VideoPrivacy.PRIVATE, | |
589 | scheduleUpdate: { | |
590 | updateAt: updateAt.toISOString(), | |
d23dd9fb | 591 | privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC |
8eb07b01 C |
592 | } |
593 | } | |
594 | ||
9e847c17 | 595 | const { shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes }) |
8eb07b01 C |
596 | |
597 | await wait(6000) | |
29837f88 C |
598 | await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) |
599 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' }) | |
600 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' }) | |
8eb07b01 C |
601 | }) |
602 | ||
603 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | |
2b32c5b3 | 604 | this.timeout(120000) |
8eb07b01 | 605 | |
d4a8e7a6 | 606 | const name = 'video without auto-blacklist ' + buildUUID() |
8eb07b01 C |
607 | |
608 | // admin with blacklist right will not be auto-blacklisted | |
29837f88 | 609 | const { shortUUID } = await servers[0].videos.upload({ attributes: { name } }) |
8eb07b01 C |
610 | |
611 | await waitJobs(servers) | |
29837f88 | 612 | await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName: name, checkType: 'absence' }) |
8eb07b01 C |
613 | }) |
614 | ||
615 | after(async () => { | |
89d241a7 | 616 | await servers[0].config.updateCustomConfig({ newCustomConfig: currentCustomConfig }) |
8eb07b01 | 617 | |
89d241a7 C |
618 | await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
619 | await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) | |
8eb07b01 C |
620 | }) |
621 | }) | |
622 | ||
623 | after(async function () { | |
624 | MockSmtpServer.Instance.kill() | |
625 | ||
626 | await cleanupTests(servers) | |
627 | }) | |
628 | }) |