diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/abuses.ts | 4 | ||||
-rw-r--r-- | server/tests/api/moderation/abuses.ts | 931 | ||||
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 73 | ||||
-rw-r--r-- | server/tests/api/server/email.ts | 2 |
4 files changed, 736 insertions, 274 deletions
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index ba7c0833f..8964c0ab2 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts | |||
@@ -21,9 +21,7 @@ import { | |||
21 | checkBadStartPagination | 21 | checkBadStartPagination |
22 | } from '../../../../shared/extra-utils/requests/check-api-params' | 22 | } from '../../../../shared/extra-utils/requests/check-api-params' |
23 | 23 | ||
24 | // FIXME: deprecated in 2.3. Remove this controller | 24 | describe('Test abuses API validators', function () { |
25 | |||
26 | describe('Test video abuses API validators', function () { | ||
27 | const basePath = '/api/v1/abuses/' | 25 | const basePath = '/api/v1/abuses/' |
28 | 26 | ||
29 | let server: ServerInfo | 27 | let server: ServerInfo |
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 28c5a5531..f186f7ea0 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts | |||
@@ -2,21 +2,30 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { Abuse, AbusePredefinedReasonsString, AbuseState } from '@shared/models' | 5 | import { Abuse, AbuseFilter, AbusePredefinedReasonsString, AbuseState, VideoComment, Account } from '@shared/models' |
6 | import { | 6 | import { |
7 | addVideoCommentThread, | ||
7 | cleanupTests, | 8 | cleanupTests, |
8 | createUser, | 9 | createUser, |
9 | deleteVideoAbuse, | 10 | deleteAbuse, |
11 | deleteVideoComment, | ||
10 | flushAndRunMultipleServers, | 12 | flushAndRunMultipleServers, |
11 | getVideoAbusesList, | 13 | getAbusesList, |
14 | getVideoCommentThreads, | ||
15 | getVideoIdFromUUID, | ||
12 | getVideosList, | 16 | getVideosList, |
17 | immutableAssign, | ||
13 | removeVideo, | 18 | removeVideo, |
14 | reportVideoAbuse, | 19 | reportAbuse, |
15 | ServerInfo, | 20 | ServerInfo, |
16 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
17 | updateVideoAbuse, | 22 | updateAbuse, |
18 | uploadVideo, | 23 | uploadVideo, |
19 | userLogin | 24 | uploadVideoAndGetId, |
25 | userLogin, | ||
26 | getAccount, | ||
27 | removeUser, | ||
28 | generateUserAccessToken | ||
20 | } from '../../../../shared/extra-utils/index' | 29 | } from '../../../../shared/extra-utils/index' |
21 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | 30 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' |
22 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 31 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
@@ -31,6 +40,7 @@ const expect = chai.expect | |||
31 | 40 | ||
32 | describe('Test abuses', function () { | 41 | describe('Test abuses', function () { |
33 | let servers: ServerInfo[] = [] | 42 | let servers: ServerInfo[] = [] |
43 | let abuseServer1: Abuse | ||
34 | let abuseServer2: Abuse | 44 | let abuseServer2: Abuse |
35 | 45 | ||
36 | before(async function () { | 46 | before(async function () { |
@@ -44,338 +54,721 @@ describe('Test abuses', function () { | |||
44 | 54 | ||
45 | // Server 1 and server 2 follow each other | 55 | // Server 1 and server 2 follow each other |
46 | await doubleFollow(servers[0], servers[1]) | 56 | await doubleFollow(servers[0], servers[1]) |
57 | }) | ||
47 | 58 | ||
48 | // Upload some videos on each servers | 59 | describe('Video abuses', function () { |
49 | const video1Attributes = { | ||
50 | name: 'my super name for server 1', | ||
51 | description: 'my super description for server 1' | ||
52 | } | ||
53 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | ||
54 | 60 | ||
55 | const video2Attributes = { | 61 | before(async function () { |
56 | name: 'my super name for server 2', | 62 | this.timeout(50000) |
57 | description: 'my super description for server 2' | ||
58 | } | ||
59 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | ||
60 | 63 | ||
61 | // Wait videos propagation, server 2 has transcoding enabled | 64 | // Upload some videos on each servers |
62 | await waitJobs(servers) | 65 | const video1Attributes = { |
66 | name: 'my super name for server 1', | ||
67 | description: 'my super description for server 1' | ||
68 | } | ||
69 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | ||
63 | 70 | ||
64 | const res = await getVideosList(servers[0].url) | 71 | const video2Attributes = { |
65 | const videos = res.body.data | 72 | name: 'my super name for server 2', |
73 | description: 'my super description for server 2' | ||
74 | } | ||
75 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | ||
66 | 76 | ||
67 | expect(videos.length).to.equal(2) | 77 | // Wait videos propagation, server 2 has transcoding enabled |
78 | await waitJobs(servers) | ||
68 | 79 | ||
69 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') | 80 | const res = await getVideosList(servers[0].url) |
70 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') | 81 | const videos = res.body.data |
71 | }) | ||
72 | 82 | ||
73 | it('Should not have video abuses', async function () { | 83 | expect(videos.length).to.equal(2) |
74 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | ||
75 | 84 | ||
76 | expect(res.body.total).to.equal(0) | 85 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') |
77 | expect(res.body.data).to.be.an('array') | 86 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') |
78 | expect(res.body.data.length).to.equal(0) | 87 | }) |
79 | }) | ||
80 | 88 | ||
81 | it('Should report abuse on a local video', async function () { | 89 | it('Should not have abuses', async function () { |
82 | this.timeout(15000) | 90 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
83 | 91 | ||
84 | const reason = 'my super bad reason' | 92 | expect(res.body.total).to.equal(0) |
85 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) | 93 | expect(res.body.data).to.be.an('array') |
94 | expect(res.body.data.length).to.equal(0) | ||
95 | }) | ||
86 | 96 | ||
87 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 | 97 | it('Should report abuse on a local video', async function () { |
88 | await waitJobs(servers) | 98 | this.timeout(15000) |
89 | }) | ||
90 | 99 | ||
91 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { | 100 | const reason = 'my super bad reason' |
92 | const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 101 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason }) |
93 | |||
94 | expect(res1.body.total).to.equal(1) | ||
95 | expect(res1.body.data).to.be.an('array') | ||
96 | expect(res1.body.data.length).to.equal(1) | ||
97 | |||
98 | const abuse: Abuse = res1.body.data[0] | ||
99 | expect(abuse.reason).to.equal('my super bad reason') | ||
100 | expect(abuse.reporterAccount.name).to.equal('root') | ||
101 | expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) | ||
102 | expect(abuse.video.id).to.equal(servers[0].video.id) | ||
103 | expect(abuse.video.channel).to.exist | ||
104 | expect(abuse.count).to.equal(1) | ||
105 | expect(abuse.nth).to.equal(1) | ||
106 | expect(abuse.countReportsForReporter).to.equal(1) | ||
107 | expect(abuse.countReportsForReportee).to.equal(1) | ||
108 | |||
109 | const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | ||
110 | expect(res2.body.total).to.equal(0) | ||
111 | expect(res2.body.data).to.be.an('array') | ||
112 | expect(res2.body.data.length).to.equal(0) | ||
113 | }) | ||
114 | 102 | ||
115 | it('Should report abuse on a remote video', async function () { | 103 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 |
116 | this.timeout(10000) | 104 | await waitJobs(servers) |
105 | }) | ||
117 | 106 | ||
118 | const reason = 'my super bad reason 2' | 107 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { |
119 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) | 108 | const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
120 | 109 | ||
121 | // We wait requests propagation | 110 | expect(res1.body.total).to.equal(1) |
122 | await waitJobs(servers) | 111 | expect(res1.body.data).to.be.an('array') |
123 | }) | 112 | expect(res1.body.data.length).to.equal(1) |
124 | 113 | ||
125 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { | 114 | const abuse: Abuse = res1.body.data[0] |
126 | const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 115 | expect(abuse.reason).to.equal('my super bad reason') |
127 | expect(res1.body.total).to.equal(2) | ||
128 | expect(res1.body.data).to.be.an('array') | ||
129 | expect(res1.body.data.length).to.equal(2) | ||
130 | |||
131 | const abuse1: Abuse = res1.body.data[0] | ||
132 | expect(abuse1.reason).to.equal('my super bad reason') | ||
133 | expect(abuse1.reporterAccount.name).to.equal('root') | ||
134 | expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port) | ||
135 | expect(abuse1.video.id).to.equal(servers[0].video.id) | ||
136 | expect(abuse1.state.id).to.equal(AbuseState.PENDING) | ||
137 | expect(abuse1.state.label).to.equal('Pending') | ||
138 | expect(abuse1.moderationComment).to.be.null | ||
139 | expect(abuse1.count).to.equal(1) | ||
140 | expect(abuse1.nth).to.equal(1) | ||
141 | |||
142 | const abuse2: Abuse = res1.body.data[1] | ||
143 | expect(abuse2.reason).to.equal('my super bad reason 2') | ||
144 | expect(abuse2.reporterAccount.name).to.equal('root') | ||
145 | expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port) | ||
146 | expect(abuse2.video.id).to.equal(servers[1].video.id) | ||
147 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | ||
148 | expect(abuse2.state.label).to.equal('Pending') | ||
149 | expect(abuse2.moderationComment).to.be.null | ||
150 | |||
151 | const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | ||
152 | expect(res2.body.total).to.equal(1) | ||
153 | expect(res2.body.data).to.be.an('array') | ||
154 | expect(res2.body.data.length).to.equal(1) | ||
155 | |||
156 | abuseServer2 = res2.body.data[0] | ||
157 | expect(abuseServer2.reason).to.equal('my super bad reason 2') | ||
158 | expect(abuseServer2.reporterAccount.name).to.equal('root') | ||
159 | expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port) | ||
160 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | ||
161 | expect(abuseServer2.state.label).to.equal('Pending') | ||
162 | expect(abuseServer2.moderationComment).to.be.null | ||
163 | }) | ||
164 | 116 | ||
165 | it('Should update the state of a video abuse', async function () { | 117 | expect(abuse.reporterAccount.name).to.equal('root') |
166 | const body = { state: AbuseState.REJECTED } | 118 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) |
167 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) | ||
168 | 119 | ||
169 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | 120 | expect(abuse.video.id).to.equal(servers[0].video.id) |
170 | expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) | 121 | expect(abuse.video.channel).to.exist |
171 | }) | ||
172 | 122 | ||
173 | it('Should add a moderation comment', async function () { | 123 | expect(abuse.comment).to.be.null |
174 | const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } | ||
175 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) | ||
176 | 124 | ||
177 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | 125 | expect(abuse.flaggedAccount.name).to.equal('root') |
178 | expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) | 126 | expect(abuse.flaggedAccount.host).to.equal(servers[0].host) |
179 | expect(res.body.data[0].moderationComment).to.equal('It is valid') | 127 | |
180 | }) | 128 | expect(abuse.video.countReports).to.equal(1) |
129 | expect(abuse.video.nthReport).to.equal(1) | ||
130 | |||
131 | expect(abuse.countReportsForReporter).to.equal(1) | ||
132 | expect(abuse.countReportsForReportee).to.equal(1) | ||
181 | 133 | ||
182 | it('Should hide video abuses from blocked accounts', async function () { | 134 | const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
183 | this.timeout(10000) | 135 | expect(res2.body.total).to.equal(0) |
136 | expect(res2.body.data).to.be.an('array') | ||
137 | expect(res2.body.data.length).to.equal(0) | ||
138 | }) | ||
184 | 139 | ||
185 | { | 140 | it('Should report abuse on a remote video', async function () { |
186 | await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this') | 141 | this.timeout(10000) |
142 | |||
143 | const reason = 'my super bad reason 2' | ||
144 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[1].video.id, reason }) | ||
145 | |||
146 | // We wait requests propagation | ||
187 | await waitJobs(servers) | 147 | await waitJobs(servers) |
148 | }) | ||
188 | 149 | ||
189 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 150 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { |
190 | expect(res.body.total).to.equal(3) | 151 | const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
191 | } | ||
192 | 152 | ||
193 | const accountToBlock = 'root@localhost:' + servers[1].port | 153 | expect(res1.body.total).to.equal(2) |
154 | expect(res1.body.data.length).to.equal(2) | ||
194 | 155 | ||
195 | { | 156 | const abuse1: Abuse = res1.body.data[0] |
196 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) | 157 | expect(abuse1.reason).to.equal('my super bad reason') |
158 | expect(abuse1.reporterAccount.name).to.equal('root') | ||
159 | expect(abuse1.reporterAccount.host).to.equal(servers[0].host) | ||
197 | 160 | ||
198 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 161 | expect(abuse1.video.id).to.equal(servers[0].video.id) |
199 | expect(res.body.total).to.equal(2) | 162 | expect(abuse1.video.countReports).to.equal(1) |
163 | expect(abuse1.video.nthReport).to.equal(1) | ||
200 | 164 | ||
201 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | 165 | expect(abuse1.comment).to.be.null |
202 | expect(abuse).to.be.undefined | ||
203 | } | ||
204 | 166 | ||
205 | { | 167 | expect(abuse1.flaggedAccount.name).to.equal('root') |
206 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) | 168 | expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) |
207 | 169 | ||
208 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 170 | expect(abuse1.state.id).to.equal(AbuseState.PENDING) |
209 | expect(res.body.total).to.equal(3) | 171 | expect(abuse1.state.label).to.equal('Pending') |
210 | } | 172 | expect(abuse1.moderationComment).to.be.null |
211 | }) | ||
212 | 173 | ||
213 | it('Should hide video abuses from blocked servers', async function () { | 174 | const abuse2: Abuse = res1.body.data[1] |
214 | const serverToBlock = servers[1].host | 175 | expect(abuse2.reason).to.equal('my super bad reason 2') |
215 | 176 | ||
216 | { | 177 | expect(abuse2.reporterAccount.name).to.equal('root') |
217 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) | 178 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) |
218 | 179 | ||
219 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 180 | expect(abuse2.video.id).to.equal(servers[1].video.id) |
220 | expect(res.body.total).to.equal(2) | ||
221 | 181 | ||
222 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | 182 | expect(abuse2.comment).to.be.null |
223 | expect(abuse).to.be.undefined | ||
224 | } | ||
225 | 183 | ||
226 | { | 184 | expect(abuse2.flaggedAccount.name).to.equal('root') |
227 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) | 185 | expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) |
228 | 186 | ||
229 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 187 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) |
230 | expect(res.body.total).to.equal(3) | 188 | expect(abuse2.state.label).to.equal('Pending') |
231 | } | 189 | expect(abuse2.moderationComment).to.be.null |
232 | }) | ||
233 | 190 | ||
234 | it('Should keep the video abuse when deleting the video', async function () { | 191 | const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
235 | this.timeout(10000) | 192 | expect(res2.body.total).to.equal(1) |
193 | expect(res2.body.data.length).to.equal(1) | ||
236 | 194 | ||
237 | await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) | 195 | abuseServer2 = res2.body.data[0] |
196 | expect(abuseServer2.reason).to.equal('my super bad reason 2') | ||
197 | expect(abuseServer2.reporterAccount.name).to.equal('root') | ||
198 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | ||
238 | 199 | ||
239 | await waitJobs(servers) | 200 | expect(abuse2.flaggedAccount.name).to.equal('root') |
201 | expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) | ||
240 | 202 | ||
241 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | 203 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) |
242 | expect(res.body.total).to.equal(2, "wrong number of videos returned") | 204 | expect(abuseServer2.state.label).to.equal('Pending') |
243 | expect(res.body.data.length).to.equal(2, "wrong number of videos returned") | 205 | expect(abuseServer2.moderationComment).to.be.null |
244 | expect(res.body.data[0].id).to.equal(abuseServer2.id, "wrong origin server id for first video") | 206 | }) |
245 | 207 | ||
246 | const abuse: Abuse = res.body.data[0] | 208 | it('Should hide video abuses from blocked accounts', async function () { |
247 | expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") | 209 | this.timeout(10000) |
248 | expect(abuse.video.channel).to.exist | ||
249 | expect(abuse.video.deleted).to.be.true | ||
250 | }) | ||
251 | 210 | ||
252 | it('Should include counts of reports from reporter and reportee', async function () { | 211 | { |
253 | this.timeout(10000) | 212 | const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) |
213 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) | ||
214 | await waitJobs(servers) | ||
254 | 215 | ||
255 | // register a second user to have two reporters/reportees | 216 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
256 | const user = { username: 'user2', password: 'password' } | 217 | expect(res.body.total).to.equal(3) |
257 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) | 218 | } |
258 | const userAccessToken = await userLogin(servers[0], user) | ||
259 | 219 | ||
260 | // upload a third video via this user | 220 | const accountToBlock = 'root@' + servers[1].host |
261 | const video3Attributes = { | 221 | |
262 | name: 'my second super name for server 1', | 222 | { |
263 | description: 'my second super description for server 1' | 223 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) |
264 | } | 224 | |
265 | await uploadVideo(servers[0].url, userAccessToken, video3Attributes) | 225 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
266 | 226 | expect(res.body.total).to.equal(2) | |
267 | const res1 = await getVideosList(servers[0].url) | 227 | |
268 | const videos = res1.body.data | 228 | const abuse = res.body.data.find(a => a.reason === 'will mute this') |
269 | const video3 = videos.find(video => video.name === 'my second super name for server 1') | 229 | expect(abuse).to.be.undefined |
270 | 230 | } | |
271 | // resume with the test | 231 | |
272 | const reason3 = 'my super bad reason 3' | 232 | { |
273 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, video3.id, reason3) | 233 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) |
274 | const reason4 = 'my super bad reason 4' | 234 | |
275 | await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4) | 235 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
276 | 236 | expect(res.body.total).to.equal(3) | |
277 | const res2 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 237 | } |
278 | 238 | }) | |
279 | { | 239 | |
280 | for (const abuse of res2.body.data as Abuse[]) { | 240 | it('Should hide video abuses from blocked servers', async function () { |
281 | if (abuse.video.id === video3.id) { | 241 | const serverToBlock = servers[1].host |
282 | expect(abuse.count).to.equal(1, "wrong reports count for video 3") | 242 | |
283 | expect(abuse.nth).to.equal(1, "wrong report position in report list for video 3") | 243 | { |
284 | expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") | 244 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) |
285 | expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") | 245 | |
286 | } | 246 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
287 | if (abuse.video.id === servers[0].video.id) { | 247 | expect(res.body.total).to.equal(2) |
288 | expect(abuse.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") | 248 | |
249 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | ||
250 | expect(abuse).to.be.undefined | ||
251 | } | ||
252 | |||
253 | { | ||
254 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) | ||
255 | |||
256 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | ||
257 | expect(res.body.total).to.equal(3) | ||
258 | } | ||
259 | }) | ||
260 | |||
261 | it('Should keep the video abuse when deleting the video', async function () { | ||
262 | this.timeout(10000) | ||
263 | |||
264 | await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) | ||
265 | |||
266 | await waitJobs(servers) | ||
267 | |||
268 | const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | ||
269 | expect(res.body.total).to.equal(2, "wrong number of videos returned") | ||
270 | expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned") | ||
271 | |||
272 | const abuse: Abuse = res.body.data[0] | ||
273 | expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") | ||
274 | expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") | ||
275 | expect(abuse.video.channel).to.exist | ||
276 | expect(abuse.video.deleted).to.be.true | ||
277 | }) | ||
278 | |||
279 | it('Should include counts of reports from reporter and reportee', async function () { | ||
280 | this.timeout(10000) | ||
281 | |||
282 | // register a second user to have two reporters/reportees | ||
283 | const user = { username: 'user2', password: 'password' } | ||
284 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) | ||
285 | const userAccessToken = await userLogin(servers[0], user) | ||
286 | |||
287 | // upload a third video via this user | ||
288 | const video3Attributes = { | ||
289 | name: 'my second super name for server 1', | ||
290 | description: 'my second super description for server 1' | ||
291 | } | ||
292 | await uploadVideo(servers[0].url, userAccessToken, video3Attributes) | ||
293 | |||
294 | const res1 = await getVideosList(servers[0].url) | ||
295 | const videos = res1.body.data | ||
296 | const video3 = videos.find(video => video.name === 'my second super name for server 1') | ||
297 | |||
298 | // resume with the test | ||
299 | const reason3 = 'my super bad reason 3' | ||
300 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 }) | ||
301 | |||
302 | const reason4 = 'my super bad reason 4' | ||
303 | await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) | ||
304 | |||
305 | { | ||
306 | const res2 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | ||
307 | const abuses = res2.body.data as Abuse[] | ||
308 | |||
309 | const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) | ||
310 | expect(abuseVideo3).to.not.be.undefined | ||
311 | expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") | ||
312 | expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3") | ||
313 | expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") | ||
314 | expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") | ||
315 | |||
316 | const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id) | ||
317 | expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") | ||
318 | } | ||
319 | }) | ||
320 | |||
321 | it('Should list predefined reasons as well as timestamps for the reported video', async function () { | ||
322 | this.timeout(10000) | ||
323 | |||
324 | const reason5 = 'my super bad reason 5' | ||
325 | const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] | ||
326 | const createdAbuse = (await reportAbuse({ | ||
327 | url: servers[0].url, | ||
328 | token: servers[0].accessToken, | ||
329 | videoId: servers[0].video.id, | ||
330 | reason: reason5, | ||
331 | predefinedReasons: predefinedReasons5, | ||
332 | startAt: 1, | ||
333 | endAt: 5 | ||
334 | })).body.abuse | ||
335 | |||
336 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | ||
337 | |||
338 | { | ||
339 | const abuse = (res.body.data as Abuse[]).find(a => a.id === createdAbuse.id) | ||
340 | expect(abuse.reason).to.equals(reason5) | ||
341 | expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") | ||
342 | expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") | ||
343 | expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported") | ||
344 | } | ||
345 | }) | ||
346 | |||
347 | it('Should delete the video abuse', async function () { | ||
348 | this.timeout(10000) | ||
349 | |||
350 | await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) | ||
351 | |||
352 | await waitJobs(servers) | ||
353 | |||
354 | { | ||
355 | const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | ||
356 | expect(res.body.total).to.equal(1) | ||
357 | expect(res.body.data.length).to.equal(1) | ||
358 | expect(res.body.data[0].id).to.not.equal(abuseServer2.id) | ||
359 | } | ||
360 | |||
361 | { | ||
362 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | ||
363 | expect(res.body.total).to.equal(6) | ||
364 | } | ||
365 | }) | ||
366 | |||
367 | it('Should list and filter video abuses', async function () { | ||
368 | this.timeout(10000) | ||
369 | |||
370 | async function list (query: Omit<Parameters<typeof getAbusesList>[0], 'url' | 'token'>) { | ||
371 | const options = { | ||
372 | url: servers[0].url, | ||
373 | token: servers[0].accessToken | ||
289 | } | 374 | } |
375 | |||
376 | Object.assign(options, query) | ||
377 | |||
378 | const res = await getAbusesList(options) | ||
379 | |||
380 | return res.body.data as Abuse[] | ||
290 | } | 381 | } |
291 | } | ||
292 | }) | ||
293 | 382 | ||
294 | it('Should list predefined reasons as well as timestamps for the reported video', async function () { | 383 | expect(await list({ id: 56 })).to.have.lengthOf(0) |
295 | this.timeout(10000) | 384 | expect(await list({ id: 1 })).to.have.lengthOf(1) |
296 | 385 | ||
297 | const reason5 = 'my super bad reason 5' | 386 | expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4) |
298 | const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] | 387 | expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0) |
299 | const createdAbuse = (await reportVideoAbuse( | 388 | |
300 | servers[0].url, | 389 | expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1) |
301 | servers[0].accessToken, | 390 | |
302 | servers[0].video.id, | 391 | expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4) |
303 | reason5, | 392 | expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0) |
304 | predefinedReasons5, | 393 | |
305 | 1, | 394 | expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1) |
306 | 5 | 395 | expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5) |
307 | )).body.abuse | 396 | |
308 | 397 | expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5) | |
309 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 398 | expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0) |
310 | 399 | ||
311 | { | 400 | expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1) |
312 | const abuse = (res.body.data as Abuse[]).find(a => a.id === createdAbuse.id) | 401 | expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0) |
313 | expect(abuse.reason).to.equals(reason5) | 402 | |
314 | expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") | 403 | expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0) |
315 | expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") | 404 | expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6) |
316 | expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported") | 405 | |
317 | } | 406 | expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1) |
407 | expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0) | ||
408 | }) | ||
318 | }) | 409 | }) |
319 | 410 | ||
320 | it('Should delete the video abuse', async function () { | 411 | describe('Comment abuses', function () { |
321 | this.timeout(10000) | ||
322 | 412 | ||
323 | await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id) | 413 | async function getComment (url: string, videoIdArg: number | string) { |
414 | const videoId = typeof videoIdArg === 'string' | ||
415 | ? await getVideoIdFromUUID(url, videoIdArg) | ||
416 | : videoIdArg | ||
324 | 417 | ||
325 | await waitJobs(servers) | 418 | const res = await getVideoCommentThreads(url, videoId, 0, 5) |
326 | 419 | ||
327 | { | 420 | return res.body.data[0] as VideoComment |
328 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) | ||
329 | expect(res.body.total).to.equal(1) | ||
330 | expect(res.body.data.length).to.equal(1) | ||
331 | expect(res.body.data[0].id).to.not.equal(abuseServer2.id) | ||
332 | } | 421 | } |
333 | 422 | ||
334 | { | 423 | before(async function () { |
335 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | 424 | this.timeout(50000) |
336 | expect(res.body.total).to.equal(6) | ||
337 | } | ||
338 | }) | ||
339 | 425 | ||
340 | it('Should list and filter video abuses', async function () { | 426 | servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) |
341 | async function list (query: Omit<Parameters<typeof getVideoAbusesList>[0], 'url' | 'token'>) { | 427 | servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) |
342 | const options = { | 428 | |
343 | url: servers[0].url, | 429 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1') |
344 | token: servers[0].accessToken | 430 | await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2') |
431 | |||
432 | await waitJobs(servers) | ||
433 | }) | ||
434 | |||
435 | it('Should report abuse on a comment', async function () { | ||
436 | this.timeout(15000) | ||
437 | |||
438 | const comment = await getComment(servers[0].url, servers[0].video.id) | ||
439 | |||
440 | const reason = 'it is a bad comment' | ||
441 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) | ||
442 | |||
443 | await waitJobs(servers) | ||
444 | }) | ||
445 | |||
446 | it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { | ||
447 | { | ||
448 | const comment = await getComment(servers[0].url, servers[0].video.id) | ||
449 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | ||
450 | |||
451 | expect(res.body.total).to.equal(1) | ||
452 | expect(res.body.data).to.have.lengthOf(1) | ||
453 | |||
454 | const abuse: Abuse = res.body.data[0] | ||
455 | expect(abuse.reason).to.equal('it is a bad comment') | ||
456 | |||
457 | expect(abuse.reporterAccount.name).to.equal('root') | ||
458 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) | ||
459 | |||
460 | expect(abuse.video).to.be.null | ||
461 | |||
462 | expect(abuse.comment.deleted).to.be.false | ||
463 | expect(abuse.comment.id).to.equal(comment.id) | ||
464 | expect(abuse.comment.text).to.equal(comment.text) | ||
465 | expect(abuse.comment.video.name).to.equal('server 1') | ||
466 | expect(abuse.comment.video.id).to.equal(servers[0].video.id) | ||
467 | expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid) | ||
468 | |||
469 | expect(abuse.countReportsForReporter).to.equal(5) | ||
470 | expect(abuse.countReportsForReportee).to.equal(5) | ||
471 | } | ||
472 | |||
473 | { | ||
474 | const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | ||
475 | expect(res.body.total).to.equal(0) | ||
476 | expect(res.body.data.length).to.equal(0) | ||
477 | } | ||
478 | }) | ||
479 | |||
480 | it('Should report abuse on a remote comment', async function () { | ||
481 | this.timeout(10000) | ||
482 | |||
483 | const comment = await getComment(servers[0].url, servers[1].video.uuid) | ||
484 | |||
485 | const reason = 'it is a really bad comment' | ||
486 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) | ||
487 | |||
488 | await waitJobs(servers) | ||
489 | }) | ||
490 | |||
491 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | ||
492 | const commentServer2 = await getComment(servers[0].url, servers[1].video.id) | ||
493 | |||
494 | const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | ||
495 | expect(res1.body.total).to.equal(2) | ||
496 | expect(res1.body.data.length).to.equal(2) | ||
497 | |||
498 | const abuse: Abuse = res1.body.data[0] | ||
499 | expect(abuse.reason).to.equal('it is a bad comment') | ||
500 | expect(abuse.countReportsForReporter).to.equal(6) | ||
501 | expect(abuse.countReportsForReportee).to.equal(5) | ||
502 | |||
503 | const abuse2: Abuse = res1.body.data[1] | ||
504 | |||
505 | expect(abuse2.reason).to.equal('it is a really bad comment') | ||
506 | |||
507 | expect(abuse2.reporterAccount.name).to.equal('root') | ||
508 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | ||
509 | |||
510 | expect(abuse2.video).to.be.null | ||
511 | |||
512 | expect(abuse2.comment.deleted).to.be.false | ||
513 | expect(abuse2.comment.id).to.equal(commentServer2.id) | ||
514 | expect(abuse2.comment.text).to.equal(commentServer2.text) | ||
515 | expect(abuse2.comment.video.name).to.equal('server 2') | ||
516 | expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) | ||
517 | |||
518 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | ||
519 | expect(abuse2.state.label).to.equal('Pending') | ||
520 | |||
521 | expect(abuse2.moderationComment).to.be.null | ||
522 | |||
523 | expect(abuse2.countReportsForReporter).to.equal(6) | ||
524 | expect(abuse2.countReportsForReportee).to.equal(2) | ||
525 | |||
526 | const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | ||
527 | expect(res2.body.total).to.equal(1) | ||
528 | expect(res2.body.data.length).to.equal(1) | ||
529 | |||
530 | abuseServer2 = res2.body.data[0] | ||
531 | expect(abuseServer2.reason).to.equal('it is a really bad comment') | ||
532 | expect(abuseServer2.reporterAccount.name).to.equal('root') | ||
533 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | ||
534 | |||
535 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | ||
536 | expect(abuseServer2.state.label).to.equal('Pending') | ||
537 | |||
538 | expect(abuseServer2.moderationComment).to.be.null | ||
539 | |||
540 | expect(abuseServer2.countReportsForReporter).to.equal(1) | ||
541 | expect(abuseServer2.countReportsForReportee).to.equal(1) | ||
542 | }) | ||
543 | |||
544 | it('Should keep the comment abuse when deleting the comment', async function () { | ||
545 | this.timeout(10000) | ||
546 | |||
547 | const commentServer2 = await getComment(servers[0].url, servers[1].video.id) | ||
548 | |||
549 | await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id) | ||
550 | |||
551 | await waitJobs(servers) | ||
552 | |||
553 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | ||
554 | expect(res.body.total).to.equal(2) | ||
555 | expect(res.body.data).to.have.lengthOf(2) | ||
556 | |||
557 | const abuse = (res.body.data as Abuse[]).find(a => a.comment?.id === commentServer2.id) | ||
558 | expect(abuse).to.not.be.undefined | ||
559 | |||
560 | expect(abuse.comment.text).to.be.empty | ||
561 | expect(abuse.comment.video.name).to.equal('server 2') | ||
562 | expect(abuse.comment.deleted).to.be.true | ||
563 | }) | ||
564 | |||
565 | it('Should delete the comment abuse', async function () { | ||
566 | this.timeout(10000) | ||
567 | |||
568 | await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) | ||
569 | |||
570 | await waitJobs(servers) | ||
571 | |||
572 | { | ||
573 | const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | ||
574 | expect(res.body.total).to.equal(0) | ||
575 | expect(res.body.data.length).to.equal(0) | ||
576 | } | ||
577 | |||
578 | { | ||
579 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) | ||
580 | expect(res.body.total).to.equal(2) | ||
581 | } | ||
582 | }) | ||
583 | |||
584 | it('Should list and filter video abuses', async function () { | ||
585 | { | ||
586 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment', searchReportee: 'foo' }) | ||
587 | expect(res.body.total).to.equal(0) | ||
588 | } | ||
589 | |||
590 | { | ||
591 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment', searchReportee: 'ot' }) | ||
592 | expect(res.body.total).to.equal(2) | ||
593 | } | ||
594 | |||
595 | { | ||
596 | const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } | ||
597 | |||
598 | const res1 = await getAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) | ||
599 | expect(res1.body.data).to.have.lengthOf(1) | ||
600 | expect(res1.body.data[0].comment.text).to.be.empty | ||
601 | |||
602 | const res2 = await getAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) | ||
603 | expect(res2.body.data).to.have.lengthOf(1) | ||
604 | expect(res2.body.data[0].comment.text).to.equal('comment server 1') | ||
345 | } | 605 | } |
606 | }) | ||
607 | }) | ||
346 | 608 | ||
347 | Object.assign(options, query) | 609 | describe('Account abuses', function () { |
348 | 610 | ||
349 | const res = await getVideoAbusesList(options) | 611 | async function getAccountFromServer (url: string, name: string, server: ServerInfo) { |
612 | const res = await getAccount(url, name + '@' + server.host) | ||
350 | 613 | ||
351 | return res.body.data as Abuse[] | 614 | return res.body as Account |
352 | } | 615 | } |
353 | 616 | ||
354 | expect(await list({ id: 56 })).to.have.lengthOf(0) | 617 | before(async function () { |
355 | expect(await list({ id: 1 })).to.have.lengthOf(1) | 618 | this.timeout(50000) |
619 | |||
620 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' }) | ||
621 | |||
622 | const token = await generateUserAccessToken(servers[1], 'user_2') | ||
623 | await uploadVideo(servers[1].url, token, { name: 'super video' }) | ||
624 | |||
625 | await waitJobs(servers) | ||
626 | }) | ||
627 | |||
628 | it('Should report abuse on an account', async function () { | ||
629 | this.timeout(15000) | ||
630 | |||
631 | const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) | ||
632 | |||
633 | const reason = 'it is a bad account' | ||
634 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) | ||
635 | |||
636 | await waitJobs(servers) | ||
637 | }) | ||
638 | |||
639 | it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { | ||
640 | { | ||
641 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | ||
642 | |||
643 | expect(res.body.total).to.equal(1) | ||
644 | expect(res.body.data).to.have.lengthOf(1) | ||
645 | |||
646 | const abuse: Abuse = res.body.data[0] | ||
647 | expect(abuse.reason).to.equal('it is a bad account') | ||
648 | |||
649 | expect(abuse.reporterAccount.name).to.equal('root') | ||
650 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) | ||
651 | |||
652 | expect(abuse.video).to.be.null | ||
653 | expect(abuse.comment).to.be.null | ||
654 | |||
655 | expect(abuse.flaggedAccount.name).to.equal('user_1') | ||
656 | expect(abuse.flaggedAccount.host).to.equal(servers[0].host) | ||
657 | } | ||
658 | |||
659 | { | ||
660 | const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) | ||
661 | expect(res.body.total).to.equal(0) | ||
662 | expect(res.body.data.length).to.equal(0) | ||
663 | } | ||
664 | }) | ||
665 | |||
666 | it('Should report abuse on a remote account', async function () { | ||
667 | this.timeout(10000) | ||
668 | |||
669 | const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) | ||
670 | |||
671 | const reason = 'it is a really bad account' | ||
672 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) | ||
673 | |||
674 | await waitJobs(servers) | ||
675 | }) | ||
676 | |||
677 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | ||
678 | const res1 = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | ||
679 | expect(res1.body.total).to.equal(2) | ||
680 | expect(res1.body.data.length).to.equal(2) | ||
681 | |||
682 | const abuse: Abuse = res1.body.data[0] | ||
683 | expect(abuse.reason).to.equal('it is a bad account') | ||
356 | 684 | ||
357 | expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4) | 685 | const abuse2: Abuse = res1.body.data[1] |
358 | expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0) | 686 | expect(abuse2.reason).to.equal('it is a really bad account') |
359 | 687 | ||
360 | expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1) | 688 | expect(abuse2.reporterAccount.name).to.equal('root') |
689 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | ||
361 | 690 | ||
362 | expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4) | 691 | expect(abuse2.video).to.be.null |
363 | expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0) | 692 | expect(abuse2.comment).to.be.null |
693 | |||
694 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | ||
695 | expect(abuse2.state.label).to.equal('Pending') | ||
696 | |||
697 | expect(abuse2.moderationComment).to.be.null | ||
698 | |||
699 | const res2 = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) | ||
700 | expect(res2.body.total).to.equal(1) | ||
701 | expect(res2.body.data.length).to.equal(1) | ||
702 | |||
703 | abuseServer2 = res2.body.data[0] | ||
704 | |||
705 | expect(abuseServer2.reason).to.equal('it is a really bad account') | ||
706 | |||
707 | expect(abuseServer2.reporterAccount.name).to.equal('root') | ||
708 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | ||
709 | |||
710 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | ||
711 | expect(abuseServer2.state.label).to.equal('Pending') | ||
712 | |||
713 | expect(abuseServer2.moderationComment).to.be.null | ||
714 | }) | ||
715 | |||
716 | it('Should keep the account abuse when deleting the account', async function () { | ||
717 | this.timeout(10000) | ||
718 | |||
719 | const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) | ||
720 | await removeUser(servers[1].url, account.userId, servers[1].accessToken) | ||
721 | |||
722 | await waitJobs(servers) | ||
723 | |||
724 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | ||
725 | expect(res.body.total).to.equal(2) | ||
726 | expect(res.body.data).to.have.lengthOf(2) | ||
727 | |||
728 | const abuse = (res.body.data as Abuse[]).find(a => a.reason === 'it is a really bad account') | ||
729 | expect(abuse).to.not.be.undefined | ||
730 | }) | ||
731 | |||
732 | it('Should delete the account abuse', async function () { | ||
733 | this.timeout(10000) | ||
734 | |||
735 | await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) | ||
736 | |||
737 | await waitJobs(servers) | ||
738 | |||
739 | { | ||
740 | const res = await getAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) | ||
741 | expect(res.body.total).to.equal(0) | ||
742 | expect(res.body.data.length).to.equal(0) | ||
743 | } | ||
744 | |||
745 | { | ||
746 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) | ||
747 | expect(res.body.total).to.equal(2) | ||
748 | |||
749 | abuseServer1 = res.body.data[0] | ||
750 | } | ||
751 | }) | ||
752 | }) | ||
364 | 753 | ||
365 | expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1) | 754 | describe('Common actions on abuses', function () { |
366 | expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5) | ||
367 | 755 | ||
368 | expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5) | 756 | it('Should update the state of an abuse', async function () { |
369 | expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0) | 757 | const body = { state: AbuseState.REJECTED } |
758 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) | ||
370 | 759 | ||
371 | expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1) | 760 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) |
372 | expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0) | 761 | expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) |
762 | }) | ||
373 | 763 | ||
374 | expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0) | 764 | it('Should add a moderation comment', async function () { |
375 | expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6) | 765 | const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } |
766 | await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) | ||
376 | 767 | ||
377 | expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1) | 768 | const res = await getAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) |
378 | expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0) | 769 | expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) |
770 | expect(res.body.data[0].moderationComment).to.equal('It is valid') | ||
771 | }) | ||
379 | }) | 772 | }) |
380 | 773 | ||
381 | after(async function () { | 774 | after(async function () { |
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index a27681603..a8517600a 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -3,10 +3,16 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { v4 as uuidv4 } from 'uuid' | 4 | import { v4 as uuidv4 } from 'uuid' |
5 | import { | 5 | import { |
6 | addVideoCommentThread, | ||
6 | addVideoToBlacklist, | 7 | addVideoToBlacklist, |
7 | cleanupTests, | 8 | cleanupTests, |
9 | createUser, | ||
8 | follow, | 10 | follow, |
11 | generateUserAccessToken, | ||
12 | getAccount, | ||
9 | getCustomConfig, | 13 | getCustomConfig, |
14 | getVideoCommentThreads, | ||
15 | getVideoIdFromUUID, | ||
10 | immutableAssign, | 16 | immutableAssign, |
11 | MockInstancesIndex, | 17 | MockInstancesIndex, |
12 | registerUser, | 18 | registerUser, |
@@ -23,7 +29,9 @@ import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |||
23 | import { | 29 | import { |
24 | checkAutoInstanceFollowing, | 30 | checkAutoInstanceFollowing, |
25 | CheckerBaseParams, | 31 | CheckerBaseParams, |
32 | checkNewAccountAbuseForModerators, | ||
26 | checkNewBlacklistOnMyVideo, | 33 | checkNewBlacklistOnMyVideo, |
34 | checkNewCommentAbuseForModerators, | ||
27 | checkNewInstanceFollower, | 35 | checkNewInstanceFollower, |
28 | checkNewVideoAbuseForModerators, | 36 | checkNewVideoAbuseForModerators, |
29 | checkNewVideoFromSubscription, | 37 | checkNewVideoFromSubscription, |
@@ -91,11 +99,74 @@ describe('Test moderation notifications', function () { | |||
91 | 99 | ||
92 | await waitJobs(servers) | 100 | await waitJobs(servers) |
93 | 101 | ||
94 | await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId: video.id, reason: 'super reason' }) | 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' }) | ||
95 | 104 | ||
96 | await waitJobs(servers) | 105 | await waitJobs(servers) |
97 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') | 106 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') |
98 | }) | 107 | }) |
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 | }) | ||
99 | }) | 170 | }) |
100 | 171 | ||
101 | describe('Video blacklist on my video', function () { | 172 | describe('Video blacklist on my video', function () { |
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 9c3299618..b01a91d48 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts | |||
@@ -180,7 +180,7 @@ describe('Test emails', function () { | |||
180 | }) | 180 | }) |
181 | }) | 181 | }) |
182 | 182 | ||
183 | describe('When creating a video abuse', function () { | 183 | describe('When creating an abuse', function () { |
184 | it('Should send the notification email', async function () { | 184 | it('Should send the notification email', async function () { |
185 | this.timeout(10000) | 185 | this.timeout(10000) |
186 | 186 | ||