1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/* eslint-disable no-unused-expressions */
'use strict'
const chai = require('chai')
const each = require('async/each')
const expect = chai.expect
const series = require('async/series')
const loginUtils = require('../utils/login')
const podsUtils = require('../utils/pods')
const serversUtils = require('../utils/servers')
const videosUtils = require('../utils/videos')
const videoAbusesUtils = require('../utils/video-abuses')
describe('Test video abuses', function () {
let servers = []
before(function (done) {
this.timeout(30000)
series([
// Run servers
function (next) {
serversUtils.flushAndRunMultipleServers(2, function (serversRun) {
servers = serversRun
next()
})
},
// Get the access tokens
function (next) {
each(servers, function (server, callbackEach) {
loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
if (err) return callbackEach(err)
server.accessToken = accessToken
callbackEach()
})
}, next)
},
// Pod 1 make friends too
function (next) {
const server = servers[0]
podsUtils.makeFriends(server.url, server.accessToken, next)
},
// Upload some videos on each pods
function (next) {
const name = 'my super name for pod 1'
const description = 'my super description for pod 1'
const tags = [ 'tag' ]
const file = 'video_short2.webm'
videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
},
function (next) {
const name = 'my super name for pod 2'
const description = 'my super description for pod 2'
const tags = [ 'tag' ]
const file = 'video_short2.webm'
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
},
// Wait videos propagation
function (next) {
setTimeout(next, 11000)
},
function (next) {
videosUtils.getVideosList(servers[0].url, function (err, res) {
if (err) throw err
const videos = res.body.data
expect(videos.length).to.equal(2)
servers[0].video = videos.find(function (video) { return video.name === 'my super name for pod 1' })
servers[1].video = videos.find(function (video) { return video.name === 'my super name for pod 2' })
next()
})
}
], done)
})
it('Should not have video abuses', function (done) {
videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(0)
done()
})
})
it('Should report abuse on a local video', function (done) {
this.timeout(15000)
const reason = 'my super bad reason'
videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason, function (err) {
if (err) throw err
// We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2
setTimeout(done, 11000)
})
})
it('Should have 1 video abuses on pod 1 and 0 on pod 2', function (done) {
videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(1)
const abuse = res.body.data[0]
expect(abuse.reason).to.equal('my super bad reason')
expect(abuse.reporterUsername).to.equal('root')
expect(abuse.reporterPodHost).to.equal('localhost:9001')
expect(abuse.videoId).to.equal(servers[0].video.id)
videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(0)
done()
})
})
})
it('Should report abuse on a remote video', function (done) {
this.timeout(15000)
const reason = 'my super bad reason 2'
videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason, function (err) {
if (err) throw err
// We wait requests propagation
setTimeout(done, 11000)
})
})
it('Should have 2 video abuse on pod 1 and 1 on pod 2', function (done) {
videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(2)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(2)
let abuse = res.body.data[0]
expect(abuse.reason).to.equal('my super bad reason')
expect(abuse.reporterUsername).to.equal('root')
expect(abuse.reporterPodHost).to.equal('localhost:9001')
expect(abuse.videoId).to.equal(servers[0].video.id)
abuse = res.body.data[1]
expect(abuse.reason).to.equal('my super bad reason 2')
expect(abuse.reporterUsername).to.equal('root')
expect(abuse.reporterPodHost).to.equal('localhost:9001')
expect(abuse.videoId).to.equal(servers[1].video.id)
videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(1)
let abuse = res.body.data[0]
expect(abuse.reason).to.equal('my super bad reason 2')
expect(abuse.reporterUsername).to.equal('root')
expect(abuse.reporterPodHost).to.equal('localhost:9001')
done()
})
})
})
after(function (done) {
servers.forEach(function (server) {
process.kill(-server.app.pid)
})
// Keep the logs if the test failed
if (this.ok) {
serversUtils.flushTests(done)
} else {
done()
}
})
})
|