diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-09 14:27:32 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-09 14:27:32 +0100 |
commit | 9e847c17f968076287025c798b87506a8d50bb93 (patch) | |
tree | 6f1ccb14b80aef31761c1e651a21268f171b40e9 /server/tests/api/notifications/moderation-notifications.ts | |
parent | 650580504cf14a87bd4025eec9673eb5642dc71d (diff) | |
download | PeerTube-9e847c17f968076287025c798b87506a8d50bb93.tar.gz PeerTube-9e847c17f968076287025c798b87506a8d50bb93.tar.zst PeerTube-9e847c17f968076287025c798b87506a8d50bb93.zip |
No notification on moderator abuse
Diffstat (limited to 'server/tests/api/notifications/moderation-notifications.ts')
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 84 |
1 files changed, 50 insertions, 34 deletions
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index f806fed31..81ce8061b 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -24,11 +24,13 @@ import { | |||
24 | wait, | 24 | wait, |
25 | waitJobs | 25 | waitJobs |
26 | } from '@shared/extra-utils' | 26 | } from '@shared/extra-utils' |
27 | import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' | 27 | import { AbuseState, CustomConfig, UserNotification, UserRole, VideoPrivacy } from '@shared/models' |
28 | 28 | ||
29 | describe('Test moderation notifications', function () { | 29 | describe('Test moderation notifications', function () { |
30 | let servers: PeerTubeServer[] = [] | 30 | let servers: PeerTubeServer[] = [] |
31 | let userAccessToken: string | 31 | let userToken1: string |
32 | let userToken2: string | ||
33 | |||
32 | let userNotifications: UserNotification[] = [] | 34 | let userNotifications: UserNotification[] = [] |
33 | let adminNotifications: UserNotification[] = [] | 35 | let adminNotifications: UserNotification[] = [] |
34 | let adminNotificationsServer2: UserNotification[] = [] | 36 | let adminNotificationsServer2: UserNotification[] = [] |
@@ -39,11 +41,13 @@ describe('Test moderation notifications', function () { | |||
39 | 41 | ||
40 | const res = await prepareNotificationsTest(3) | 42 | const res = await prepareNotificationsTest(3) |
41 | emails = res.emails | 43 | emails = res.emails |
42 | userAccessToken = res.userAccessToken | 44 | userToken1 = res.userAccessToken |
43 | servers = res.servers | 45 | servers = res.servers |
44 | userNotifications = res.userNotifications | 46 | userNotifications = res.userNotifications |
45 | adminNotifications = res.adminNotifications | 47 | adminNotifications = res.adminNotifications |
46 | adminNotificationsServer2 = res.adminNotificationsServer2 | 48 | adminNotificationsServer2 = res.adminNotificationsServer2 |
49 | |||
50 | userToken2 = await servers[1].users.generateUserAndToken('user2', UserRole.USER) | ||
47 | }) | 51 | }) |
48 | 52 | ||
49 | describe('Abuse for moderators notification', function () { | 53 | describe('Abuse for moderators notification', function () { |
@@ -58,15 +62,27 @@ describe('Test moderation notifications', function () { | |||
58 | } | 62 | } |
59 | }) | 63 | }) |
60 | 64 | ||
61 | it('Should send a notification to moderators on local video abuse', async function () { | 65 | it('Should not send a notification to moderators on local abuse reported by an admin', async function () { |
62 | this.timeout(20000) | 66 | this.timeout(20000) |
63 | 67 | ||
64 | const name = 'video for abuse ' + buildUUID() | 68 | const name = 'video for abuse ' + buildUUID() |
65 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 69 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
66 | 70 | ||
67 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) | 71 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) |
68 | 72 | ||
69 | await waitJobs(servers) | 73 | await waitJobs(servers) |
74 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'absence' }) | ||
75 | }) | ||
76 | |||
77 | it('Should send a notification to moderators on local video abuse', async function () { | ||
78 | this.timeout(20000) | ||
79 | |||
80 | const name = 'video for abuse ' + buildUUID() | ||
81 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | ||
82 | |||
83 | await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) | ||
84 | |||
85 | await waitJobs(servers) | ||
70 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 86 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
71 | }) | 87 | }) |
72 | 88 | ||
@@ -74,12 +90,12 @@ describe('Test moderation notifications', function () { | |||
74 | this.timeout(20000) | 90 | this.timeout(20000) |
75 | 91 | ||
76 | const name = 'video for abuse ' + buildUUID() | 92 | const name = 'video for abuse ' + buildUUID() |
77 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 93 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
78 | 94 | ||
79 | await waitJobs(servers) | 95 | await waitJobs(servers) |
80 | 96 | ||
81 | const videoId = await servers[1].videos.getId({ uuid: video.uuid }) | 97 | const videoId = await servers[1].videos.getId({ uuid: video.uuid }) |
82 | await servers[1].abuses.report({ videoId, reason: 'super reason' }) | 98 | await servers[1].abuses.report({ token: userToken2, videoId, reason: 'super reason' }) |
83 | 99 | ||
84 | await waitJobs(servers) | 100 | await waitJobs(servers) |
85 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 101 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
@@ -89,16 +105,16 @@ describe('Test moderation notifications', function () { | |||
89 | this.timeout(20000) | 105 | this.timeout(20000) |
90 | 106 | ||
91 | const name = 'video for abuse ' + buildUUID() | 107 | const name = 'video for abuse ' + buildUUID() |
92 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 108 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
93 | const comment = await servers[0].comments.createThread({ | 109 | const comment = await servers[0].comments.createThread({ |
94 | token: userAccessToken, | 110 | token: userToken1, |
95 | videoId: video.id, | 111 | videoId: video.id, |
96 | text: 'comment abuse ' + buildUUID() | 112 | text: 'comment abuse ' + buildUUID() |
97 | }) | 113 | }) |
98 | 114 | ||
99 | await waitJobs(servers) | 115 | await waitJobs(servers) |
100 | 116 | ||
101 | await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) | 117 | await servers[0].abuses.report({ token: userToken1, commentId: comment.id, reason: 'super reason' }) |
102 | 118 | ||
103 | await waitJobs(servers) | 119 | await waitJobs(servers) |
104 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 120 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
@@ -108,10 +124,10 @@ describe('Test moderation notifications', function () { | |||
108 | this.timeout(20000) | 124 | this.timeout(20000) |
109 | 125 | ||
110 | const name = 'video for abuse ' + buildUUID() | 126 | const name = 'video for abuse ' + buildUUID() |
111 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 127 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
112 | 128 | ||
113 | await servers[0].comments.createThread({ | 129 | await servers[0].comments.createThread({ |
114 | token: userAccessToken, | 130 | token: userToken1, |
115 | videoId: video.id, | 131 | videoId: video.id, |
116 | text: 'comment abuse ' + buildUUID() | 132 | text: 'comment abuse ' + buildUUID() |
117 | }) | 133 | }) |
@@ -120,7 +136,7 @@ describe('Test moderation notifications', function () { | |||
120 | 136 | ||
121 | const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) | 137 | const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) |
122 | const commentId = data[0].id | 138 | const commentId = data[0].id |
123 | await servers[1].abuses.report({ commentId, reason: 'super reason' }) | 139 | await servers[1].abuses.report({ token: userToken2, commentId, reason: 'super reason' }) |
124 | 140 | ||
125 | await waitJobs(servers) | 141 | await waitJobs(servers) |
126 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 142 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
@@ -133,7 +149,7 @@ describe('Test moderation notifications', function () { | |||
133 | const { account } = await servers[0].users.create({ username, password: 'donald' }) | 149 | const { account } = await servers[0].users.create({ username, password: 'donald' }) |
134 | const accountId = account.id | 150 | const accountId = account.id |
135 | 151 | ||
136 | await servers[0].abuses.report({ accountId, reason: 'super reason' }) | 152 | await servers[0].abuses.report({ token: userToken1, accountId, reason: 'super reason' }) |
137 | 153 | ||
138 | await waitJobs(servers) | 154 | await waitJobs(servers) |
139 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) | 155 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
@@ -149,7 +165,7 @@ describe('Test moderation notifications', function () { | |||
149 | await waitJobs(servers) | 165 | await waitJobs(servers) |
150 | 166 | ||
151 | const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) | 167 | const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) |
152 | await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) | 168 | await servers[1].abuses.report({ token: userToken2, accountId: account.id, reason: 'super reason' }) |
153 | 169 | ||
154 | await waitJobs(servers) | 170 | await waitJobs(servers) |
155 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) | 171 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
@@ -165,13 +181,13 @@ describe('Test moderation notifications', function () { | |||
165 | server: servers[0], | 181 | server: servers[0], |
166 | emails, | 182 | emails, |
167 | socketNotifications: userNotifications, | 183 | socketNotifications: userNotifications, |
168 | token: userAccessToken | 184 | token: userToken1 |
169 | } | 185 | } |
170 | 186 | ||
171 | const name = 'abuse ' + buildUUID() | 187 | const name = 'abuse ' + buildUUID() |
172 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 188 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
173 | 189 | ||
174 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 190 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) |
175 | abuseId = body.abuse.id | 191 | abuseId = body.abuse.id |
176 | }) | 192 | }) |
177 | 193 | ||
@@ -205,7 +221,7 @@ describe('Test moderation notifications', function () { | |||
205 | server: servers[0], | 221 | server: servers[0], |
206 | emails, | 222 | emails, |
207 | socketNotifications: userNotifications, | 223 | socketNotifications: userNotifications, |
208 | token: userAccessToken | 224 | token: userToken1 |
209 | } | 225 | } |
210 | 226 | ||
211 | baseParamsAdmin = { | 227 | baseParamsAdmin = { |
@@ -216,15 +232,15 @@ describe('Test moderation notifications', function () { | |||
216 | } | 232 | } |
217 | 233 | ||
218 | const name = 'abuse ' + buildUUID() | 234 | const name = 'abuse ' + buildUUID() |
219 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 235 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
220 | 236 | ||
221 | { | 237 | { |
222 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 238 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) |
223 | abuseId = body.abuse.id | 239 | abuseId = body.abuse.id |
224 | } | 240 | } |
225 | 241 | ||
226 | { | 242 | { |
227 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) | 243 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason 2' }) |
228 | abuseId2 = body.abuse.id | 244 | abuseId2 = body.abuse.id |
229 | } | 245 | } |
230 | }) | 246 | }) |
@@ -254,7 +270,7 @@ describe('Test moderation notifications', function () { | |||
254 | this.timeout(10000) | 270 | this.timeout(10000) |
255 | 271 | ||
256 | const message = 'my super message to moderators' | 272 | const message = 'my super message to moderators' |
257 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) | 273 | await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message }) |
258 | await waitJobs(servers) | 274 | await waitJobs(servers) |
259 | 275 | ||
260 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' | 276 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
@@ -265,7 +281,7 @@ describe('Test moderation notifications', function () { | |||
265 | this.timeout(10000) | 281 | this.timeout(10000) |
266 | 282 | ||
267 | const message = 'my super message that should not be sent to reporter' | 283 | const message = 'my super message that should not be sent to reporter' |
268 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) | 284 | await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message }) |
269 | await waitJobs(servers) | 285 | await waitJobs(servers) |
270 | 286 | ||
271 | const toEmail = 'user_1@example.com' | 287 | const toEmail = 'user_1@example.com' |
@@ -281,7 +297,7 @@ describe('Test moderation notifications', function () { | |||
281 | server: servers[0], | 297 | server: servers[0], |
282 | emails, | 298 | emails, |
283 | socketNotifications: userNotifications, | 299 | socketNotifications: userNotifications, |
284 | token: userAccessToken | 300 | token: userToken1 |
285 | } | 301 | } |
286 | }) | 302 | }) |
287 | 303 | ||
@@ -289,7 +305,7 @@ describe('Test moderation notifications', function () { | |||
289 | this.timeout(10000) | 305 | this.timeout(10000) |
290 | 306 | ||
291 | const name = 'video for abuse ' + buildUUID() | 307 | const name = 'video for abuse ' + buildUUID() |
292 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 308 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
293 | 309 | ||
294 | await servers[0].blacklist.add({ videoId: uuid }) | 310 | await servers[0].blacklist.add({ videoId: uuid }) |
295 | 311 | ||
@@ -301,7 +317,7 @@ describe('Test moderation notifications', function () { | |||
301 | this.timeout(10000) | 317 | this.timeout(10000) |
302 | 318 | ||
303 | const name = 'video for abuse ' + buildUUID() | 319 | const name = 'video for abuse ' + buildUUID() |
304 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 320 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
305 | 321 | ||
306 | await servers[0].blacklist.add({ videoId: uuid }) | 322 | await servers[0].blacklist.add({ videoId: uuid }) |
307 | 323 | ||
@@ -335,7 +351,7 @@ describe('Test moderation notifications', function () { | |||
335 | 351 | ||
336 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) | 352 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) |
337 | 353 | ||
338 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 354 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
339 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) | 355 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) |
340 | }) | 356 | }) |
341 | }) | 357 | }) |
@@ -377,7 +393,7 @@ describe('Test moderation notifications', function () { | |||
377 | 393 | ||
378 | await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) | 394 | await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) |
379 | 395 | ||
380 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 396 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
381 | await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) | 397 | await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) |
382 | }) | 398 | }) |
383 | 399 | ||
@@ -404,7 +420,7 @@ describe('Test moderation notifications', function () { | |||
404 | const followingHost = servers[2].host | 420 | const followingHost = servers[2].host |
405 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) | 421 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
406 | 422 | ||
407 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 423 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
408 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) | 424 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) |
409 | 425 | ||
410 | config.followings.instance.autoFollowBack.enabled = false | 426 | config.followings.instance.autoFollowBack.enabled = false |
@@ -461,7 +477,7 @@ describe('Test moderation notifications', function () { | |||
461 | server: servers[0], | 477 | server: servers[0], |
462 | emails, | 478 | emails, |
463 | socketNotifications: userNotifications, | 479 | socketNotifications: userNotifications, |
464 | token: userAccessToken | 480 | token: userToken1 |
465 | } | 481 | } |
466 | 482 | ||
467 | currentCustomConfig = await servers[0].config.getCustomConfig() | 483 | currentCustomConfig = await servers[0].config.getCustomConfig() |
@@ -490,7 +506,7 @@ describe('Test moderation notifications', function () { | |||
490 | this.timeout(120000) | 506 | this.timeout(120000) |
491 | 507 | ||
492 | videoName = 'video with auto-blacklist ' + buildUUID() | 508 | videoName = 'video with auto-blacklist ' + buildUUID() |
493 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) | 509 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name: videoName } }) |
494 | shortUUID = video.shortUUID | 510 | shortUUID = video.shortUUID |
495 | uuid = video.uuid | 511 | uuid = video.uuid |
496 | 512 | ||
@@ -547,7 +563,7 @@ describe('Test moderation notifications', function () { | |||
547 | } | 563 | } |
548 | } | 564 | } |
549 | 565 | ||
550 | const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) | 566 | const { shortUUID, uuid } = await servers[0].videos.upload({ token: userToken1, attributes }) |
551 | 567 | ||
552 | await servers[0].blacklist.remove({ videoId: uuid }) | 568 | await servers[0].blacklist.remove({ videoId: uuid }) |
553 | 569 | ||
@@ -579,7 +595,7 @@ describe('Test moderation notifications', function () { | |||
579 | } | 595 | } |
580 | } | 596 | } |
581 | 597 | ||
582 | const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes }) | 598 | const { shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes }) |
583 | 599 | ||
584 | await wait(6000) | 600 | await wait(6000) |
585 | await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) | 601 | await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) |