aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/index.js1
-rw-r--r--server/tests/api/check-params/video-abuses.js8
-rw-r--r--server/tests/api/check-params/video-blacklists.js123
-rw-r--r--server/tests/api/index.js2
-rw-r--r--server/tests/api/video-abuse.js2
-rw-r--r--server/tests/api/video-blacklist.js138
6 files changed, 269 insertions, 5 deletions
diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js
index d0824f08a..527ab65a9 100644
--- a/server/tests/api/check-params/index.js
+++ b/server/tests/api/check-params/index.js
@@ -7,3 +7,4 @@ require('./users')
7require('./requests') 7require('./requests')
8require('./videos') 8require('./videos')
9require('./video-abuses') 9require('./video-abuses')
10require('./video-blacklists')
diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js
index 6dc5a7090..8c520aab4 100644
--- a/server/tests/api/check-params/video-abuses.js
+++ b/server/tests/api/check-params/video-abuses.js
@@ -129,7 +129,7 @@ describe('Test video abuses API validators', function () {
129 const basePath = '/api/v1/videos/' 129 const basePath = '/api/v1/videos/'
130 130
131 it('Should fail with nothing', function (done) { 131 it('Should fail with nothing', function (done) {
132 const path = basePath + server.video + '/abuse' 132 const path = basePath + server.video.id + '/abuse'
133 const data = {} 133 const data = {}
134 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) 134 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
135 }) 135 })
@@ -142,7 +142,7 @@ describe('Test video abuses API validators', function () {
142 142
143 it('Should fail with a non authenticated user', function (done) { 143 it('Should fail with a non authenticated user', function (done) {
144 const data = {} 144 const data = {}
145 const path = basePath + server.video + '/abuse' 145 const path = basePath + server.video.id + '/abuse'
146 requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) 146 requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
147 }) 147 })
148 148
@@ -150,7 +150,7 @@ describe('Test video abuses API validators', function () {
150 const data = { 150 const data = {
151 reason: 'h' 151 reason: 'h'
152 } 152 }
153 const path = basePath + server.video + '/abuse' 153 const path = basePath + server.video.id + '/abuse'
154 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) 154 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
155 }) 155 })
156 156
@@ -161,7 +161,7 @@ describe('Test video abuses API validators', function () {
161 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + 161 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
162 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' 162 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
163 } 163 }
164 const path = basePath + server.video + '/abuse' 164 const path = basePath + server.video.id + '/abuse'
165 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) 165 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
166 }) 166 })
167 }) 167 })
diff --git a/server/tests/api/check-params/video-blacklists.js b/server/tests/api/check-params/video-blacklists.js
new file mode 100644
index 000000000..a39ab0cfa
--- /dev/null
+++ b/server/tests/api/check-params/video-blacklists.js
@@ -0,0 +1,123 @@
1/* eslint-disable no-unused-expressions */
2
3'use strict'
4
5const series = require('async/series')
6
7const loginUtils = require('../../utils/login')
8const requestsUtils = require('../../utils/requests')
9const serversUtils = require('../../utils/servers')
10const usersUtils = require('../../utils/users')
11const videosUtils = require('../../utils/videos')
12
13describe('Test video blacklists API validators', function () {
14 let server = null
15 let userAccessToken = null
16
17 // ---------------------------------------------------------------
18
19 before(function (done) {
20 this.timeout(20000)
21
22 series([
23 function (next) {
24 serversUtils.flushTests(next)
25 },
26 function (next) {
27 serversUtils.runServer(1, function (server1) {
28 server = server1
29
30 next()
31 })
32 },
33 function (next) {
34 loginUtils.loginAndGetAccessToken(server, function (err, token) {
35 if (err) throw err
36 server.accessToken = token
37
38 next()
39 })
40 },
41 function (next) {
42 const username = 'user1'
43 const password = 'my super password'
44
45 usersUtils.createUser(server.url, server.accessToken, username, password, next)
46 },
47 function (next) {
48 const user = {
49 username: 'user1',
50 password: 'my super password'
51 }
52
53 loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
54 if (err) throw err
55
56 userAccessToken = accessToken
57
58 next()
59 })
60 },
61 // Upload a video
62 function (next) {
63 const videoAttributes = {}
64 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next)
65 },
66 function (next) {
67 videosUtils.getVideosList(server.url, function (err, res) {
68 if (err) throw err
69
70 const videos = res.body.data
71 server.video = videos[0]
72
73 next()
74 })
75 }
76 ], done)
77 })
78
79 describe('When adding a video in blacklist', function () {
80 const basePath = '/api/v1/videos/'
81
82 it('Should fail with nothing', function (done) {
83 const path = basePath + server.video + '/blacklist'
84 const data = {}
85 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
86 })
87
88 it('Should fail with a wrong video', function (done) {
89 const wrongPath = '/api/v1/videos/blabla/blacklist'
90 const data = {}
91 requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done)
92 })
93
94 it('Should fail with a non authenticated user', function (done) {
95 const data = {}
96 const path = basePath + server.video + '/blacklist'
97 requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
98 })
99
100 it('Should fail with a non admin user', function (done) {
101 const data = {}
102 const path = basePath + server.video + '/blacklist'
103 requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403)
104 })
105
106 it('Should fail with a local video', function (done) {
107 const data = {}
108 const path = basePath + server.video.id + '/blacklist'
109 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 403)
110 })
111 })
112
113 after(function (done) {
114 process.kill(-server.app.pid)
115
116 // Keep the logs if the test failed
117 if (this.ok) {
118 serversUtils.flushTests(done)
119 } else {
120 done()
121 }
122 })
123})
diff --git a/server/tests/api/index.js b/server/tests/api/index.js
index fcd12617e..7ae18f674 100644
--- a/server/tests/api/index.js
+++ b/server/tests/api/index.js
@@ -6,6 +6,8 @@ require('./check-params')
6require('./friends-basic') 6require('./friends-basic')
7require('./users') 7require('./users')
8require('./single-pod') 8require('./single-pod')
9require('./video-abuse')
10require('./video-blacklist')
9require('./multiple-pods') 11require('./multiple-pods')
10require('./requests') 12require('./requests')
11require('./friends-advanced') 13require('./friends-advanced')
diff --git a/server/tests/api/video-abuse.js b/server/tests/api/video-abuse.js
index 7db067585..1f64ec861 100644
--- a/server/tests/api/video-abuse.js
+++ b/server/tests/api/video-abuse.js
@@ -38,7 +38,7 @@ describe('Test video abuses', function () {
38 }) 38 })
39 }, next) 39 }, next)
40 }, 40 },
41 // Pod 1 make friends too 41 // Pod 1 makes friend with pod 2
42 function (next) { 42 function (next) {
43 const server = servers[0] 43 const server = servers[0]
44 podsUtils.makeFriends(server.url, server.accessToken, next) 44 podsUtils.makeFriends(server.url, server.accessToken, next)
diff --git a/server/tests/api/video-blacklist.js b/server/tests/api/video-blacklist.js
new file mode 100644
index 000000000..c95fc17cb
--- /dev/null
+++ b/server/tests/api/video-blacklist.js
@@ -0,0 +1,138 @@
1/* eslint-disable no-unused-expressions */
2
3'use strict'
4
5const chai = require('chai')
6const each = require('async/each')
7const expect = chai.expect
8const series = require('async/series')
9
10const loginUtils = require('../utils/login')
11const podsUtils = require('../utils/pods')
12const serversUtils = require('../utils/servers')
13const videosUtils = require('../utils/videos')
14const videoBlacklistsUtils = require('../utils/video-blacklists')
15
16describe('Test video blacklists', function () {
17 let servers = []
18
19 before(function (done) {
20 this.timeout(30000)
21
22 series([
23 // Run servers
24 function (next) {
25 serversUtils.flushAndRunMultipleServers(2, function (serversRun) {
26 servers = serversRun
27 next()
28 })
29 },
30 // Get the access tokens
31 function (next) {
32 each(servers, function (server, callbackEach) {
33 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
34 if (err) return callbackEach(err)
35
36 server.accessToken = accessToken
37 callbackEach()
38 })
39 }, next)
40 },
41 // Pod 1 makes friend with pod 2
42 function (next) {
43 const server = servers[0]
44 podsUtils.makeFriends(server.url, server.accessToken, next)
45 },
46 // Upload a video on pod 2
47 function (next) {
48 const videoAttributes = {
49 name: 'my super name for pod 2',
50 description: 'my super description for pod 2'
51 }
52 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
53 },
54 // Wait videos propagation
55 function (next) {
56 setTimeout(next, 11000)
57 },
58 function (next) {
59 videosUtils.getVideosList(servers[0].url, function (err, res) {
60 if (err) throw err
61
62 const videos = res.body.data
63
64 expect(videos.length).to.equal(1)
65
66 servers[0].remoteVideo = videos.find(function (video) { return video.name === 'my super name for pod 2' })
67
68 next()
69 })
70 }
71 ], done)
72 })
73
74 it('Should blacklist a remote video on pod 1', function (done) {
75 videoBlacklistsUtils.addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id, done)
76 })
77
78 it('Should not have the video blacklisted in videos list on pod 1', function (done) {
79 videosUtils.getVideosList(servers[0].url, function (err, res) {
80 if (err) throw err
81
82 expect(res.body.total).to.equal(0)
83 expect(res.body.data).to.be.an('array')
84 expect(res.body.data.length).to.equal(0)
85
86 done()
87 })
88 })
89
90 it('Should not have the video blacklisted in videos search on pod 1', function (done) {
91 videosUtils.searchVideo(servers[0].url, 'name', function (err, res) {
92 if (err) throw err
93
94 expect(res.body.total).to.equal(0)
95 expect(res.body.data).to.be.an('array')
96 expect(res.body.data.length).to.equal(0)
97
98 done()
99 })
100 })
101
102 it('Should have the blacklisted video in videos list on pod 2', function (done) {
103 videosUtils.getVideosList(servers[1].url, function (err, res) {
104 if (err) throw err
105
106 expect(res.body.total).to.equal(1)
107 expect(res.body.data).to.be.an('array')
108 expect(res.body.data.length).to.equal(1)
109
110 done()
111 })
112 })
113
114 it('Should have the video blacklisted in videos search on pod 2', function (done) {
115 videosUtils.searchVideo(servers[1].url, 'name', function (err, res) {
116 if (err) throw err
117
118 expect(res.body.total).to.equal(1)
119 expect(res.body.data).to.be.an('array')
120 expect(res.body.data.length).to.equal(1)
121
122 done()
123 })
124 })
125
126 after(function (done) {
127 servers.forEach(function (server) {
128 process.kill(-server.app.pid)
129 })
130
131 // Keep the logs if the test failed
132 if (this.ok) {
133 serversUtils.flushTests(done)
134 } else {
135 done()
136 }
137 })
138})