]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/video-abuse.js
871054788dec75f121f0671389c18d94867a5af4
1 /* eslint-disable no-unused-expressions */
5 const chai
= require('chai')
6 const each
= require('async/each')
7 const expect
= chai
.expect
8 const series
= require('async/series')
10 const loginUtils
= require('../utils/login')
11 const podsUtils
= require('../utils/pods')
12 const serversUtils
= require('../utils/servers')
13 const videosUtils
= require('../utils/videos')
14 const videoAbusesUtils
= require('../utils/video-abuses')
16 describe('Test video abuses', function () {
19 before(function (done
) {
25 serversUtils
.flushAndRunMultipleServers(2, function (serversRun
) {
30 // Get the access tokens
32 each(servers
, function (server
, callbackEach
) {
33 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
34 if (err
) return callbackEach(err
)
36 server
.accessToken
= accessToken
41 // Pod 1 make friends too
43 const server
= servers
[0]
44 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
46 // Upload some videos on each pods
48 const name
= 'my super name for pod 1'
50 const description
= 'my super description for pod 1'
51 const tags
= [ 'tag' ]
52 const file
= 'video_short2.webm'
53 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, category
, description
, tags
, file
, next
)
56 const name
= 'my super name for pod 2'
58 const description
= 'my super description for pod 2'
59 const tags
= [ 'tag' ]
60 const file
= 'video_short2.webm'
61 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, category
, description
, tags
, file
, next
)
63 // Wait videos propagation
65 setTimeout(next
, 11000)
68 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
71 const videos
= res
.body
.data
73 expect(videos
.length
).to
.equal(2)
75 servers
[0].video
= videos
.find(function (video
) { return video
.name
=== 'my super name for pod 1' })
76 servers
[1].video
= videos
.find(function (video
) { return video
.name
=== 'my super name for pod 2' })
84 it('Should not have video abuses', function (done
) {
85 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
88 expect(res
.body
.total
).to
.equal(0)
89 expect(res
.body
.data
).to
.be
.an('array')
90 expect(res
.body
.data
.length
).to
.equal(0)
96 it('Should report abuse on a local video', function (done
) {
99 const reason
= 'my super bad reason'
100 videoAbusesUtils
.reportVideoAbuse(servers
[0].url
, servers
[0].accessToken
, servers
[0].video
.id
, reason
, function (err
) {
103 // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2
104 setTimeout(done
, 11000)
108 it('Should have 1 video abuses on pod 1 and 0 on pod 2', function (done
) {
109 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
112 expect(res
.body
.total
).to
.equal(1)
113 expect(res
.body
.data
).to
.be
.an('array')
114 expect(res
.body
.data
.length
).to
.equal(1)
116 const abuse
= res
.body
.data
[0]
117 expect(abuse
.reason
).to
.equal('my super bad reason')
118 expect(abuse
.reporterUsername
).to
.equal('root')
119 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
120 expect(abuse
.videoId
).to
.equal(servers
[0].video
.id
)
122 videoAbusesUtils
.getVideoAbusesList(servers
[1].url
, servers
[1].accessToken
, function (err
, res
) {
125 expect(res
.body
.total
).to
.equal(0)
126 expect(res
.body
.data
).to
.be
.an('array')
127 expect(res
.body
.data
.length
).to
.equal(0)
134 it('Should report abuse on a remote video', function (done
) {
137 const reason
= 'my super bad reason 2'
138 videoAbusesUtils
.reportVideoAbuse(servers
[0].url
, servers
[0].accessToken
, servers
[1].video
.id
, reason
, function (err
) {
141 // We wait requests propagation
142 setTimeout(done
, 11000)
146 it('Should have 2 video abuse on pod 1 and 1 on pod 2', function (done
) {
147 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
150 expect(res
.body
.total
).to
.equal(2)
151 expect(res
.body
.data
).to
.be
.an('array')
152 expect(res
.body
.data
.length
).to
.equal(2)
154 let abuse
= res
.body
.data
[0]
155 expect(abuse
.reason
).to
.equal('my super bad reason')
156 expect(abuse
.reporterUsername
).to
.equal('root')
157 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
158 expect(abuse
.videoId
).to
.equal(servers
[0].video
.id
)
160 abuse
= res
.body
.data
[1]
161 expect(abuse
.reason
).to
.equal('my super bad reason 2')
162 expect(abuse
.reporterUsername
).to
.equal('root')
163 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
164 expect(abuse
.videoId
).to
.equal(servers
[1].video
.id
)
166 videoAbusesUtils
.getVideoAbusesList(servers
[1].url
, servers
[1].accessToken
, function (err
, res
) {
169 expect(res
.body
.total
).to
.equal(1)
170 expect(res
.body
.data
).to
.be
.an('array')
171 expect(res
.body
.data
.length
).to
.equal(1)
173 let abuse
= res
.body
.data
[0]
174 expect(abuse
.reason
).to
.equal('my super bad reason 2')
175 expect(abuse
.reporterUsername
).to
.equal('root')
176 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
183 after(function (done
) {
184 servers
.forEach(function (server
) {
185 process
.kill(-server
.app
.pid
)
188 // Keep the logs if the test failed
190 serversUtils
.flushTests(done
)