aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/index.js1
-rw-r--r--server/tests/api/check-params/remotes.js4
-rw-r--r--server/tests/api/check-params/video-abuses.js180
-rw-r--r--server/tests/api/friends-advanced.js10
-rw-r--r--server/tests/api/friends-basic.js12
-rw-r--r--server/tests/api/video-abuse.js191
-rw-r--r--server/tests/utils/video-abuses.js73
7 files changed, 460 insertions, 11 deletions
diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js
index 3d6f09267..d0824f08a 100644
--- a/server/tests/api/check-params/index.js
+++ b/server/tests/api/check-params/index.js
@@ -6,3 +6,4 @@ require('./remotes')
6require('./users') 6require('./users')
7require('./requests') 7require('./requests')
8require('./videos') 8require('./videos')
9require('./video-abuses')
diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js
index 30ba3b697..c1ab9fb2b 100644
--- a/server/tests/api/check-params/remotes.js
+++ b/server/tests/api/check-params/remotes.js
@@ -47,6 +47,10 @@ describe('Test remote videos API validators', function () {
47 it('Should check when removing a video') 47 it('Should check when removing a video')
48 }) 48 })
49 49
50 describe('When reporting abuse on a video', function () {
51 it('Should check when reporting a video abuse')
52 })
53
50 after(function (done) { 54 after(function (done) {
51 process.kill(-server.app.pid) 55 process.kill(-server.app.pid)
52 56
diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js
new file mode 100644
index 000000000..8cb4ccdc1
--- /dev/null
+++ b/server/tests/api/check-params/video-abuses.js
@@ -0,0 +1,180 @@
1'use strict'
2
3const request = require('supertest')
4const series = require('async/series')
5
6const loginUtils = require('../../utils/login')
7const requestsUtils = require('../../utils/requests')
8const serversUtils = require('../../utils/servers')
9const usersUtils = require('../../utils/users')
10const videosUtils = require('../../utils/videos')
11
12describe('Test video abuses API validators', function () {
13 let server = null
14 let userAccessToken = null
15
16 // ---------------------------------------------------------------
17
18 before(function (done) {
19 this.timeout(20000)
20
21 series([
22 function (next) {
23 serversUtils.flushTests(next)
24 },
25 function (next) {
26 serversUtils.runServer(1, function (server1) {
27 server = server1
28
29 next()
30 })
31 },
32 function (next) {
33 loginUtils.loginAndGetAccessToken(server, function (err, token) {
34 if (err) throw err
35 server.accessToken = token
36
37 next()
38 })
39 },
40 function (next) {
41 const username = 'user1'
42 const password = 'my super password'
43
44 usersUtils.createUser(server.url, server.accessToken, username, password, next)
45 },
46 function (next) {
47 const user = {
48 username: 'user1',
49 password: 'my super password'
50 }
51
52 loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
53 if (err) throw err
54
55 userAccessToken = accessToken
56
57 next()
58 })
59 },
60 // Upload some videos on each pods
61 function (next) {
62 const name = 'my super name for pod'
63 const description = 'my super description for pod'
64 const tags = [ 'tag' ]
65 const file = 'video_short2.webm'
66 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next)
67 },
68 function (next) {
69 videosUtils.getVideosList(server.url, function (err, res) {
70 if (err) throw err
71
72 const videos = res.body.data
73 server.video = videos[0]
74
75 next()
76 })
77 }
78 ], done)
79 })
80
81 describe('When listing video abuses', function () {
82 const path = '/api/v1/videos/abuse'
83
84 it('Should fail with a bad start pagination', function (done) {
85 request(server.url)
86 .get(path)
87 .query({ start: 'hello' })
88 .set('Authorization', 'Bearer ' + server.accessToken)
89 .set('Accept', 'application/json')
90 .expect(400, done)
91 })
92
93 it('Should fail with a bad count pagination', function (done) {
94 request(server.url)
95 .get(path)
96 .query({ count: 'hello' })
97 .set('Accept', 'application/json')
98 .set('Authorization', 'Bearer ' + server.accessToken)
99 .expect(400, done)
100 })
101
102 it('Should fail with an incorrect sort', function (done) {
103 request(server.url)
104 .get(path)
105 .query({ sort: 'hello' })
106 .set('Accept', 'application/json')
107 .set('Authorization', 'Bearer ' + server.accessToken)
108 .expect(400, done)
109 })
110
111 it('Should fail with a non authenticated user', function (done) {
112 request(server.url)
113 .get(path)
114 .query({ sort: 'hello' })
115 .set('Accept', 'application/json')
116 .expect(401, done)
117 })
118
119 it('Should fail with a non admin user', function (done) {
120 request(server.url)
121 .get(path)
122 .query({ sort: 'hello' })
123 .set('Accept', 'application/json')
124 .set('Authorization', 'Bearer ' + userAccessToken)
125 .expect(403, done)
126 })
127 })
128
129 describe('When reporting a video abuse', function () {
130 const basePath = '/api/v1/videos/'
131
132 it('Should fail with nothing', function (done) {
133 const path = basePath + server.video + '/abuse'
134 const data = {}
135 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
136 })
137
138 it('Should fail with a wrong video', function (done) {
139 const wrongPath = '/api/v1/videos/blabla/abuse'
140 const data = {}
141 requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done)
142 })
143
144 it('Should fail with a non authenticated user', function (done) {
145 const data = {}
146 const path = basePath + server.video + '/abuse'
147 requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
148 })
149
150 it('Should fail with a reason too short', function (done) {
151 const data = {
152 reason: 'h'
153 }
154 const path = basePath + server.video + '/abuse'
155 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
156 })
157
158 it('Should fail with a reason too big', function (done) {
159 const data = {
160 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
161 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
162 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
163 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
164 }
165 const path = basePath + server.video + '/abuse'
166 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
167 })
168 })
169
170 after(function (done) {
171 process.kill(-server.app.pid)
172
173 // Keep the logs if the test failed
174 if (this.ok) {
175 serversUtils.flushTests(done)
176 } else {
177 done()
178 }
179 })
180})
diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.js
index 0a2d58d82..708138bc9 100644
--- a/server/tests/api/friends-advanced.js
+++ b/server/tests/api/friends-advanced.js
@@ -86,7 +86,7 @@ describe('Test advanced friends', function () {
86 getFriendsList(5, function (err, res) { 86 getFriendsList(5, function (err, res) {
87 if (err) throw err 87 if (err) throw err
88 88
89 expect(res.body.length).to.equal(0) 89 expect(res.body.data.length).to.equal(0)
90 90
91 done() 91 done()
92 }) 92 })
@@ -111,7 +111,7 @@ describe('Test advanced friends', function () {
111 getFriendsList(i, function (err, res) { 111 getFriendsList(i, function (err, res) {
112 if (err) throw err 112 if (err) throw err
113 113
114 expect(res.body.length).to.equal(0) 114 expect(res.body.data.length).to.equal(0)
115 115
116 callback() 116 callback()
117 }) 117 })
@@ -140,7 +140,7 @@ describe('Test advanced friends', function () {
140 getFriendsList(i, function (err, res) { 140 getFriendsList(i, function (err, res) {
141 if (err) throw err 141 if (err) throw err
142 142
143 expect(res.body.length).to.equal(3) 143 expect(res.body.data.length).to.equal(3)
144 144
145 callback() 145 callback()
146 }) 146 })
@@ -182,7 +182,7 @@ describe('Test advanced friends', function () {
182 if (err) throw err 182 if (err) throw err
183 183
184 // Pod 4 didn't know pod 1 and 2 removed it 184 // Pod 4 didn't know pod 1 and 2 removed it
185 expect(res.body.length).to.equal(3) 185 expect(res.body.data.length).to.equal(3)
186 next() 186 next()
187 }) 187 })
188 }, 188 },
@@ -200,7 +200,7 @@ describe('Test advanced friends', function () {
200 if (err) throw err 200 if (err) throw err
201 201
202 // Pod 4 should not be our friend 202 // Pod 4 should not be our friend
203 const result = res.body 203 const result = res.body.data
204 expect(result.length).to.equal(3) 204 expect(result.length).to.equal(3)
205 for (const pod of result) { 205 for (const pod of result) {
206 expect(pod.host).not.equal(servers[3].host) 206 expect(pod.host).not.equal(servers[3].host)
diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js
index 3a904dbd7..6f37ff291 100644
--- a/server/tests/api/friends-basic.js
+++ b/server/tests/api/friends-basic.js
@@ -28,7 +28,7 @@ describe('Test basic friends', function () {
28 podsUtils.getFriendsList(serverToTest.url, function (err, res) { 28 podsUtils.getFriendsList(serverToTest.url, function (err, res) {
29 if (err) throw err 29 if (err) throw err
30 30
31 const result = res.body 31 const result = res.body.data
32 expect(result).to.be.an('array') 32 expect(result).to.be.an('array')
33 expect(result.length).to.equal(2) 33 expect(result.length).to.equal(2)
34 34
@@ -65,7 +65,7 @@ describe('Test basic friends', function () {
65 podsUtils.getFriendsList(server.url, function (err, res) { 65 podsUtils.getFriendsList(server.url, function (err, res) {
66 if (err) throw err 66 if (err) throw err
67 67
68 const result = res.body 68 const result = res.body.data
69 expect(result).to.be.an('array') 69 expect(result).to.be.an('array')
70 expect(result.length).to.equal(0) 70 expect(result.length).to.equal(0)
71 callback() 71 callback()
@@ -90,7 +90,7 @@ describe('Test basic friends', function () {
90 podsUtils.getFriendsList(servers[1].url, function (err, res) { 90 podsUtils.getFriendsList(servers[1].url, function (err, res) {
91 if (err) throw err 91 if (err) throw err
92 92
93 const result = res.body 93 const result = res.body.data
94 expect(result).to.be.an('array') 94 expect(result).to.be.an('array')
95 expect(result.length).to.equal(1) 95 expect(result.length).to.equal(1)
96 96
@@ -107,7 +107,7 @@ describe('Test basic friends', function () {
107 podsUtils.getFriendsList(servers[2].url, function (err, res) { 107 podsUtils.getFriendsList(servers[2].url, function (err, res) {
108 if (err) throw err 108 if (err) throw err
109 109
110 const result = res.body 110 const result = res.body.data
111 expect(result).to.be.an('array') 111 expect(result).to.be.an('array')
112 expect(result.length).to.equal(1) 112 expect(result.length).to.equal(1)
113 113
@@ -154,7 +154,7 @@ describe('Test basic friends', function () {
154 podsUtils.getFriendsList(servers[1].url, function (err, res) { 154 podsUtils.getFriendsList(servers[1].url, function (err, res) {
155 if (err) throw err 155 if (err) throw err
156 156
157 const result = res.body 157 const result = res.body.data
158 expect(result).to.be.an('array') 158 expect(result).to.be.an('array')
159 expect(result.length).to.equal(0) 159 expect(result.length).to.equal(0)
160 160
@@ -167,7 +167,7 @@ describe('Test basic friends', function () {
167 podsUtils.getFriendsList(url, function (err, res) { 167 podsUtils.getFriendsList(url, function (err, res) {
168 if (err) throw err 168 if (err) throw err
169 169
170 const result = res.body 170 const result = res.body.data
171 expect(result).to.be.an('array') 171 expect(result).to.be.an('array')
172 expect(result.length).to.equal(1) 172 expect(result.length).to.equal(1)
173 expect(result[0].host).not.to.be.equal(servers[1].host) 173 expect(result[0].host).not.to.be.equal(servers[1].host)
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
3const chai = require('chai')
4const each = require('async/each')
5const expect = chai.expect
6const series = require('async/series')
7
8const loginUtils = require('../utils/login')
9const podsUtils = require('../utils/pods')
10const serversUtils = require('../utils/servers')
11const videosUtils = require('../utils/videos')
12const videoAbusesUtils = require('../utils/video-abuses')
13
14describe('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})
diff --git a/server/tests/utils/video-abuses.js b/server/tests/utils/video-abuses.js
new file mode 100644
index 000000000..596c824b3
--- /dev/null
+++ b/server/tests/utils/video-abuses.js
@@ -0,0 +1,73 @@
1'use strict'
2
3const request = require('supertest')
4
5const videosUtils = {
6 getVideoAbusesList,
7 getVideoAbusesListPagination,
8 getVideoAbusesListSort,
9 reportVideoAbuse
10}
11
12// ---------------------- Export functions --------------------
13
14function reportVideoAbuse (url, token, videoId, reason, specialStatus, end) {
15 if (!end) {
16 end = specialStatus
17 specialStatus = 204
18 }
19
20 const path = '/api/v1/videos/' + videoId + '/abuse'
21
22 request(url)
23 .post(path)
24 .set('Accept', 'application/json')
25 .set('Authorization', 'Bearer ' + token)
26 .send({ reason })
27 .expect(specialStatus)
28 .end(end)
29}
30
31function getVideoAbusesList (url, token, end) {
32 const path = '/api/v1/videos/abuse'
33
34 request(url)
35 .get(path)
36 .query({ sort: 'createdAt' })
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + token)
39 .expect(200)
40 .expect('Content-Type', /json/)
41 .end(end)
42}
43
44function getVideoAbusesListPagination (url, token, start, count, end) {
45 const path = '/api/v1/videos/abuse'
46
47 request(url)
48 .get(path)
49 .query({ start: start })
50 .query({ count: count })
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + token)
53 .expect(200)
54 .expect('Content-Type', /json/)
55 .end(end)
56}
57
58function getVideoAbusesListSort (url, token, sort, end) {
59 const path = '/api/v1/videos/abuse'
60
61 request(url)
62 .get(path)
63 .query({ sort: sort })
64 .set('Accept', 'application/json')
65 .set('Authorization', 'Bearer ' + token)
66 .expect(200)
67 .expect('Content-Type', /json/)
68 .end(end)
69}
70
71// ---------------------------------------------------------------------------
72
73module.exports = videosUtils