aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-24 13:53:45 +0200
committerChocobozzz <me@florianbigard.com>2020-08-24 13:53:45 +0200
commit8b6f0fd53d12faf54a58602a8bcfab05e8b5947b (patch)
treeddfae0ddd7b44a0a626e1033d578937a7023c948 /server/tests/api/moderation
parent1f5221fb4a511bb175083a9c7f578679c6122ce3 (diff)
downloadPeerTube-8b6f0fd53d12faf54a58602a8bcfab05e8b5947b.tar.gz
PeerTube-8b6f0fd53d12faf54a58602a8bcfab05e8b5947b.tar.zst
PeerTube-8b6f0fd53d12faf54a58602a8bcfab05e8b5947b.zip
Reorganize a little bit tests
Diffstat (limited to 'server/tests/api/moderation')
-rw-r--r--server/tests/api/moderation/index.ts2
-rw-r--r--server/tests/api/moderation/video-abuse.ts386
-rw-r--r--server/tests/api/moderation/video-blacklist.ts479
3 files changed, 867 insertions, 0 deletions
diff --git a/server/tests/api/moderation/index.ts b/server/tests/api/moderation/index.ts
index cb018d88e..ceb223003 100644
--- a/server/tests/api/moderation/index.ts
+++ b/server/tests/api/moderation/index.ts
@@ -1,2 +1,4 @@
1export * from './abuses' 1export * from './abuses'
2export * from './blocklist' 2export * from './blocklist'
3export * from './video-abuse'
4export * from './video-blacklist'
diff --git a/server/tests/api/moderation/video-abuse.ts b/server/tests/api/moderation/video-abuse.ts
new file mode 100644
index 000000000..0b6a0e8ae
--- /dev/null
+++ b/server/tests/api/moderation/video-abuse.ts
@@ -0,0 +1,386 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { AbusePredefinedReasonsString, AbuseState, AdminAbuse } from '@shared/models'
6import {
7 cleanupTests,
8 createUser,
9 deleteVideoAbuse,
10 flushAndRunMultipleServers,
11 getVideoAbusesList,
12 getVideosList,
13 removeVideo,
14 reportVideoAbuse,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateVideoAbuse,
18 uploadVideo,
19 userLogin
20} from '../../../../shared/extra-utils/index'
21import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import {
24 addAccountToServerBlocklist,
25 addServerToServerBlocklist,
26 removeAccountFromServerBlocklist,
27 removeServerFromServerBlocklist
28} from '../../../../shared/extra-utils/users/blocklist'
29
30const expect = chai.expect
31
32// FIXME: deprecated in 2.3. Remove this controller
33
34describe('Test video abuses', function () {
35 let servers: ServerInfo[] = []
36 let abuseServer2: AdminAbuse
37
38 before(async function () {
39 this.timeout(50000)
40
41 // Run servers
42 servers = await flushAndRunMultipleServers(2)
43
44 // Get the access tokens
45 await setAccessTokensToServers(servers)
46
47 // Server 1 and server 2 follow each other
48 await doubleFollow(servers[0], servers[1])
49
50 // Upload some videos on each servers
51 const video1Attributes = {
52 name: 'my super name for server 1',
53 description: 'my super description for server 1'
54 }
55 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
56
57 const video2Attributes = {
58 name: 'my super name for server 2',
59 description: 'my super description for server 2'
60 }
61 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
62
63 // Wait videos propagation, server 2 has transcoding enabled
64 await waitJobs(servers)
65
66 const res = await getVideosList(servers[0].url)
67 const videos = res.body.data
68
69 expect(videos.length).to.equal(2)
70
71 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
72 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
73 })
74
75 it('Should not have video abuses', async function () {
76 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
77
78 expect(res.body.total).to.equal(0)
79 expect(res.body.data).to.be.an('array')
80 expect(res.body.data.length).to.equal(0)
81 })
82
83 it('Should report abuse on a local video', async function () {
84 this.timeout(15000)
85
86 const reason = 'my super bad reason'
87 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
88
89 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
90 await waitJobs(servers)
91 })
92
93 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
94 const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
95
96 expect(res1.body.total).to.equal(1)
97 expect(res1.body.data).to.be.an('array')
98 expect(res1.body.data.length).to.equal(1)
99
100 const abuse: AdminAbuse = res1.body.data[0]
101 expect(abuse.reason).to.equal('my super bad reason')
102 expect(abuse.reporterAccount.name).to.equal('root')
103 expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port)
104 expect(abuse.video.id).to.equal(servers[0].video.id)
105 expect(abuse.video.channel).to.exist
106 expect(abuse.video.countReports).to.equal(1)
107 expect(abuse.video.nthReport).to.equal(1)
108 expect(abuse.countReportsForReporter).to.equal(1)
109 expect(abuse.countReportsForReportee).to.equal(1)
110
111 const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
112 expect(res2.body.total).to.equal(0)
113 expect(res2.body.data).to.be.an('array')
114 expect(res2.body.data.length).to.equal(0)
115 })
116
117 it('Should report abuse on a remote video', async function () {
118 this.timeout(10000)
119
120 const reason = 'my super bad reason 2'
121 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
122
123 // We wait requests propagation
124 await waitJobs(servers)
125 })
126
127 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
128 const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
129 expect(res1.body.total).to.equal(2)
130 expect(res1.body.data).to.be.an('array')
131 expect(res1.body.data.length).to.equal(2)
132
133 const abuse1: AdminAbuse = res1.body.data[0]
134 expect(abuse1.reason).to.equal('my super bad reason')
135 expect(abuse1.reporterAccount.name).to.equal('root')
136 expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port)
137 expect(abuse1.video.id).to.equal(servers[0].video.id)
138 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
139 expect(abuse1.state.label).to.equal('Pending')
140 expect(abuse1.moderationComment).to.be.null
141 expect(abuse1.video.countReports).to.equal(1)
142 expect(abuse1.video.nthReport).to.equal(1)
143
144 const abuse2: AdminAbuse = res1.body.data[1]
145 expect(abuse2.reason).to.equal('my super bad reason 2')
146 expect(abuse2.reporterAccount.name).to.equal('root')
147 expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port)
148 expect(abuse2.video.id).to.equal(servers[1].video.id)
149 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
150 expect(abuse2.state.label).to.equal('Pending')
151 expect(abuse2.moderationComment).to.be.null
152
153 const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
154 expect(res2.body.total).to.equal(1)
155 expect(res2.body.data).to.be.an('array')
156 expect(res2.body.data.length).to.equal(1)
157
158 abuseServer2 = res2.body.data[0]
159 expect(abuseServer2.reason).to.equal('my super bad reason 2')
160 expect(abuseServer2.reporterAccount.name).to.equal('root')
161 expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port)
162 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
163 expect(abuseServer2.state.label).to.equal('Pending')
164 expect(abuseServer2.moderationComment).to.be.null
165 })
166
167 it('Should update the state of a video abuse', async function () {
168 const body = { state: AbuseState.REJECTED }
169 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
170
171 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
172 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED)
173 })
174
175 it('Should add a moderation comment', async function () {
176 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' }
177 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
178
179 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
180 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
181 expect(res.body.data[0].moderationComment).to.equal('It is valid')
182 })
183
184 it('Should hide video abuses from blocked accounts', async function () {
185 this.timeout(10000)
186
187 {
188 await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this')
189 await waitJobs(servers)
190
191 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
192 expect(res.body.total).to.equal(3)
193 }
194
195 const accountToBlock = 'root@localhost:' + servers[1].port
196
197 {
198 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
199
200 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
201 expect(res.body.total).to.equal(2)
202
203 const abuse = res.body.data.find(a => a.reason === 'will mute this')
204 expect(abuse).to.be.undefined
205 }
206
207 {
208 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
209
210 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
211 expect(res.body.total).to.equal(3)
212 }
213 })
214
215 it('Should hide video abuses from blocked servers', async function () {
216 const serverToBlock = servers[1].host
217
218 {
219 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
220
221 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
222 expect(res.body.total).to.equal(2)
223
224 const abuse = res.body.data.find(a => a.reason === 'will mute this')
225 expect(abuse).to.be.undefined
226 }
227
228 {
229 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
230
231 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
232 expect(res.body.total).to.equal(3)
233 }
234 })
235
236 it('Should keep the video abuse when deleting the video', async function () {
237 this.timeout(10000)
238
239 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
240
241 await waitJobs(servers)
242
243 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
244 expect(res.body.total).to.equal(2, "wrong number of videos returned")
245 expect(res.body.data.length).to.equal(2, "wrong number of videos returned")
246 expect(res.body.data[0].id).to.equal(abuseServer2.id, "wrong origin server id for first video")
247
248 const abuse: AdminAbuse = res.body.data[0]
249 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
250 expect(abuse.video.channel).to.exist
251 expect(abuse.video.deleted).to.be.true
252 })
253
254 it('Should include counts of reports from reporter and reportee', async function () {
255 this.timeout(10000)
256
257 // register a second user to have two reporters/reportees
258 const user = { username: 'user2', password: 'password' }
259 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
260 const userAccessToken = await userLogin(servers[0], user)
261
262 // upload a third video via this user
263 const video3Attributes = {
264 name: 'my second super name for server 1',
265 description: 'my second super description for server 1'
266 }
267 await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
268
269 const res1 = await getVideosList(servers[0].url)
270 const videos = res1.body.data
271 const video3 = videos.find(video => video.name === 'my second super name for server 1')
272
273 // resume with the test
274 const reason3 = 'my super bad reason 3'
275 await reportVideoAbuse(servers[0].url, servers[0].accessToken, video3.id, reason3)
276 const reason4 = 'my super bad reason 4'
277 await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4)
278
279 const res2 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
280
281 {
282 for (const abuse of res2.body.data as AdminAbuse[]) {
283 if (abuse.video.id === video3.id) {
284 expect(abuse.video.countReports).to.equal(1, "wrong reports count for video 3")
285 expect(abuse.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
286 expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
287 expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
288 }
289 if (abuse.video.id === servers[0].video.id) {
290 expect(abuse.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
291 }
292 }
293 }
294 })
295
296 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
297 this.timeout(10000)
298
299 const reason5 = 'my super bad reason 5'
300 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
301 const createdAbuse = (await reportVideoAbuse(
302 servers[0].url,
303 servers[0].accessToken,
304 servers[0].video.id,
305 reason5,
306 predefinedReasons5,
307 1,
308 5
309 )).body.abuse
310
311 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
312
313 {
314 const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id)
315 expect(abuse.reason).to.equals(reason5)
316 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
317 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
318 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
319 }
320 })
321
322 it('Should delete the video abuse', async function () {
323 this.timeout(10000)
324
325 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
326
327 await waitJobs(servers)
328
329 {
330 const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken })
331 expect(res.body.total).to.equal(1)
332 expect(res.body.data.length).to.equal(1)
333 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
334 }
335
336 {
337 const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken })
338 expect(res.body.total).to.equal(6)
339 }
340 })
341
342 it('Should list and filter video abuses', async function () {
343 async function list (query: Omit<Parameters<typeof getVideoAbusesList>[0], 'url' | 'token'>) {
344 const options = {
345 url: servers[0].url,
346 token: servers[0].accessToken
347 }
348
349 Object.assign(options, query)
350
351 const res = await getVideoAbusesList(options)
352
353 return res.body.data as AdminAbuse[]
354 }
355
356 expect(await list({ id: 56 })).to.have.lengthOf(0)
357 expect(await list({ id: 1 })).to.have.lengthOf(1)
358
359 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
360 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
361
362 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
363
364 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
365 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
366
367 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
368 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
369
370 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
371 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
372
373 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
374 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
375
376 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
377 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
378
379 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
380 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
381 })
382
383 after(async function () {
384 await cleanupTests(servers)
385 })
386})
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
new file mode 100644
index 000000000..52cac20d9
--- /dev/null
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -0,0 +1,479 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { orderBy } from 'lodash'
6import {
7 addVideoToBlacklist,
8 cleanupTests,
9 createUser,
10 flushAndRunMultipleServers,
11 getBlacklistedVideosList,
12 getMyUserInformation,
13 getMyVideos,
14 getVideosList,
15 killallServers,
16 removeVideoFromBlacklist,
17 reRunServer,
18 searchVideo,
19 ServerInfo,
20 setAccessTokensToServers,
21 updateVideo,
22 updateVideoBlacklist,
23 uploadVideo,
24 userLogin
25} from '../../../../shared/extra-utils/index'
26import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
27import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
28import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
29import { User, UserRole } from '../../../../shared/models/users'
30import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
31import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
32
33const expect = chai.expect
34
35describe('Test video blacklist', function () {
36 let servers: ServerInfo[] = []
37 let videoId: number
38
39 async function blacklistVideosOnServer (server: ServerInfo) {
40 const res = await getVideosList(server.url)
41
42 const videos = res.body.data
43 for (const video of videos) {
44 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
45 }
46 }
47
48 before(async function () {
49 this.timeout(50000)
50
51 // Run servers
52 servers = await flushAndRunMultipleServers(2)
53
54 // Get the access tokens
55 await setAccessTokensToServers(servers)
56
57 // Server 1 and server 2 follow each other
58 await doubleFollow(servers[0], servers[1])
59
60 // Upload 2 videos on server 2
61 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
62 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
63
64 // Wait videos propagation, server 2 has transcoding enabled
65 await waitJobs(servers)
66
67 // Blacklist the two videos on server 1
68 await blacklistVideosOnServer(servers[0])
69 })
70
71 describe('When listing/searching videos', function () {
72
73 it('Should not have the video blacklisted in videos list/search on server 1', async function () {
74 {
75 const res = await getVideosList(servers[0].url)
76
77 expect(res.body.total).to.equal(0)
78 expect(res.body.data).to.be.an('array')
79 expect(res.body.data.length).to.equal(0)
80 }
81
82 {
83 const res = await searchVideo(servers[0].url, 'name')
84
85 expect(res.body.total).to.equal(0)
86 expect(res.body.data).to.be.an('array')
87 expect(res.body.data.length).to.equal(0)
88 }
89 })
90
91 it('Should have the blacklisted video in videos list/search on server 2', async function () {
92 {
93 const res = await getVideosList(servers[1].url)
94
95 expect(res.body.total).to.equal(2)
96 expect(res.body.data).to.be.an('array')
97 expect(res.body.data.length).to.equal(2)
98 }
99
100 {
101 const res = await searchVideo(servers[1].url, 'video')
102
103 expect(res.body.total).to.equal(2)
104 expect(res.body.data).to.be.an('array')
105 expect(res.body.data.length).to.equal(2)
106 }
107 })
108 })
109
110 describe('When listing manually blacklisted videos', function () {
111 it('Should display all the blacklisted videos', async function () {
112 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken })
113
114 expect(res.body.total).to.equal(2)
115
116 const blacklistedVideos = res.body.data
117 expect(blacklistedVideos).to.be.an('array')
118 expect(blacklistedVideos.length).to.equal(2)
119
120 for (const blacklistedVideo of blacklistedVideos) {
121 expect(blacklistedVideo.reason).to.equal('super reason')
122 videoId = blacklistedVideo.video.id
123 }
124 })
125
126 it('Should display all the blacklisted videos when applying manual type filter', async function () {
127 const res = await getBlacklistedVideosList({
128 url: servers[0].url,
129 token: servers[0].accessToken,
130 type: VideoBlacklistType.MANUAL
131 })
132
133 expect(res.body.total).to.equal(2)
134
135 const blacklistedVideos = res.body.data
136 expect(blacklistedVideos).to.be.an('array')
137 expect(blacklistedVideos.length).to.equal(2)
138 })
139
140 it('Should display nothing when applying automatic type filter', async function () {
141 const res = await getBlacklistedVideosList({
142 url: servers[0].url,
143 token: servers[0].accessToken,
144 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
145 })
146
147 expect(res.body.total).to.equal(0)
148
149 const blacklistedVideos = res.body.data
150 expect(blacklistedVideos).to.be.an('array')
151 expect(blacklistedVideos.length).to.equal(0)
152 })
153
154 it('Should get the correct sort when sorting by descending id', async function () {
155 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' })
156 expect(res.body.total).to.equal(2)
157
158 const blacklistedVideos = res.body.data
159 expect(blacklistedVideos).to.be.an('array')
160 expect(blacklistedVideos.length).to.equal(2)
161
162 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
163
164 expect(blacklistedVideos).to.deep.equal(result)
165 })
166
167 it('Should get the correct sort when sorting by descending video name', async function () {
168 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' })
169 expect(res.body.total).to.equal(2)
170
171 const blacklistedVideos = res.body.data
172 expect(blacklistedVideos).to.be.an('array')
173 expect(blacklistedVideos.length).to.equal(2)
174
175 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
176
177 expect(blacklistedVideos).to.deep.equal(result)
178 })
179
180 it('Should get the correct sort when sorting by ascending creation date', async function () {
181 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' })
182 expect(res.body.total).to.equal(2)
183
184 const blacklistedVideos = res.body.data
185 expect(blacklistedVideos).to.be.an('array')
186 expect(blacklistedVideos.length).to.equal(2)
187
188 const result = orderBy(res.body.data, [ 'createdAt' ])
189
190 expect(blacklistedVideos).to.deep.equal(result)
191 })
192 })
193
194 describe('When updating blacklisted videos', function () {
195 it('Should change the reason', async function () {
196 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
197
198 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' })
199 const video = res.body.data.find(b => b.video.id === videoId)
200
201 expect(video.reason).to.equal('my super reason updated')
202 })
203 })
204
205 describe('When listing my videos', function () {
206 it('Should display blacklisted videos', async function () {
207 await blacklistVideosOnServer(servers[1])
208
209 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
210
211 expect(res.body.total).to.equal(2)
212 expect(res.body.data).to.have.lengthOf(2)
213
214 for (const video of res.body.data) {
215 expect(video.blacklisted).to.be.true
216 expect(video.blacklistedReason).to.equal('super reason')
217 }
218 })
219 })
220
221 describe('When removing a blacklisted video', function () {
222 let videoToRemove: VideoBlacklist
223 let blacklist = []
224
225 it('Should not have any video in videos list on server 1', async function () {
226 const res = await getVideosList(servers[0].url)
227 expect(res.body.total).to.equal(0)
228 expect(res.body.data).to.be.an('array')
229 expect(res.body.data.length).to.equal(0)
230 })
231
232 it('Should remove a video from the blacklist on server 1', async function () {
233 // Get one video in the blacklist
234 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' })
235 videoToRemove = res.body.data[0]
236 blacklist = res.body.data.slice(1)
237
238 // Remove it
239 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
240 })
241
242 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
243 const res = await getVideosList(servers[0].url)
244 expect(res.body.total).to.equal(1)
245
246 const videos = res.body.data
247 expect(videos).to.be.an('array')
248 expect(videos.length).to.equal(1)
249
250 expect(videos[0].name).to.equal(videoToRemove.video.name)
251 expect(videos[0].id).to.equal(videoToRemove.video.id)
252 })
253
254 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
255 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' })
256 expect(res.body.total).to.equal(1)
257
258 const videos = res.body.data
259 expect(videos).to.be.an('array')
260 expect(videos.length).to.equal(1)
261 expect(videos).to.deep.equal(blacklist)
262 })
263 })
264
265 describe('When blacklisting local videos', function () {
266 let video3UUID: string
267 let video4UUID: string
268
269 before(async function () {
270 this.timeout(10000)
271
272 {
273 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' })
274 video3UUID = res.body.video.uuid
275 }
276 {
277 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' })
278 video4UUID = res.body.video.uuid
279 }
280
281 await waitJobs(servers)
282 })
283
284 it('Should blacklist video 3 and keep it federated', async function () {
285 this.timeout(10000)
286
287 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false)
288
289 await waitJobs(servers)
290
291 {
292 const res = await getVideosList(servers[0].url)
293 expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined
294 }
295
296 {
297 const res = await getVideosList(servers[1].url)
298 expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined
299 }
300 })
301
302 it('Should unfederate the video', async function () {
303 this.timeout(10000)
304
305 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true)
306
307 await waitJobs(servers)
308
309 for (const server of servers) {
310 const res = await getVideosList(server.url)
311 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
312 }
313 })
314
315 it('Should have the video unfederated even after an Update AP message', async function () {
316 this.timeout(10000)
317
318 await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' })
319
320 await waitJobs(servers)
321
322 for (const server of servers) {
323 const res = await getVideosList(server.url)
324 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
325 }
326 })
327
328 it('Should have the correct video blacklist unfederate attribute', async function () {
329 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' })
330
331 const blacklistedVideos: VideoBlacklist[] = res.body.data
332 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
333 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
334
335 expect(video3Blacklisted.unfederated).to.be.false
336 expect(video4Blacklisted.unfederated).to.be.true
337 })
338
339 it('Should remove the video from blacklist and refederate the video', async function () {
340 this.timeout(10000)
341
342 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID)
343
344 await waitJobs(servers)
345
346 for (const server of servers) {
347 const res = await getVideosList(server.url)
348 expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined
349 }
350 })
351
352 })
353
354 describe('When auto blacklist videos', function () {
355 let userWithoutFlag: string
356 let userWithFlag: string
357 let channelOfUserWithoutFlag: number
358
359 before(async function () {
360 this.timeout(20000)
361
362 killallServers([ servers[0] ])
363
364 const config = {
365 auto_blacklist: {
366 videos: {
367 of_users: {
368 enabled: true
369 }
370 }
371 }
372 }
373 await reRunServer(servers[0], config)
374
375 {
376 const user = { username: 'user_without_flag', password: 'password' }
377 await createUser({
378 url: servers[0].url,
379 accessToken: servers[0].accessToken,
380 username: user.username,
381 adminFlags: UserAdminFlag.NONE,
382 password: user.password,
383 role: UserRole.USER
384 })
385
386 userWithoutFlag = await userLogin(servers[0], user)
387
388 const res = await getMyUserInformation(servers[0].url, userWithoutFlag)
389 const body: User = res.body
390 channelOfUserWithoutFlag = body.videoChannels[0].id
391 }
392
393 {
394 const user = { username: 'user_with_flag', password: 'password' }
395 await createUser({
396 url: servers[0].url,
397 accessToken: servers[0].accessToken,
398 username: user.username,
399 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST,
400 password: user.password,
401 role: UserRole.USER
402 })
403
404 userWithFlag = await userLogin(servers[0], user)
405 }
406
407 await waitJobs(servers)
408 })
409
410 it('Should auto blacklist a video on upload', async function () {
411 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
412
413 const res = await getBlacklistedVideosList({
414 url: servers[0].url,
415 token: servers[0].accessToken,
416 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
417 })
418
419 expect(res.body.total).to.equal(1)
420 expect(res.body.data[0].video.name).to.equal('blacklisted')
421 })
422
423 it('Should auto blacklist a video on URL import', async function () {
424 this.timeout(15000)
425
426 const attributes = {
427 targetUrl: getGoodVideoUrl(),
428 name: 'URL import',
429 channelId: channelOfUserWithoutFlag
430 }
431 await importVideo(servers[0].url, userWithoutFlag, attributes)
432
433 const res = await getBlacklistedVideosList({
434 url: servers[0].url,
435 token: servers[0].accessToken,
436 sort: 'createdAt',
437 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
438 })
439
440 expect(res.body.total).to.equal(2)
441 expect(res.body.data[1].video.name).to.equal('URL import')
442 })
443
444 it('Should auto blacklist a video on torrent import', async function () {
445 const attributes = {
446 magnetUri: getMagnetURI(),
447 name: 'Torrent import',
448 channelId: channelOfUserWithoutFlag
449 }
450 await importVideo(servers[0].url, userWithoutFlag, attributes)
451
452 const res = await getBlacklistedVideosList({
453 url: servers[0].url,
454 token: servers[0].accessToken,
455 sort: 'createdAt',
456 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
457 })
458
459 expect(res.body.total).to.equal(3)
460 expect(res.body.data[2].video.name).to.equal('Torrent import')
461 })
462
463 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
464 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
465
466 const res = await getBlacklistedVideosList({
467 url: servers[0].url,
468 token: servers[0].accessToken,
469 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
470 })
471
472 expect(res.body.total).to.equal(3)
473 })
474 })
475
476 after(async function () {
477 await cleanupTests(servers)
478 })
479})