aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-08 11:17:55 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commite3d15a6a9aed97a004d9dac1b7a6499d794e080a (patch)
tree7637ac85a8659a66a1290c9533e0206e9a0c5a30 /server/tests/api/moderation
parenta1637fa1e25b60a88f7cfe50aac8953f50d55761 (diff)
downloadPeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.tar.gz
PeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.tar.zst
PeerTube-e3d15a6a9aed97a004d9dac1b7a6499d794e080a.zip
Introduce blacklist command
Diffstat (limited to 'server/tests/api/moderation')
-rw-r--r--server/tests/api/moderation/video-blacklist.ts144
1 files changed, 54 insertions, 90 deletions
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index 4a4930c98..17a68e4a6 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -4,22 +4,19 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { orderBy } from 'lodash' 5import { orderBy } from 'lodash'
6import { 6import {
7 addVideoToBlacklist, 7 BlacklistCommand,
8 cleanupTests, 8 cleanupTests,
9 createUser, 9 createUser,
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 getBlacklistedVideosList,
13 getMyUserInformation, 12 getMyUserInformation,
14 getMyVideos, 13 getMyVideos,
15 getVideosList, 14 getVideosList,
16 killallServers, 15 killallServers,
17 removeVideoFromBlacklist,
18 reRunServer, 16 reRunServer,
19 ServerInfo, 17 ServerInfo,
20 setAccessTokensToServers, 18 setAccessTokensToServers,
21 updateVideo, 19 updateVideo,
22 updateVideoBlacklist,
23 uploadVideo, 20 uploadVideo,
24 userLogin, 21 userLogin,
25 waitJobs 22 waitJobs
@@ -32,13 +29,14 @@ const expect = chai.expect
32describe('Test video blacklist', function () { 29describe('Test video blacklist', function () {
33 let servers: ServerInfo[] = [] 30 let servers: ServerInfo[] = []
34 let videoId: number 31 let videoId: number
32 let command: BlacklistCommand
35 33
36 async function blacklistVideosOnServer (server: ServerInfo) { 34 async function blacklistVideosOnServer (server: ServerInfo) {
37 const res = await getVideosList(server.url) 35 const res = await getVideosList(server.url)
38 36
39 const videos = res.body.data 37 const videos = res.body.data
40 for (const video of videos) { 38 for (const video of videos) {
41 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') 39 await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' })
42 } 40 }
43 } 41 }
44 42
@@ -61,6 +59,8 @@ describe('Test video blacklist', function () {
61 // Wait videos propagation, server 2 has transcoding enabled 59 // Wait videos propagation, server 2 has transcoding enabled
62 await waitJobs(servers) 60 await waitJobs(servers)
63 61
62 command = servers[0].blacklistCommand
63
64 // Blacklist the two videos on server 1 64 // Blacklist the two videos on server 1
65 await blacklistVideosOnServer(servers[0]) 65 await blacklistVideosOnServer(servers[0])
66 }) 66 })
@@ -77,7 +77,7 @@ describe('Test video blacklist', function () {
77 } 77 }
78 78
79 { 79 {
80 const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) 80 const body = await servers[0].searchCommand.searchVideos({ search: 'video' })
81 81
82 expect(body.total).to.equal(0) 82 expect(body.total).to.equal(0)
83 expect(body.data).to.be.an('array') 83 expect(body.data).to.be.an('array')
@@ -95,7 +95,7 @@ describe('Test video blacklist', function () {
95 } 95 }
96 96
97 { 97 {
98 const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) 98 const body = await servers[1].searchCommand.searchVideos({ search: 'video' })
99 99
100 expect(body.total).to.equal(2) 100 expect(body.total).to.equal(2)
101 expect(body.data).to.be.an('array') 101 expect(body.data).to.be.an('array')
@@ -106,11 +106,10 @@ describe('Test video blacklist', function () {
106 106
107 describe('When listing manually blacklisted videos', function () { 107 describe('When listing manually blacklisted videos', function () {
108 it('Should display all the blacklisted videos', async function () { 108 it('Should display all the blacklisted videos', async function () {
109 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) 109 const body = await command.list()
110 110 expect(body.total).to.equal(2)
111 expect(res.body.total).to.equal(2)
112 111
113 const blacklistedVideos = res.body.data 112 const blacklistedVideos = body.data
114 expect(blacklistedVideos).to.be.an('array') 113 expect(blacklistedVideos).to.be.an('array')
115 expect(blacklistedVideos.length).to.equal(2) 114 expect(blacklistedVideos.length).to.equal(2)
116 115
@@ -121,79 +120,66 @@ describe('Test video blacklist', function () {
121 }) 120 })
122 121
123 it('Should display all the blacklisted videos when applying manual type filter', async function () { 122 it('Should display all the blacklisted videos when applying manual type filter', async function () {
124 const res = await getBlacklistedVideosList({ 123 const body = await command.list({ type: VideoBlacklistType.MANUAL })
125 url: servers[0].url, 124 expect(body.total).to.equal(2)
126 token: servers[0].accessToken,
127 type: VideoBlacklistType.MANUAL
128 })
129 125
130 expect(res.body.total).to.equal(2) 126 const blacklistedVideos = body.data
131
132 const blacklistedVideos = res.body.data
133 expect(blacklistedVideos).to.be.an('array') 127 expect(blacklistedVideos).to.be.an('array')
134 expect(blacklistedVideos.length).to.equal(2) 128 expect(blacklistedVideos.length).to.equal(2)
135 }) 129 })
136 130
137 it('Should display nothing when applying automatic type filter', async function () { 131 it('Should display nothing when applying automatic type filter', async function () {
138 const res = await getBlacklistedVideosList({ 132 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
139 url: servers[0].url, 133 expect(body.total).to.equal(0)
140 token: servers[0].accessToken,
141 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
142 })
143 134
144 expect(res.body.total).to.equal(0) 135 const blacklistedVideos = body.data
145
146 const blacklistedVideos = res.body.data
147 expect(blacklistedVideos).to.be.an('array') 136 expect(blacklistedVideos).to.be.an('array')
148 expect(blacklistedVideos.length).to.equal(0) 137 expect(blacklistedVideos.length).to.equal(0)
149 }) 138 })
150 139
151 it('Should get the correct sort when sorting by descending id', async function () { 140 it('Should get the correct sort when sorting by descending id', async function () {
152 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' }) 141 const body = await command.list({ sort: '-id' })
153 expect(res.body.total).to.equal(2) 142 expect(body.total).to.equal(2)
154 143
155 const blacklistedVideos = res.body.data 144 const blacklistedVideos = body.data
156 expect(blacklistedVideos).to.be.an('array') 145 expect(blacklistedVideos).to.be.an('array')
157 expect(blacklistedVideos.length).to.equal(2) 146 expect(blacklistedVideos.length).to.equal(2)
158 147
159 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) 148 const result = orderBy(body.data, [ 'id' ], [ 'desc' ])
160
161 expect(blacklistedVideos).to.deep.equal(result) 149 expect(blacklistedVideos).to.deep.equal(result)
162 }) 150 })
163 151
164 it('Should get the correct sort when sorting by descending video name', async function () { 152 it('Should get the correct sort when sorting by descending video name', async function () {
165 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 153 const body = await command.list({ sort: '-name' })
166 expect(res.body.total).to.equal(2) 154 expect(body.total).to.equal(2)
167 155
168 const blacklistedVideos = res.body.data 156 const blacklistedVideos = body.data
169 expect(blacklistedVideos).to.be.an('array') 157 expect(blacklistedVideos).to.be.an('array')
170 expect(blacklistedVideos.length).to.equal(2) 158 expect(blacklistedVideos.length).to.equal(2)
171 159
172 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) 160 const result = orderBy(body.data, [ 'name' ], [ 'desc' ])
173
174 expect(blacklistedVideos).to.deep.equal(result) 161 expect(blacklistedVideos).to.deep.equal(result)
175 }) 162 })
176 163
177 it('Should get the correct sort when sorting by ascending creation date', async function () { 164 it('Should get the correct sort when sorting by ascending creation date', async function () {
178 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) 165 const body = await command.list({ sort: 'createdAt' })
179 expect(res.body.total).to.equal(2) 166 expect(body.total).to.equal(2)
180 167
181 const blacklistedVideos = res.body.data 168 const blacklistedVideos = body.data
182 expect(blacklistedVideos).to.be.an('array') 169 expect(blacklistedVideos).to.be.an('array')
183 expect(blacklistedVideos.length).to.equal(2) 170 expect(blacklistedVideos.length).to.equal(2)
184 171
185 const result = orderBy(res.body.data, [ 'createdAt' ]) 172 const result = orderBy(body.data, [ 'createdAt' ])
186
187 expect(blacklistedVideos).to.deep.equal(result) 173 expect(blacklistedVideos).to.deep.equal(result)
188 }) 174 })
189 }) 175 })
190 176
191 describe('When updating blacklisted videos', function () { 177 describe('When updating blacklisted videos', function () {
192 it('Should change the reason', async function () { 178 it('Should change the reason', async function () {
193 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') 179 await command.update({ videoId, reason: 'my super reason updated' })
194 180
195 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 181 const body = await command.list({ sort: '-name' })
196 const video = res.body.data.find(b => b.video.id === videoId) 182 const video = body.data.find(b => b.video.id === videoId)
197 183
198 expect(video.reason).to.equal('my super reason updated') 184 expect(video.reason).to.equal('my super reason updated')
199 }) 185 })
@@ -228,12 +214,12 @@ describe('Test video blacklist', function () {
228 214
229 it('Should remove a video from the blacklist on server 1', async function () { 215 it('Should remove a video from the blacklist on server 1', async function () {
230 // Get one video in the blacklist 216 // Get one video in the blacklist
231 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 217 const body = await command.list({ sort: '-name' })
232 videoToRemove = res.body.data[0] 218 videoToRemove = body.data[0]
233 blacklist = res.body.data.slice(1) 219 blacklist = body.data.slice(1)
234 220
235 // Remove it 221 // Remove it
236 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) 222 await command.remove({ videoId: videoToRemove.video.id })
237 }) 223 })
238 224
239 it('Should have the ex-blacklisted video in videos list on server 1', async function () { 225 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
@@ -249,10 +235,10 @@ describe('Test video blacklist', function () {
249 }) 235 })
250 236
251 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 237 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
252 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 238 const body = await command.list({ sort: '-name' })
253 expect(res.body.total).to.equal(1) 239 expect(body.total).to.equal(1)
254 240
255 const videos = res.body.data 241 const videos = body.data
256 expect(videos).to.be.an('array') 242 expect(videos).to.be.an('array')
257 expect(videos.length).to.equal(1) 243 expect(videos.length).to.equal(1)
258 expect(videos).to.deep.equal(blacklist) 244 expect(videos).to.deep.equal(blacklist)
@@ -281,7 +267,7 @@ describe('Test video blacklist', function () {
281 it('Should blacklist video 3 and keep it federated', async function () { 267 it('Should blacklist video 3 and keep it federated', async function () {
282 this.timeout(10000) 268 this.timeout(10000)
283 269
284 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false) 270 await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false })
285 271
286 await waitJobs(servers) 272 await waitJobs(servers)
287 273
@@ -299,7 +285,7 @@ describe('Test video blacklist', function () {
299 it('Should unfederate the video', async function () { 285 it('Should unfederate the video', async function () {
300 this.timeout(10000) 286 this.timeout(10000)
301 287
302 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true) 288 await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true })
303 289
304 await waitJobs(servers) 290 await waitJobs(servers)
305 291
@@ -323,9 +309,9 @@ describe('Test video blacklist', function () {
323 }) 309 })
324 310
325 it('Should have the correct video blacklist unfederate attribute', async function () { 311 it('Should have the correct video blacklist unfederate attribute', async function () {
326 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) 312 const body = await command.list({ sort: 'createdAt' })
327 313
328 const blacklistedVideos: VideoBlacklist[] = res.body.data 314 const blacklistedVideos = body.data
329 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) 315 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
330 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) 316 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
331 317
@@ -336,7 +322,7 @@ describe('Test video blacklist', function () {
336 it('Should remove the video from blacklist and refederate the video', async function () { 322 it('Should remove the video from blacklist and refederate the video', async function () {
337 this.timeout(10000) 323 this.timeout(10000)
338 324
339 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID) 325 await command.remove({ videoId: video4UUID })
340 326
341 await waitJobs(servers) 327 await waitJobs(servers)
342 328
@@ -407,14 +393,9 @@ describe('Test video blacklist', function () {
407 it('Should auto blacklist a video on upload', async function () { 393 it('Should auto blacklist a video on upload', async function () {
408 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) 394 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
409 395
410 const res = await getBlacklistedVideosList({ 396 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
411 url: servers[0].url, 397 expect(body.total).to.equal(1)
412 token: servers[0].accessToken, 398 expect(body.data[0].video.name).to.equal('blacklisted')
413 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
414 })
415
416 expect(res.body.total).to.equal(1)
417 expect(res.body.data[0].video.name).to.equal('blacklisted')
418 }) 399 })
419 400
420 it('Should auto blacklist a video on URL import', async function () { 401 it('Should auto blacklist a video on URL import', async function () {
@@ -427,15 +408,9 @@ describe('Test video blacklist', function () {
427 } 408 }
428 await importVideo(servers[0].url, userWithoutFlag, attributes) 409 await importVideo(servers[0].url, userWithoutFlag, attributes)
429 410
430 const res = await getBlacklistedVideosList({ 411 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
431 url: servers[0].url, 412 expect(body.total).to.equal(2)
432 token: servers[0].accessToken, 413 expect(body.data[1].video.name).to.equal('URL import')
433 sort: 'createdAt',
434 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
435 })
436
437 expect(res.body.total).to.equal(2)
438 expect(res.body.data[1].video.name).to.equal('URL import')
439 }) 414 })
440 415
441 it('Should auto blacklist a video on torrent import', async function () { 416 it('Should auto blacklist a video on torrent import', async function () {
@@ -446,27 +421,16 @@ describe('Test video blacklist', function () {
446 } 421 }
447 await importVideo(servers[0].url, userWithoutFlag, attributes) 422 await importVideo(servers[0].url, userWithoutFlag, attributes)
448 423
449 const res = await getBlacklistedVideosList({ 424 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
450 url: servers[0].url, 425 expect(body.total).to.equal(3)
451 token: servers[0].accessToken, 426 expect(body.data[2].video.name).to.equal('Torrent import')
452 sort: 'createdAt',
453 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
454 })
455
456 expect(res.body.total).to.equal(3)
457 expect(res.body.data[2].video.name).to.equal('Torrent import')
458 }) 427 })
459 428
460 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { 429 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
461 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) 430 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
462 431
463 const res = await getBlacklistedVideosList({ 432 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
464 url: servers[0].url, 433 expect(body.total).to.equal(3)
465 token: servers[0].accessToken,
466 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
467 })
468
469 expect(res.body.total).to.equal(3)
470 }) 434 })
471 }) 435 })
472 436