diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
commit | 99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch) | |
tree | c9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/tests/api/video-abuse.js | |
parent | fcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff) | |
parent | 91cc839af88730ba55f84997c56b85ea100070a7 (diff) | |
download | PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip |
Merge branch 'postgresql'
Diffstat (limited to 'server/tests/api/video-abuse.js')
-rw-r--r-- | server/tests/api/video-abuse.js | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/server/tests/api/video-abuse.js b/server/tests/api/video-abuse.js new file mode 100644 index 000000000..58db17c42 --- /dev/null +++ b/server/tests/api/video-abuse.js | |||
@@ -0,0 +1,191 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const chai = require('chai') | ||
4 | const each = require('async/each') | ||
5 | const expect = chai.expect | ||
6 | const series = require('async/series') | ||
7 | |||
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') | ||
13 | |||
14 | describe('Test video abuses', function () { | ||
15 | let servers = [] | ||
16 | |||
17 | before(function (done) { | ||
18 | this.timeout(30000) | ||
19 | |||
20 | series([ | ||
21 | // Run servers | ||
22 | function (next) { | ||
23 | serversUtils.flushAndRunMultipleServers(2, function (serversRun) { | ||
24 | servers = serversRun | ||
25 | next() | ||
26 | }) | ||
27 | }, | ||
28 | // Get the access tokens | ||
29 | function (next) { | ||
30 | each(servers, function (server, callbackEach) { | ||
31 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
32 | if (err) return callbackEach(err) | ||
33 | |||
34 | server.accessToken = accessToken | ||
35 | callbackEach() | ||
36 | }) | ||
37 | }, next) | ||
38 | }, | ||
39 | // Pod 1 make friends too | ||
40 | function (next) { | ||
41 | const server = servers[0] | ||
42 | podsUtils.makeFriends(server.url, server.accessToken, next) | ||
43 | }, | ||
44 | // Upload some videos on each pods | ||
45 | function (next) { | ||
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) | ||
51 | }, | ||
52 | function (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) | ||
58 | }, | ||
59 | // Wait videos propagation | ||
60 | function (next) { | ||
61 | setTimeout(next, 11000) | ||
62 | }, | ||
63 | function (next) { | ||
64 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
65 | if (err) throw err | ||
66 | |||
67 | const videos = res.body.data | ||
68 | |||
69 | expect(videos.length).to.equal(2) | ||
70 | |||
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' }) | ||
73 | |||
74 | next() | ||
75 | }) | ||
76 | } | ||
77 | ], done) | ||
78 | }) | ||
79 | |||
80 | it('Should not have video abuses', function (done) { | ||
81 | videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) { | ||
82 | if (err) throw err | ||
83 | |||
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) | ||
87 | |||
88 | done() | ||
89 | }) | ||
90 | }) | ||
91 | |||
92 | it('Should report abuse on a local video', function (done) { | ||
93 | this.timeout(15000) | ||
94 | |||
95 | const reason = 'my super bad reason' | ||
96 | videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason, function (err) { | ||
97 | if (err) throw err | ||
98 | |||
99 | // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2 | ||
100 | setTimeout(done, 11000) | ||
101 | }) | ||
102 | }) | ||
103 | |||
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) { | ||
106 | if (err) throw err | ||
107 | |||
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) | ||
111 | |||
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) | ||
117 | |||
118 | videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) { | ||
119 | if (err) throw err | ||
120 | |||
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) | ||
124 | |||
125 | done() | ||
126 | }) | ||
127 | }) | ||
128 | }) | ||
129 | |||
130 | it('Should report abuse on a remote video', function (done) { | ||
131 | this.timeout(15000) | ||
132 | |||
133 | const reason = 'my super bad reason 2' | ||
134 | videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason, function (err) { | ||
135 | if (err) throw err | ||
136 | |||
137 | // We wait requests propagation | ||
138 | setTimeout(done, 11000) | ||
139 | }) | ||
140 | }) | ||
141 | |||
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) { | ||
144 | if (err) throw err | ||
145 | |||
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) | ||
149 | |||
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) | ||
155 | |||
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) | ||
161 | |||
162 | videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) { | ||
163 | if (err) throw err | ||
164 | |||
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) | ||
168 | |||
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') | ||
173 | |||
174 | done() | ||
175 | }) | ||
176 | }) | ||
177 | }) | ||
178 | |||
179 | after(function (done) { | ||
180 | servers.forEach(function (server) { | ||
181 | process.kill(-server.app.pid) | ||
182 | }) | ||
183 | |||
184 | // Keep the logs if the test failed | ||
185 | if (this.ok) { | ||
186 | serversUtils.flushTests(done) | ||
187 | } else { | ||
188 | done() | ||
189 | } | ||
190 | }) | ||
191 | }) | ||