diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/index.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/remotes.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/request-schedulers.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklist.ts | 195 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklists.ts | 90 | ||||
-rw-r--r-- | server/tests/api/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/video-blacklist-management.ts | 162 | ||||
-rw-r--r-- | server/tests/api/video-transcoder.ts | 2 |
8 files changed, 362 insertions, 94 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 97f2a19d7..399a05bc3 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -5,4 +5,4 @@ import './users' | |||
5 | import './request-schedulers' | 5 | import './request-schedulers' |
6 | import './videos' | 6 | import './videos' |
7 | import './video-abuses' | 7 | import './video-abuses' |
8 | import './video-blacklists' | 8 | import './video-blacklist' |
diff --git a/server/tests/api/check-params/remotes.ts b/server/tests/api/check-params/remotes.ts index b36f1c08b..9456ae665 100644 --- a/server/tests/api/check-params/remotes.ts +++ b/server/tests/api/check-params/remotes.ts | |||
@@ -14,7 +14,7 @@ describe('Test remote videos API validators', function () { | |||
14 | // --------------------------------------------------------------- | 14 | // --------------------------------------------------------------- |
15 | 15 | ||
16 | before(async function () { | 16 | before(async function () { |
17 | this.timeout(20000) | 17 | this.timeout(60000) |
18 | 18 | ||
19 | await flushTests() | 19 | await flushTests() |
20 | 20 | ||
diff --git a/server/tests/api/check-params/request-schedulers.ts b/server/tests/api/check-params/request-schedulers.ts index c39f5947b..01a54ffa1 100644 --- a/server/tests/api/check-params/request-schedulers.ts +++ b/server/tests/api/check-params/request-schedulers.ts | |||
@@ -20,7 +20,7 @@ describe('Test request schedulers stats API validators', function () { | |||
20 | // --------------------------------------------------------------- | 20 | // --------------------------------------------------------------- |
21 | 21 | ||
22 | before(async function () { | 22 | before(async function () { |
23 | this.timeout(20000) | 23 | this.timeout(60000) |
24 | 24 | ||
25 | await flushTests() | 25 | await flushTests() |
26 | 26 | ||
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts new file mode 100644 index 000000000..80e6f8011 --- /dev/null +++ b/server/tests/api/check-params/video-blacklist.ts | |||
@@ -0,0 +1,195 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as request from 'supertest' | ||
5 | |||
6 | import { | ||
7 | ServerInfo, | ||
8 | flushTests, | ||
9 | runServer, | ||
10 | uploadVideo, | ||
11 | getVideosList, | ||
12 | createUser, | ||
13 | setAccessTokensToServers, | ||
14 | killallServers, | ||
15 | makePostBodyRequest, | ||
16 | getUserAccessToken | ||
17 | } from '../../utils' | ||
18 | |||
19 | describe('Test video blacklist API validators', function () { | ||
20 | let server: ServerInfo | ||
21 | let userAccessToken = '' | ||
22 | |||
23 | // --------------------------------------------------------------- | ||
24 | |||
25 | before(async function () { | ||
26 | this.timeout(120000) | ||
27 | |||
28 | await flushTests() | ||
29 | |||
30 | server = await runServer(1) | ||
31 | |||
32 | await setAccessTokensToServers([ server ]) | ||
33 | |||
34 | const username = 'user1' | ||
35 | const password = 'my super password' | ||
36 | await createUser(server.url, server.accessToken, username, password) | ||
37 | userAccessToken = await getUserAccessToken(server, { username, password }) | ||
38 | |||
39 | // Upload a video | ||
40 | const videoAttributes = {} | ||
41 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
42 | |||
43 | const res = await getVideosList(server.url) | ||
44 | |||
45 | const videos = res.body.data | ||
46 | server.video = videos[0] | ||
47 | }) | ||
48 | |||
49 | describe('When adding a video in blacklist', function () { | ||
50 | const basePath = '/api/v1/videos/' | ||
51 | |||
52 | it('Should fail with nothing', async function () { | ||
53 | const path = basePath + server.video + '/blacklist' | ||
54 | const fields = {} | ||
55 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
56 | }) | ||
57 | |||
58 | it('Should fail with a wrong video', async function () { | ||
59 | const wrongPath = '/api/v1/videos/blabla/blacklist' | ||
60 | const fields = {} | ||
61 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | ||
62 | }) | ||
63 | |||
64 | it('Should fail with a non authenticated user', async function () { | ||
65 | const fields = {} | ||
66 | const path = basePath + server.video + '/blacklist' | ||
67 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | ||
68 | }) | ||
69 | |||
70 | it('Should fail with a non admin user', async function () { | ||
71 | const fields = {} | ||
72 | const path = basePath + server.video + '/blacklist' | ||
73 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | ||
74 | }) | ||
75 | |||
76 | it('Should fail with a local video', async function () { | ||
77 | const fields = {} | ||
78 | const path = basePath + server.video.id + '/blacklist' | ||
79 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) | ||
80 | }) | ||
81 | }) | ||
82 | |||
83 | describe('When removing a video in blacklist', function () { | ||
84 | const basePath = '/api/v1/blacklist/' | ||
85 | |||
86 | it('Should fail with a non authenticated user', async function () { | ||
87 | const path = basePath + server.video.id | ||
88 | |||
89 | await request(server.url) | ||
90 | .delete(path) | ||
91 | .set('Authorization', 'Bearer ' + 'fake token') | ||
92 | .set('Accept', 'application/json') | ||
93 | .expect(401) | ||
94 | }) | ||
95 | |||
96 | it('Should fail with a non admin user', async function () { | ||
97 | const path = basePath + server.video.id | ||
98 | |||
99 | await request(server.url) | ||
100 | .delete(path) | ||
101 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
102 | .set('Accept', 'application/json') | ||
103 | .expect(403) | ||
104 | }) | ||
105 | |||
106 | it('Should fail with an incorrect id', async function () { | ||
107 | const path = basePath + 'foobar' | ||
108 | |||
109 | await request(server.url) | ||
110 | .delete(path) | ||
111 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
112 | .set('Accept', 'application/json') | ||
113 | .expect(400) | ||
114 | }) | ||
115 | |||
116 | it('Should fail with a not blacklisted video', async function () { | ||
117 | // The video was not added to the blacklist so it should fail | ||
118 | const path = basePath + server.video.id | ||
119 | |||
120 | await request(server.url) | ||
121 | .delete(path) | ||
122 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
123 | .set('Accept', 'application/json') | ||
124 | .expect(404) | ||
125 | }) | ||
126 | }) | ||
127 | |||
128 | describe('When listing videos in blacklist', function () { | ||
129 | const basePath = '/api/v1/blacklist/' | ||
130 | |||
131 | it('Should fail with a non authenticated user', async function () { | ||
132 | const path = basePath | ||
133 | |||
134 | await request(server.url) | ||
135 | .get(path) | ||
136 | .query({ sort: 'createdAt' }) | ||
137 | .set('Accept', 'application/json') | ||
138 | .set('Authorization', 'Bearer ' + 'fake token') | ||
139 | .expect(401) | ||
140 | }) | ||
141 | |||
142 | it('Should fail with a non admin user', async function () { | ||
143 | const path = basePath | ||
144 | |||
145 | await request(server.url) | ||
146 | .get(path) | ||
147 | .query({ sort: 'createdAt' }) | ||
148 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
149 | .set('Accept', 'application/json') | ||
150 | .expect(403) | ||
151 | }) | ||
152 | |||
153 | it('Should fail with a bad start pagination', async function () { | ||
154 | const path = basePath | ||
155 | |||
156 | await request(server.url) | ||
157 | .get(path) | ||
158 | .query({ start: 'foobar' }) | ||
159 | .set('Accept', 'application/json') | ||
160 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
161 | .expect(400) | ||
162 | }) | ||
163 | |||
164 | it('Should fail with a bad count pagination', async function () { | ||
165 | const path = basePath | ||
166 | |||
167 | await request(server.url) | ||
168 | .get(path) | ||
169 | .query({ count: 'foobar' }) | ||
170 | .set('Accept', 'application/json') | ||
171 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
172 | .expect(400) | ||
173 | }) | ||
174 | |||
175 | it('Should fail with an incorrect sort', async function () { | ||
176 | const path = basePath | ||
177 | |||
178 | await request(server.url) | ||
179 | .get(path) | ||
180 | .query({ sort: 'foobar' }) | ||
181 | .set('Accept', 'application/json') | ||
182 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
183 | .expect(400) | ||
184 | }) | ||
185 | }) | ||
186 | |||
187 | after(async function () { | ||
188 | killallServers([ server ]) | ||
189 | |||
190 | // Keep the logs if the test failed | ||
191 | if (this['ok']) { | ||
192 | await flushTests() | ||
193 | } | ||
194 | }) | ||
195 | }) | ||
diff --git a/server/tests/api/check-params/video-blacklists.ts b/server/tests/api/check-params/video-blacklists.ts deleted file mode 100644 index d0ad78ff1..000000000 --- a/server/tests/api/check-params/video-blacklists.ts +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { | ||
6 | ServerInfo, | ||
7 | flushTests, | ||
8 | runServer, | ||
9 | uploadVideo, | ||
10 | getVideosList, | ||
11 | createUser, | ||
12 | setAccessTokensToServers, | ||
13 | killallServers, | ||
14 | makePostBodyRequest, | ||
15 | getUserAccessToken | ||
16 | } from '../../utils' | ||
17 | |||
18 | describe('Test video blacklists API validators', function () { | ||
19 | let server: ServerInfo | ||
20 | let userAccessToken = '' | ||
21 | |||
22 | // --------------------------------------------------------------- | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(120000) | ||
26 | |||
27 | await flushTests() | ||
28 | |||
29 | server = await runServer(1) | ||
30 | |||
31 | await setAccessTokensToServers([ server ]) | ||
32 | |||
33 | const username = 'user1' | ||
34 | const password = 'my super password' | ||
35 | await createUser(server.url, server.accessToken, username, password) | ||
36 | userAccessToken = await getUserAccessToken(server, { username, password }) | ||
37 | |||
38 | // Upload a video | ||
39 | const videoAttributes = {} | ||
40 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
41 | |||
42 | const res = await getVideosList(server.url) | ||
43 | |||
44 | const videos = res.body.data | ||
45 | server.video = videos[0] | ||
46 | }) | ||
47 | |||
48 | describe('When adding a video in blacklist', function () { | ||
49 | const basePath = '/api/v1/videos/' | ||
50 | |||
51 | it('Should fail with nothing', async function () { | ||
52 | const path = basePath + server.video + '/blacklist' | ||
53 | const fields = {} | ||
54 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
55 | }) | ||
56 | |||
57 | it('Should fail with a wrong video', async function () { | ||
58 | const wrongPath = '/api/v1/videos/blabla/blacklist' | ||
59 | const fields = {} | ||
60 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | ||
61 | }) | ||
62 | |||
63 | it('Should fail with a non authenticated user', async function () { | ||
64 | const fields = {} | ||
65 | const path = basePath + server.video + '/blacklist' | ||
66 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | ||
67 | }) | ||
68 | |||
69 | it('Should fail with a non admin user', async function () { | ||
70 | const fields = {} | ||
71 | const path = basePath + server.video + '/blacklist' | ||
72 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | ||
73 | }) | ||
74 | |||
75 | it('Should fail with a local video', async function () { | ||
76 | const fields = {} | ||
77 | const path = basePath + server.video.id + '/blacklist' | ||
78 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) | ||
79 | }) | ||
80 | }) | ||
81 | |||
82 | after(async function () { | ||
83 | killallServers([ server ]) | ||
84 | |||
85 | // Keep the logs if the test failed | ||
86 | if (this['ok']) { | ||
87 | await flushTests() | ||
88 | } | ||
89 | }) | ||
90 | }) | ||
diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts index f60d709c8..03711e68a 100644 --- a/server/tests/api/index.ts +++ b/server/tests/api/index.ts | |||
@@ -6,6 +6,7 @@ import './users' | |||
6 | import './single-pod' | 6 | import './single-pod' |
7 | import './video-abuse' | 7 | import './video-abuse' |
8 | import './video-blacklist' | 8 | import './video-blacklist' |
9 | import './video-blacklist-management' | ||
9 | import './multiple-pods' | 10 | import './multiple-pods' |
10 | import './request-schedulers' | 11 | import './request-schedulers' |
11 | import './friends-advanced' | 12 | import './friends-advanced' |
diff --git a/server/tests/api/video-blacklist-management.ts b/server/tests/api/video-blacklist-management.ts new file mode 100644 index 000000000..7057f4b23 --- /dev/null +++ b/server/tests/api/video-blacklist-management.ts | |||
@@ -0,0 +1,162 @@ | |||
1 | /* tslint:disable:no-unused-expressions */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | import * as lodash from 'lodash' | ||
7 | const orderBy = lodash.orderBy | ||
8 | |||
9 | import { | ||
10 | ServerInfo, | ||
11 | flushTests, | ||
12 | wait, | ||
13 | setAccessTokensToServers, | ||
14 | flushAndRunMultipleServers, | ||
15 | killallServers, | ||
16 | makeFriends, | ||
17 | getVideosList, | ||
18 | uploadVideo, | ||
19 | addVideoToBlacklist, | ||
20 | removeVideoFromBlacklist, | ||
21 | getBlacklistedVideosList, | ||
22 | getSortedBlacklistedVideosList | ||
23 | } from '../utils' | ||
24 | |||
25 | describe('Test video blacklist management', function () { | ||
26 | let servers: ServerInfo[] = [] | ||
27 | |||
28 | async function blacklistVideosOnPod (server: ServerInfo) { | ||
29 | const res = await getVideosList(server.url) | ||
30 | |||
31 | const videos = res.body.data | ||
32 | for (let video of videos) { | ||
33 | await addVideoToBlacklist(server.url, server.accessToken, video.id) | ||
34 | } | ||
35 | } | ||
36 | |||
37 | before(async function () { | ||
38 | this.timeout(120000) | ||
39 | |||
40 | // Run servers | ||
41 | servers = await flushAndRunMultipleServers(2) | ||
42 | |||
43 | // Get the access tokens | ||
44 | await setAccessTokensToServers(servers) | ||
45 | |||
46 | // Pod 1 makes friend with pod 2 | ||
47 | await makeFriends(servers[0].url, servers[0].accessToken) | ||
48 | |||
49 | // Upload 2 videos on pod 2 | ||
50 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on pod 2' }) | ||
51 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on pod 2' }) | ||
52 | |||
53 | // Wait videos propagation | ||
54 | await wait(22000) | ||
55 | |||
56 | // Blacklist the two videos on pod 1 | ||
57 | await blacklistVideosOnPod(servers[0]) | ||
58 | }) | ||
59 | |||
60 | describe('When listing blacklisted videos', function () { | ||
61 | it('Should display all the blacklisted videos', async function () { | ||
62 | const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) | ||
63 | |||
64 | expect(res.body.total).to.equal(2) | ||
65 | |||
66 | const videos = res.body.data | ||
67 | expect(videos).to.be.an('array') | ||
68 | expect(videos.length).to.equal(2) | ||
69 | }) | ||
70 | |||
71 | it('Should get the correct sort when sorting by descending id', async function () { | ||
72 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') | ||
73 | expect(res.body.total).to.equal(2) | ||
74 | |||
75 | const videos = res.body.data | ||
76 | expect(videos).to.be.an('array') | ||
77 | expect(videos.length).to.equal(2) | ||
78 | |||
79 | const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) | ||
80 | |||
81 | expect(videos).to.deep.equal(result) | ||
82 | }) | ||
83 | |||
84 | it('Should get the correct sort when sorting by descending video name', async function () { | ||
85 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | ||
86 | expect(res.body.total).to.equal(2) | ||
87 | |||
88 | const videos = res.body.data | ||
89 | expect(videos).to.be.an('array') | ||
90 | expect(videos.length).to.equal(2) | ||
91 | |||
92 | const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) | ||
93 | |||
94 | expect(videos).to.deep.equal(result) | ||
95 | }) | ||
96 | |||
97 | it('Should get the correct sort when sorting by ascending creation date', async function () { | ||
98 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | ||
99 | expect(res.body.total).to.equal(2) | ||
100 | |||
101 | const videos = res.body.data | ||
102 | expect(videos).to.be.an('array') | ||
103 | expect(videos.length).to.equal(2) | ||
104 | |||
105 | const result = orderBy(res.body.data, [ 'createdAt' ]) | ||
106 | |||
107 | expect(videos).to.deep.equal(result) | ||
108 | }) | ||
109 | }) | ||
110 | |||
111 | describe('When removing a blacklisted video', function () { | ||
112 | let videoToRemove | ||
113 | let blacklist = [] | ||
114 | |||
115 | it('Should not have any video in videos list on pod 1', async function () { | ||
116 | const res = await getVideosList(servers[0].url) | ||
117 | expect(res.body.total).to.equal(0) | ||
118 | expect(res.body.data).to.be.an('array') | ||
119 | expect(res.body.data.length).to.equal(0) | ||
120 | }) | ||
121 | |||
122 | it('Should remove a video from the blacklist on pod 1', async function () { | ||
123 | // Get one video in the blacklist | ||
124 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | ||
125 | videoToRemove = res.body.data[0] | ||
126 | blacklist = res.body.data.slice(1) | ||
127 | |||
128 | // Remove it | ||
129 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId) | ||
130 | }) | ||
131 | |||
132 | it('Should have the ex-blacklisted video in videos list on pod 1', async function () { | ||
133 | const res = await getVideosList(servers[0].url) | ||
134 | expect(res.body.total).to.equal(1) | ||
135 | |||
136 | const videos = res.body.data | ||
137 | expect(videos).to.be.an('array') | ||
138 | expect(videos.length).to.equal(1) | ||
139 | |||
140 | expect(videos[0].name).to.equal(videoToRemove.name) | ||
141 | expect(videos[0].id).to.equal(videoToRemove.videoId) | ||
142 | }) | ||
143 | |||
144 | it('Should not have the ex-blacklisted video in videos blacklist list on pod 1', async function () { | ||
145 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | ||
146 | expect(res.body.total).to.equal(1) | ||
147 | |||
148 | const videos = res.body.data | ||
149 | expect(videos).to.be.an('array') | ||
150 | expect(videos.length).to.equal(1) | ||
151 | expect(videos).to.deep.equal(blacklist) | ||
152 | }) | ||
153 | }) | ||
154 | |||
155 | after(async function () { | ||
156 | killallServers(servers) | ||
157 | |||
158 | if (this['ok']) { | ||
159 | await flushTests() | ||
160 | } | ||
161 | }) | ||
162 | }) | ||
diff --git a/server/tests/api/video-transcoder.ts b/server/tests/api/video-transcoder.ts index 228cef007..c6d4c61f5 100644 --- a/server/tests/api/video-transcoder.ts +++ b/server/tests/api/video-transcoder.ts | |||
@@ -20,7 +20,7 @@ describe('Test video transcoding', function () { | |||
20 | let servers: ServerInfo[] = [] | 20 | let servers: ServerInfo[] = [] |
21 | 21 | ||
22 | before(async function () { | 22 | before(async function () { |
23 | this.timeout(30000) | 23 | this.timeout(60000) |
24 | 24 | ||
25 | // Run servers | 25 | // Run servers |
26 | servers = await flushAndRunMultipleServers(2) | 26 | servers = await flushAndRunMultipleServers(2) |