diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-01 19:04:29 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-01 19:04:29 +0200 |
commit | 843aa7ba0312e7180e7bbae147e32ee60e70d9ba (patch) | |
tree | df5533a9dda312877b8b3a6992b81c75044c094e /server | |
parent | 3eeeb87fe62fab3e48455f53c8a725b49878b9b3 (diff) | |
download | PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.tar.gz PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.tar.zst PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.zip |
Server: add tests for video blacklists
Diffstat (limited to 'server')
-rw-r--r-- | server/tests/api/check-params/index.js | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/video-abuses.js | 8 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklists.js | 123 | ||||
-rw-r--r-- | server/tests/api/index.js | 2 | ||||
-rw-r--r-- | server/tests/api/video-abuse.js | 2 | ||||
-rw-r--r-- | server/tests/api/video-blacklist.js | 138 | ||||
-rw-r--r-- | server/tests/utils/video-abuses.js | 4 | ||||
-rw-r--r-- | server/tests/utils/video-blacklists.js | 29 |
8 files changed, 300 insertions, 7 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') | |||
7 | require('./requests') | 7 | require('./requests') |
8 | require('./videos') | 8 | require('./videos') |
9 | require('./video-abuses') | 9 | require('./video-abuses') |
10 | require('./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 | |||
5 | const series = require('async/series') | ||
6 | |||
7 | const loginUtils = require('../../utils/login') | ||
8 | const requestsUtils = require('../../utils/requests') | ||
9 | const serversUtils = require('../../utils/servers') | ||
10 | const usersUtils = require('../../utils/users') | ||
11 | const videosUtils = require('../../utils/videos') | ||
12 | |||
13 | describe('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') | |||
6 | require('./friends-basic') | 6 | require('./friends-basic') |
7 | require('./users') | 7 | require('./users') |
8 | require('./single-pod') | 8 | require('./single-pod') |
9 | require('./video-abuse') | ||
10 | require('./video-blacklist') | ||
9 | require('./multiple-pods') | 11 | require('./multiple-pods') |
10 | require('./requests') | 12 | require('./requests') |
11 | require('./friends-advanced') | 13 | require('./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 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const series = require('async/series') | ||
9 | |||
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 videoBlacklistsUtils = require('../utils/video-blacklists') | ||
15 | |||
16 | describe('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 | }) | ||
diff --git a/server/tests/utils/video-abuses.js b/server/tests/utils/video-abuses.js index 596c824b3..c4dd87990 100644 --- a/server/tests/utils/video-abuses.js +++ b/server/tests/utils/video-abuses.js | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | const request = require('supertest') | 3 | const request = require('supertest') |
4 | 4 | ||
5 | const videosUtils = { | 5 | const videosAbuseUtils = { |
6 | getVideoAbusesList, | 6 | getVideoAbusesList, |
7 | getVideoAbusesListPagination, | 7 | getVideoAbusesListPagination, |
8 | getVideoAbusesListSort, | 8 | getVideoAbusesListSort, |
@@ -70,4 +70,4 @@ function getVideoAbusesListSort (url, token, sort, end) { | |||
70 | 70 | ||
71 | // --------------------------------------------------------------------------- | 71 | // --------------------------------------------------------------------------- |
72 | 72 | ||
73 | module.exports = videosUtils | 73 | module.exports = videosAbuseUtils |
diff --git a/server/tests/utils/video-blacklists.js b/server/tests/utils/video-blacklists.js new file mode 100644 index 000000000..0a58dd631 --- /dev/null +++ b/server/tests/utils/video-blacklists.js | |||
@@ -0,0 +1,29 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | |||
5 | const videosBlacklistsUtils = { | ||
6 | addVideoToBlacklist | ||
7 | } | ||
8 | |||
9 | // ---------------------- Export functions -------------------- | ||
10 | |||
11 | function addVideoToBlacklist (url, token, videoId, specialStatus, end) { | ||
12 | if (!end) { | ||
13 | end = specialStatus | ||
14 | specialStatus = 204 | ||
15 | } | ||
16 | |||
17 | const path = '/api/v1/videos/' + videoId + '/blacklist' | ||
18 | |||
19 | request(url) | ||
20 | .post(path) | ||
21 | .set('Accept', 'application/json') | ||
22 | .set('Authorization', 'Bearer ' + token) | ||
23 | .expect(specialStatus) | ||
24 | .end(end) | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | module.exports = videosBlacklistsUtils | ||