]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
0e1dc3e7 | 3 | import * as chai from 'chai' |
afffe988 | 4 | import 'mocha' |
268eebed | 5 | import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos' |
0e1dc3e7 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
268eebed | 8 | deleteVideoAbuse, |
0e1dc3e7 | 9 | flushAndRunMultipleServers, |
0e1dc3e7 | 10 | getVideoAbusesList, |
afffe988 | 11 | getVideosList, |
afffe988 C |
12 | reportVideoAbuse, |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
268eebed | 15 | updateVideoAbuse, |
3cd0734f | 16 | uploadVideo |
94565d52 C |
17 | } from '../../../../shared/extra-utils/index' |
18 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
f0a47bc9 C |
20 | import { |
21 | addAccountToServerBlocklist, | |
22 | addServerToServerBlocklist, | |
23 | removeAccountFromServerBlocklist, | |
24 | removeServerFromServerBlocklist | |
25 | } from '../../../../shared/extra-utils/users/blocklist' | |
afffe988 C |
26 | |
27 | const expect = chai.expect | |
0e1dc3e7 C |
28 | |
29 | describe('Test video abuses', function () { | |
30 | let servers: ServerInfo[] = [] | |
268eebed | 31 | let abuseServer2: VideoAbuse |
0e1dc3e7 C |
32 | |
33 | before(async function () { | |
572f8d3d | 34 | this.timeout(50000) |
0e1dc3e7 C |
35 | |
36 | // Run servers | |
37 | servers = await flushAndRunMultipleServers(2) | |
38 | ||
39 | // Get the access tokens | |
40 | await setAccessTokensToServers(servers) | |
41 | ||
afffe988 C |
42 | // Server 1 and server 2 follow each other |
43 | await doubleFollow(servers[0], servers[1]) | |
0e1dc3e7 | 44 | |
afffe988 | 45 | // Upload some videos on each servers |
0e1dc3e7 | 46 | const video1Attributes = { |
afffe988 C |
47 | name: 'my super name for server 1', |
48 | description: 'my super description for server 1' | |
0e1dc3e7 C |
49 | } |
50 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | |
51 | ||
52 | const video2Attributes = { | |
afffe988 C |
53 | name: 'my super name for server 2', |
54 | description: 'my super description for server 2' | |
0e1dc3e7 C |
55 | } |
56 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | |
57 | ||
572f8d3d | 58 | // Wait videos propagation, server 2 has transcoding enabled |
3cd0734f | 59 | await waitJobs(servers) |
0e1dc3e7 C |
60 | |
61 | const res = await getVideosList(servers[0].url) | |
62 | const videos = res.body.data | |
63 | ||
64 | expect(videos.length).to.equal(2) | |
65 | ||
afffe988 C |
66 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') |
67 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') | |
0e1dc3e7 C |
68 | }) |
69 | ||
70 | it('Should not have video abuses', async function () { | |
71 | const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | |
72 | ||
73 | expect(res.body.total).to.equal(0) | |
74 | expect(res.body.data).to.be.an('array') | |
75 | expect(res.body.data.length).to.equal(0) | |
76 | }) | |
77 | ||
78 | it('Should report abuse on a local video', async function () { | |
3cd0734f | 79 | this.timeout(15000) |
0e1dc3e7 C |
80 | |
81 | const reason = 'my super bad reason' | |
82 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) | |
83 | ||
afffe988 | 84 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 |
3cd0734f | 85 | await waitJobs(servers) |
0e1dc3e7 C |
86 | }) |
87 | ||
afffe988 | 88 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { |
0e1dc3e7 C |
89 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) |
90 | ||
91 | expect(res1.body.total).to.equal(1) | |
92 | expect(res1.body.data).to.be.an('array') | |
93 | expect(res1.body.data.length).to.equal(1) | |
94 | ||
19a3b914 | 95 | const abuse: VideoAbuse = res1.body.data[0] |
0e1dc3e7 | 96 | expect(abuse.reason).to.equal('my super bad reason') |
19a3b914 | 97 | expect(abuse.reporterAccount.name).to.equal('root') |
7243f84d | 98 | expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
19a3b914 | 99 | expect(abuse.video.id).to.equal(servers[0].video.id) |
0e1dc3e7 C |
100 | |
101 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
102 | expect(res2.body.total).to.equal(0) | |
103 | expect(res2.body.data).to.be.an('array') | |
104 | expect(res2.body.data.length).to.equal(0) | |
105 | }) | |
106 | ||
107 | it('Should report abuse on a remote video', async function () { | |
572f8d3d | 108 | this.timeout(10000) |
0e1dc3e7 C |
109 | |
110 | const reason = 'my super bad reason 2' | |
111 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) | |
112 | ||
113 | // We wait requests propagation | |
3cd0734f | 114 | await waitJobs(servers) |
0e1dc3e7 C |
115 | }) |
116 | ||
268eebed | 117 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { |
0e1dc3e7 C |
118 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) |
119 | expect(res1.body.total).to.equal(2) | |
120 | expect(res1.body.data).to.be.an('array') | |
121 | expect(res1.body.data.length).to.equal(2) | |
122 | ||
19a3b914 | 123 | const abuse1: VideoAbuse = res1.body.data[0] |
0e1dc3e7 | 124 | expect(abuse1.reason).to.equal('my super bad reason') |
19a3b914 | 125 | expect(abuse1.reporterAccount.name).to.equal('root') |
7243f84d | 126 | expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
19a3b914 | 127 | expect(abuse1.video.id).to.equal(servers[0].video.id) |
268eebed C |
128 | expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING) |
129 | expect(abuse1.state.label).to.equal('Pending') | |
130 | expect(abuse1.moderationComment).to.be.null | |
0e1dc3e7 | 131 | |
19a3b914 | 132 | const abuse2: VideoAbuse = res1.body.data[1] |
0e1dc3e7 | 133 | expect(abuse2.reason).to.equal('my super bad reason 2') |
19a3b914 | 134 | expect(abuse2.reporterAccount.name).to.equal('root') |
7243f84d | 135 | expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
19a3b914 | 136 | expect(abuse2.video.id).to.equal(servers[1].video.id) |
268eebed C |
137 | expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING) |
138 | expect(abuse2.state.label).to.equal('Pending') | |
139 | expect(abuse2.moderationComment).to.be.null | |
0e1dc3e7 C |
140 | |
141 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
142 | expect(res2.body.total).to.equal(1) | |
143 | expect(res2.body.data).to.be.an('array') | |
144 | expect(res2.body.data.length).to.equal(1) | |
145 | ||
268eebed C |
146 | abuseServer2 = res2.body.data[0] |
147 | expect(abuseServer2.reason).to.equal('my super bad reason 2') | |
148 | expect(abuseServer2.reporterAccount.name).to.equal('root') | |
7243f84d | 149 | expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
268eebed C |
150 | expect(abuseServer2.state.id).to.equal(VideoAbuseState.PENDING) |
151 | expect(abuseServer2.state.label).to.equal('Pending') | |
152 | expect(abuseServer2.moderationComment).to.be.null | |
153 | }) | |
154 | ||
155 | it('Should update the state of a video abuse', async function () { | |
156 | const body = { state: VideoAbuseState.REJECTED } | |
157 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) | |
158 | ||
159 | const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
160 | expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED) | |
161 | }) | |
162 | ||
163 | it('Should add a moderation comment', async function () { | |
164 | const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' } | |
165 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) | |
166 | ||
167 | const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
168 | expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED) | |
169 | expect(res.body.data[0].moderationComment).to.equal('It is valid') | |
170 | }) | |
171 | ||
f0a47bc9 C |
172 | it('Should hide video abuses from blocked accounts', async function () { |
173 | this.timeout(10000) | |
174 | ||
175 | { | |
176 | await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this') | |
177 | await waitJobs(servers) | |
178 | ||
179 | const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | |
180 | expect(res.body.total).to.equal(3) | |
181 | } | |
182 | ||
183 | const accountToBlock = 'root@localhost:' + servers[1].port | |
184 | ||
185 | { | |
186 | await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, accountToBlock) | |
187 | ||
188 | const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken) | |
189 | expect(res.body.total).to.equal(2) | |
190 | ||
191 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | |
192 | expect(abuse).to.be.undefined | |
193 | } | |
194 | ||
195 | { | |
196 | await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, accountToBlock) | |
197 | ||
198 | const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken) | |
199 | expect(res.body.total).to.equal(3) | |
200 | } | |
201 | }) | |
202 | ||
203 | it('Should hide video abuses from blocked servers', async function () { | |
204 | const serverToBlock = servers[1].host | |
205 | ||
206 | { | |
207 | await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, servers[1].host) | |
208 | ||
209 | const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken) | |
210 | expect(res.body.total).to.equal(2) | |
211 | ||
212 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | |
213 | expect(abuse).to.be.undefined | |
214 | } | |
215 | ||
216 | { | |
217 | await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, serverToBlock) | |
218 | ||
219 | const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken) | |
220 | expect(res.body.total).to.equal(3) | |
221 | } | |
222 | }) | |
223 | ||
268eebed | 224 | it('Should delete the video abuse', async function () { |
f0a47bc9 C |
225 | this.timeout(10000) |
226 | ||
268eebed C |
227 | await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id) |
228 | ||
f0a47bc9 C |
229 | await waitJobs(servers) |
230 | ||
231 | { | |
232 | const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
233 | expect(res.body.total).to.equal(1) | |
234 | expect(res.body.data.length).to.equal(1) | |
235 | expect(res.body.data[0].id).to.not.equal(abuseServer2.id) | |
236 | } | |
237 | ||
238 | { | |
239 | const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | |
240 | expect(res.body.total).to.equal(3) | |
241 | } | |
0e1dc3e7 C |
242 | }) |
243 | ||
7c3b7976 C |
244 | after(async function () { |
245 | await cleanupTests(servers) | |
0e1dc3e7 C |
246 | }) |
247 | }) |