]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/video-abuse.js
3 const chai
= require('chai')
4 const each
= require('async/each')
5 const expect
= chai
.expect
6 const series
= require('async/series')
8 const loginUtils
= require('../utils/login')
9 const podsUtils
= require('../utils/pods')
10 const serversUtils
= require('../utils/servers')
11 const videosUtils
= require('../utils/videos')
12 const videoAbusesUtils
= require('../utils/video-abuses')
14 describe('Test video abuses', function () {
17 before(function (done
) {
23 serversUtils
.flushAndRunMultipleServers(2, function (serversRun
) {
28 // Get the access tokens
30 each(servers
, function (server
, callbackEach
) {
31 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
32 if (err
) return callbackEach(err
)
34 server
.accessToken
= accessToken
39 // Pod 1 make friends too
41 const server
= servers
[0]
42 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
44 // Upload some videos on each pods
46 const name
= 'my super name for pod 1'
47 const description
= 'my super description for pod 1'
48 const tags
= [ 'tag' ]
49 const file
= 'video_short2.webm'
50 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, name
, description
, tags
, file
, next
)
53 const name
= 'my super name for pod 2'
54 const description
= 'my super description for pod 2'
55 const tags
= [ 'tag' ]
56 const file
= 'video_short2.webm'
57 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, name
, description
, tags
, file
, next
)
59 // Wait videos propagation
61 setTimeout(next
, 11000)
64 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
67 const videos
= res
.body
.data
69 expect(videos
.length
).to
.equal(2)
71 servers
[0].video
= videos
.find(function (video
) { return video
.name
=== 'my super name for pod 1' })
72 servers
[1].video
= videos
.find(function (video
) { return video
.name
=== 'my super name for pod 2' })
80 it('Should not have video abuses', function (done
) {
81 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
84 expect(res
.body
.total
).to
.equal(0)
85 expect(res
.body
.data
).to
.be
.an('array')
86 expect(res
.body
.data
.length
).to
.equal(0)
92 it('Should report abuse on a local video', function (done
) {
95 const reason
= 'my super bad reason'
96 videoAbusesUtils
.reportVideoAbuse(servers
[0].url
, servers
[0].accessToken
, servers
[0].video
.id
, reason
, function (err
) {
99 // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2
100 setTimeout(done
, 11000)
104 it('Should have 1 video abuses on pod 1 and 0 on pod 2', function (done
) {
105 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
108 expect(res
.body
.total
).to
.equal(1)
109 expect(res
.body
.data
).to
.be
.an('array')
110 expect(res
.body
.data
.length
).to
.equal(1)
112 const abuse
= res
.body
.data
[0]
113 expect(abuse
.reason
).to
.equal('my super bad reason')
114 expect(abuse
.reporterUsername
).to
.equal('root')
115 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
116 expect(abuse
.videoId
).to
.equal(servers
[0].video
.id
)
118 videoAbusesUtils
.getVideoAbusesList(servers
[1].url
, servers
[1].accessToken
, function (err
, res
) {
121 expect(res
.body
.total
).to
.equal(0)
122 expect(res
.body
.data
).to
.be
.an('array')
123 expect(res
.body
.data
.length
).to
.equal(0)
130 it('Should report abuse on a remote video', function (done
) {
133 const reason
= 'my super bad reason 2'
134 videoAbusesUtils
.reportVideoAbuse(servers
[0].url
, servers
[0].accessToken
, servers
[1].video
.id
, reason
, function (err
) {
137 // We wait requests propagation
138 setTimeout(done
, 11000)
142 it('Should have 2 video abuse on pod 1 and 1 on pod 2', function (done
) {
143 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
146 expect(res
.body
.total
).to
.equal(2)
147 expect(res
.body
.data
).to
.be
.an('array')
148 expect(res
.body
.data
.length
).to
.equal(2)
150 let abuse
= res
.body
.data
[0]
151 expect(abuse
.reason
).to
.equal('my super bad reason')
152 expect(abuse
.reporterUsername
).to
.equal('root')
153 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
154 expect(abuse
.videoId
).to
.equal(servers
[0].video
.id
)
156 abuse
= res
.body
.data
[1]
157 expect(abuse
.reason
).to
.equal('my super bad reason 2')
158 expect(abuse
.reporterUsername
).to
.equal('root')
159 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
160 expect(abuse
.videoId
).to
.equal(servers
[1].video
.id
)
162 videoAbusesUtils
.getVideoAbusesList(servers
[1].url
, servers
[1].accessToken
, function (err
, res
) {
165 expect(res
.body
.total
).to
.equal(1)
166 expect(res
.body
.data
).to
.be
.an('array')
167 expect(res
.body
.data
.length
).to
.equal(1)
169 let abuse
= res
.body
.data
[0]
170 expect(abuse
.reason
).to
.equal('my super bad reason 2')
171 expect(abuse
.reporterUsername
).to
.equal('root')
172 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
179 after(function (done
) {
180 servers
.forEach(function (server
) {
181 process
.kill(-server
.app
.pid
)
184 // Keep the logs if the test failed
186 serversUtils
.flushTests(done
)