]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/video-abuse.js
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 makes friend with pod 2
43 const server
= servers
[0]
44 podsUtils
.makeFriends(server
.url
, server
.accessToken
, next
)
46 // Upload some videos on each pods
48 const videoAttributes
= {
49 name: 'my super name for pod 1',
50 description: 'my super description for pod 1'
52 videosUtils
.uploadVideo(servers
[0].url
, servers
[0].accessToken
, videoAttributes
, next
)
55 const videoAttributes
= {
56 name: 'my super name for pod 2',
57 description: 'my super description for pod 2'
59 videosUtils
.uploadVideo(servers
[1].url
, servers
[1].accessToken
, videoAttributes
, next
)
61 // Wait videos propagation
63 setTimeout(next
, 22000)
66 videosUtils
.getVideosList(servers
[0].url
, function (err
, res
) {
69 const videos
= res
.body
.data
71 expect(videos
.length
).to
.equal(2)
73 servers
[0].video
= videos
.find(function (video
) { return video
.name
=== 'my super name for pod 1' })
74 servers
[1].video
= videos
.find(function (video
) { return video
.name
=== 'my super name for pod 2' })
82 it('Should not have video abuses', function (done
) {
83 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
86 expect(res
.body
.total
).to
.equal(0)
87 expect(res
.body
.data
).to
.be
.an('array')
88 expect(res
.body
.data
.length
).to
.equal(0)
94 it('Should report abuse on a local video', function (done
) {
97 const reason
= 'my super bad reason'
98 videoAbusesUtils
.reportVideoAbuse(servers
[0].url
, servers
[0].accessToken
, servers
[0].video
.id
, reason
, function (err
) {
101 // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2
102 setTimeout(done
, 11000)
106 it('Should have 1 video abuses on pod 1 and 0 on pod 2', function (done
) {
107 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
110 expect(res
.body
.total
).to
.equal(1)
111 expect(res
.body
.data
).to
.be
.an('array')
112 expect(res
.body
.data
.length
).to
.equal(1)
114 const abuse
= res
.body
.data
[0]
115 expect(abuse
.reason
).to
.equal('my super bad reason')
116 expect(abuse
.reporterUsername
).to
.equal('root')
117 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
118 expect(abuse
.videoId
).to
.equal(servers
[0].video
.id
)
120 videoAbusesUtils
.getVideoAbusesList(servers
[1].url
, servers
[1].accessToken
, function (err
, res
) {
123 expect(res
.body
.total
).to
.equal(0)
124 expect(res
.body
.data
).to
.be
.an('array')
125 expect(res
.body
.data
.length
).to
.equal(0)
132 it('Should report abuse on a remote video', function (done
) {
135 const reason
= 'my super bad reason 2'
136 videoAbusesUtils
.reportVideoAbuse(servers
[0].url
, servers
[0].accessToken
, servers
[1].video
.id
, reason
, function (err
) {
139 // We wait requests propagation
140 setTimeout(done
, 11000)
144 it('Should have 2 video abuse on pod 1 and 1 on pod 2', function (done
) {
145 videoAbusesUtils
.getVideoAbusesList(servers
[0].url
, servers
[0].accessToken
, function (err
, res
) {
148 expect(res
.body
.total
).to
.equal(2)
149 expect(res
.body
.data
).to
.be
.an('array')
150 expect(res
.body
.data
.length
).to
.equal(2)
152 let abuse
= res
.body
.data
[0]
153 expect(abuse
.reason
).to
.equal('my super bad reason')
154 expect(abuse
.reporterUsername
).to
.equal('root')
155 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
156 expect(abuse
.videoId
).to
.equal(servers
[0].video
.id
)
158 abuse
= res
.body
.data
[1]
159 expect(abuse
.reason
).to
.equal('my super bad reason 2')
160 expect(abuse
.reporterUsername
).to
.equal('root')
161 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
162 expect(abuse
.videoId
).to
.equal(servers
[1].video
.id
)
164 videoAbusesUtils
.getVideoAbusesList(servers
[1].url
, servers
[1].accessToken
, function (err
, res
) {
167 expect(res
.body
.total
).to
.equal(1)
168 expect(res
.body
.data
).to
.be
.an('array')
169 expect(res
.body
.data
.length
).to
.equal(1)
171 let abuse
= res
.body
.data
[0]
172 expect(abuse
.reason
).to
.equal('my super bad reason 2')
173 expect(abuse
.reporterUsername
).to
.equal('root')
174 expect(abuse
.reporterPodHost
).to
.equal('localhost:9001')
181 after(function (done
) {
182 servers
.forEach(function (server
) {
183 process
.kill(-server
.app
.pid
)
186 // Keep the logs if the test failed
188 serversUtils
.flushTests(done
)