]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
792dbaf0 GS |
4 | |
5 | import { | |
26b7305a | 6 | createUser, |
5abb9fbb C |
7 | doubleFollow, |
8 | flushAndRunMultipleServers, | |
26b7305a | 9 | flushTests, |
5abb9fbb C |
10 | getBlacklistedVideosList, |
11 | getVideo, | |
12 | getVideoWithToken, | |
26b7305a C |
13 | killallServers, |
14 | makePostBodyRequest, | |
15 | makePutBodyRequest, | |
16 | removeVideoFromBlacklist, | |
26b7305a C |
17 | ServerInfo, |
18 | setAccessTokensToServers, | |
19 | uploadVideo, | |
5abb9fbb | 20 | userLogin, waitJobs |
9639bd17 | 21 | } from '../../../../shared/utils' |
22 | import { | |
23 | checkBadCountPagination, | |
24 | checkBadSortPagination, | |
25 | checkBadStartPagination | |
26 | } from '../../../../shared/utils/requests/check-api-params' | |
e5e7f7fe C |
27 | import { VideoDetails } from '../../../../shared/models/videos' |
28 | import { expect } from 'chai' | |
792dbaf0 GS |
29 | |
30 | describe('Test video blacklist API validators', function () { | |
5abb9fbb | 31 | let servers: ServerInfo[] |
26b7305a | 32 | let notBlacklistedVideoId: number |
5abb9fbb | 33 | let remoteVideoUUID: string |
e5e7f7fe C |
34 | let userAccessToken1 = '' |
35 | let userAccessToken2 = '' | |
792dbaf0 GS |
36 | |
37 | // --------------------------------------------------------------- | |
38 | ||
39 | before(async function () { | |
40 | this.timeout(120000) | |
41 | ||
42 | await flushTests() | |
5abb9fbb | 43 | servers = await flushAndRunMultipleServers(2) |
792dbaf0 | 44 | |
5abb9fbb C |
45 | await setAccessTokensToServers(servers) |
46 | await doubleFollow(servers[0], servers[1]) | |
792dbaf0 | 47 | |
e5e7f7fe C |
48 | { |
49 | const username = 'user1' | |
50 | const password = 'my super password' | |
5abb9fbb C |
51 | await createUser(servers[0].url, servers[0].accessToken, username, password) |
52 | userAccessToken1 = await userLogin(servers[0], { username, password }) | |
e5e7f7fe | 53 | } |
792dbaf0 | 54 | |
26b7305a | 55 | { |
e5e7f7fe C |
56 | const username = 'user2' |
57 | const password = 'my super password' | |
5abb9fbb C |
58 | await createUser(servers[0].url, servers[0].accessToken, username, password) |
59 | userAccessToken2 = await userLogin(servers[0], { username, password }) | |
e5e7f7fe C |
60 | } |
61 | ||
62 | { | |
5abb9fbb C |
63 | const res = await uploadVideo(servers[0].url, userAccessToken1, {}) |
64 | servers[0].video = res.body.video | |
26b7305a C |
65 | } |
66 | ||
67 | { | |
5abb9fbb | 68 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) |
26b7305a C |
69 | notBlacklistedVideoId = res.body.video.uuid |
70 | } | |
5abb9fbb C |
71 | |
72 | { | |
73 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) | |
74 | remoteVideoUUID = res.body.video.uuid | |
75 | } | |
76 | ||
77 | await waitJobs(servers) | |
792dbaf0 GS |
78 | }) |
79 | ||
80 | describe('When adding a video in blacklist', function () { | |
81 | const basePath = '/api/v1/videos/' | |
82 | ||
83 | it('Should fail with nothing', async function () { | |
5abb9fbb | 84 | const path = basePath + servers[0].video + '/blacklist' |
792dbaf0 | 85 | const fields = {} |
5abb9fbb | 86 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
792dbaf0 GS |
87 | }) |
88 | ||
89 | it('Should fail with a wrong video', async function () { | |
90 | const wrongPath = '/api/v1/videos/blabla/blacklist' | |
91 | const fields = {} | |
5abb9fbb | 92 | await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields }) |
792dbaf0 GS |
93 | }) |
94 | ||
95 | it('Should fail with a non authenticated user', async function () { | |
5abb9fbb | 96 | const path = basePath + servers[0].video + '/blacklist' |
11ba2ab3 | 97 | const fields = {} |
5abb9fbb | 98 | await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) |
792dbaf0 GS |
99 | }) |
100 | ||
101 | it('Should fail with a non admin user', async function () { | |
5abb9fbb | 102 | const path = basePath + servers[0].video + '/blacklist' |
11ba2ab3 | 103 | const fields = {} |
5abb9fbb | 104 | await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
792dbaf0 GS |
105 | }) |
106 | ||
26b7305a | 107 | it('Should fail with an invalid reason', async function () { |
5abb9fbb | 108 | const path = basePath + servers[0].video.uuid + '/blacklist' |
26b7305a C |
109 | const fields = { reason: 'a'.repeat(305) } |
110 | ||
5abb9fbb C |
111 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
112 | }) | |
113 | ||
114 | it('Should fail to unfederate a remote video', async function () { | |
115 | const path = basePath + remoteVideoUUID + '/blacklist' | |
116 | const fields = { unfederate: true } | |
117 | ||
118 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 }) | |
26b7305a C |
119 | }) |
120 | ||
121 | it('Should succeed with the correct params', async function () { | |
5abb9fbb | 122 | const path = basePath + servers[0].video.uuid + '/blacklist' |
26b7305a C |
123 | const fields = { } |
124 | ||
5abb9fbb | 125 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) |
26b7305a C |
126 | }) |
127 | }) | |
128 | ||
129 | describe('When updating a video in blacklist', function () { | |
130 | const basePath = '/api/v1/videos/' | |
131 | ||
132 | it('Should fail with a wrong video', async function () { | |
133 | const wrongPath = '/api/v1/videos/blabla/blacklist' | |
134 | const fields = {} | |
5abb9fbb | 135 | await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields }) |
26b7305a C |
136 | }) |
137 | ||
138 | it('Should fail with a video not blacklisted', async function () { | |
139 | const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' | |
140 | const fields = {} | |
5abb9fbb | 141 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 }) |
26b7305a C |
142 | }) |
143 | ||
144 | it('Should fail with a non authenticated user', async function () { | |
5abb9fbb | 145 | const path = basePath + servers[0].video + '/blacklist' |
26b7305a | 146 | const fields = {} |
5abb9fbb | 147 | await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) |
26b7305a C |
148 | }) |
149 | ||
150 | it('Should fail with a non admin user', async function () { | |
5abb9fbb | 151 | const path = basePath + servers[0].video + '/blacklist' |
11ba2ab3 | 152 | const fields = {} |
5abb9fbb | 153 | await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
26b7305a C |
154 | }) |
155 | ||
156 | it('Should fail with an invalid reason', async function () { | |
5abb9fbb | 157 | const path = basePath + servers[0].video.uuid + '/blacklist' |
26b7305a C |
158 | const fields = { reason: 'a'.repeat(305) } |
159 | ||
5abb9fbb | 160 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
26b7305a C |
161 | }) |
162 | ||
163 | it('Should succeed with the correct params', async function () { | |
5abb9fbb | 164 | const path = basePath + servers[0].video.uuid + '/blacklist' |
26b7305a C |
165 | const fields = { reason: 'hello' } |
166 | ||
5abb9fbb | 167 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) |
792dbaf0 GS |
168 | }) |
169 | }) | |
170 | ||
e5e7f7fe C |
171 | describe('When getting blacklisted video', function () { |
172 | ||
173 | it('Should fail with a non authenticated user', async function () { | |
5abb9fbb | 174 | await getVideo(servers[0].url, servers[0].video.uuid, 401) |
e5e7f7fe C |
175 | }) |
176 | ||
177 | it('Should fail with another user', async function () { | |
5abb9fbb | 178 | await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) |
e5e7f7fe C |
179 | }) |
180 | ||
181 | it('Should succeed with the owner authenticated user', async function () { | |
5abb9fbb | 182 | const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200) |
e5e7f7fe C |
183 | const video: VideoDetails = res.body |
184 | ||
185 | expect(video.blacklisted).to.be.true | |
186 | }) | |
187 | ||
188 | it('Should succeed with an admin', async function () { | |
5abb9fbb | 189 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200) |
e5e7f7fe C |
190 | const video: VideoDetails = res.body |
191 | ||
192 | expect(video.blacklisted).to.be.true | |
193 | }) | |
194 | }) | |
195 | ||
792dbaf0 | 196 | describe('When removing a video in blacklist', function () { |
792dbaf0 | 197 | it('Should fail with a non authenticated user', async function () { |
5abb9fbb | 198 | await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401) |
792dbaf0 GS |
199 | }) |
200 | ||
201 | it('Should fail with a non admin user', async function () { | |
5abb9fbb | 202 | await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) |
792dbaf0 GS |
203 | }) |
204 | ||
205 | it('Should fail with an incorrect id', async function () { | |
5abb9fbb | 206 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400) |
792dbaf0 GS |
207 | }) |
208 | ||
209 | it('Should fail with a not blacklisted video', async function () { | |
210 | // The video was not added to the blacklist so it should fail | |
5abb9fbb | 211 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404) |
26b7305a C |
212 | }) |
213 | ||
214 | it('Should succeed with the correct params', async function () { | |
5abb9fbb | 215 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204) |
792dbaf0 GS |
216 | }) |
217 | }) | |
218 | ||
219 | describe('When listing videos in blacklist', function () { | |
35bf0c83 | 220 | const basePath = '/api/v1/videos/blacklist/' |
792dbaf0 GS |
221 | |
222 | it('Should fail with a non authenticated user', async function () { | |
5abb9fbb | 223 | await getBlacklistedVideosList(servers[0].url, 'fake token', 401) |
792dbaf0 GS |
224 | }) |
225 | ||
226 | it('Should fail with a non admin user', async function () { | |
5abb9fbb | 227 | await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403) |
792dbaf0 GS |
228 | }) |
229 | ||
230 | it('Should fail with a bad start pagination', async function () { | |
5abb9fbb | 231 | await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken) |
792dbaf0 GS |
232 | }) |
233 | ||
234 | it('Should fail with a bad count pagination', async function () { | |
5abb9fbb | 235 | await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken) |
792dbaf0 GS |
236 | }) |
237 | ||
238 | it('Should fail with an incorrect sort', async function () { | |
5abb9fbb | 239 | await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken) |
792dbaf0 GS |
240 | }) |
241 | }) | |
242 | ||
243 | after(async function () { | |
5abb9fbb | 244 | killallServers(servers) |
792dbaf0 GS |
245 | |
246 | // Keep the logs if the test failed | |
247 | if (this['ok']) { | |
248 | await flushTests() | |
249 | } | |
250 | }) | |
251 | }) |