diff options
Diffstat (limited to 'server/tests/api/check-params/video-blacklist.ts')
-rw-r--r-- | server/tests/api/check-params/video-blacklist.ts | 132 |
1 files changed, 60 insertions, 72 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index ce7f5fa17..d28c6a952 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts | |||
@@ -1,46 +1,37 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | import { expect } from 'chai' | |
5 | import { | 5 | import { |
6 | BlacklistCommand, | ||
7 | checkBadCountPagination, | ||
8 | checkBadSortPagination, | ||
9 | checkBadStartPagination, | ||
6 | cleanupTests, | 10 | cleanupTests, |
7 | createUser, | 11 | createMultipleServers, |
8 | doubleFollow, | 12 | doubleFollow, |
9 | flushAndRunMultipleServers, | ||
10 | getBlacklistedVideosList, | ||
11 | getVideo, | ||
12 | getVideoWithToken, | ||
13 | makePostBodyRequest, | 13 | makePostBodyRequest, |
14 | makePutBodyRequest, | 14 | makePutBodyRequest, |
15 | removeVideoFromBlacklist, | 15 | PeerTubeServer, |
16 | ServerInfo, | ||
17 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
18 | uploadVideo, | ||
19 | userLogin, | ||
20 | waitJobs | 17 | waitJobs |
21 | } from '../../../../shared/extra-utils' | 18 | } from '@shared/extra-utils' |
22 | import { | 19 | import { HttpStatusCode, VideoBlacklistType } from '@shared/models' |
23 | checkBadCountPagination, | ||
24 | checkBadSortPagination, | ||
25 | checkBadStartPagination | ||
26 | } from '../../../../shared/extra-utils/requests/check-api-params' | ||
27 | import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos' | ||
28 | import { expect } from 'chai' | ||
29 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
30 | 20 | ||
31 | describe('Test video blacklist API validators', function () { | 21 | describe('Test video blacklist API validators', function () { |
32 | let servers: ServerInfo[] | 22 | let servers: PeerTubeServer[] |
33 | let notBlacklistedVideoId: number | 23 | let notBlacklistedVideoId: string |
34 | let remoteVideoUUID: string | 24 | let remoteVideoUUID: string |
35 | let userAccessToken1 = '' | 25 | let userAccessToken1 = '' |
36 | let userAccessToken2 = '' | 26 | let userAccessToken2 = '' |
27 | let command: BlacklistCommand | ||
37 | 28 | ||
38 | // --------------------------------------------------------------- | 29 | // --------------------------------------------------------------- |
39 | 30 | ||
40 | before(async function () { | 31 | before(async function () { |
41 | this.timeout(120000) | 32 | this.timeout(120000) |
42 | 33 | ||
43 | servers = await flushAndRunMultipleServers(2) | 34 | servers = await createMultipleServers(2) |
44 | 35 | ||
45 | await setAccessTokensToServers(servers) | 36 | await setAccessTokensToServers(servers) |
46 | await doubleFollow(servers[0], servers[1]) | 37 | await doubleFollow(servers[0], servers[1]) |
@@ -48,40 +39,41 @@ describe('Test video blacklist API validators', function () { | |||
48 | { | 39 | { |
49 | const username = 'user1' | 40 | const username = 'user1' |
50 | const password = 'my super password' | 41 | const password = 'my super password' |
51 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) | 42 | await servers[0].users.create({ username: username, password: password }) |
52 | userAccessToken1 = await userLogin(servers[0], { username, password }) | 43 | userAccessToken1 = await servers[0].login.getAccessToken({ username, password }) |
53 | } | 44 | } |
54 | 45 | ||
55 | { | 46 | { |
56 | const username = 'user2' | 47 | const username = 'user2' |
57 | const password = 'my super password' | 48 | const password = 'my super password' |
58 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) | 49 | await servers[0].users.create({ username: username, password: password }) |
59 | userAccessToken2 = await userLogin(servers[0], { username, password }) | 50 | userAccessToken2 = await servers[0].login.getAccessToken({ username, password }) |
60 | } | 51 | } |
61 | 52 | ||
62 | { | 53 | { |
63 | const res = await uploadVideo(servers[0].url, userAccessToken1, {}) | 54 | servers[0].store.video = await servers[0].videos.upload({ token: userAccessToken1 }) |
64 | servers[0].video = res.body.video | ||
65 | } | 55 | } |
66 | 56 | ||
67 | { | 57 | { |
68 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) | 58 | const { uuid } = await servers[0].videos.upload() |
69 | notBlacklistedVideoId = res.body.video.uuid | 59 | notBlacklistedVideoId = uuid |
70 | } | 60 | } |
71 | 61 | ||
72 | { | 62 | { |
73 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) | 63 | const { uuid } = await servers[1].videos.upload() |
74 | remoteVideoUUID = res.body.video.uuid | 64 | remoteVideoUUID = uuid |
75 | } | 65 | } |
76 | 66 | ||
77 | await waitJobs(servers) | 67 | await waitJobs(servers) |
68 | |||
69 | command = servers[0].blacklist | ||
78 | }) | 70 | }) |
79 | 71 | ||
80 | describe('When adding a video in blacklist', function () { | 72 | describe('When adding a video in blacklist', function () { |
81 | const basePath = '/api/v1/videos/' | 73 | const basePath = '/api/v1/videos/' |
82 | 74 | ||
83 | it('Should fail with nothing', async function () { | 75 | it('Should fail with nothing', async function () { |
84 | const path = basePath + servers[0].video + '/blacklist' | 76 | const path = basePath + servers[0].store.video + '/blacklist' |
85 | const fields = {} | 77 | const fields = {} |
86 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) | 78 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
87 | }) | 79 | }) |
@@ -93,25 +85,25 @@ describe('Test video blacklist API validators', function () { | |||
93 | }) | 85 | }) |
94 | 86 | ||
95 | it('Should fail with a non authenticated user', async function () { | 87 | it('Should fail with a non authenticated user', async function () { |
96 | const path = basePath + servers[0].video + '/blacklist' | 88 | const path = basePath + servers[0].store.video + '/blacklist' |
97 | const fields = {} | 89 | const fields = {} |
98 | await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | 90 | await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
99 | }) | 91 | }) |
100 | 92 | ||
101 | it('Should fail with a non admin user', async function () { | 93 | it('Should fail with a non admin user', async function () { |
102 | const path = basePath + servers[0].video + '/blacklist' | 94 | const path = basePath + servers[0].store.video + '/blacklist' |
103 | const fields = {} | 95 | const fields = {} |
104 | await makePostBodyRequest({ | 96 | await makePostBodyRequest({ |
105 | url: servers[0].url, | 97 | url: servers[0].url, |
106 | path, | 98 | path, |
107 | token: userAccessToken2, | 99 | token: userAccessToken2, |
108 | fields, | 100 | fields, |
109 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | 101 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
110 | }) | 102 | }) |
111 | }) | 103 | }) |
112 | 104 | ||
113 | it('Should fail with an invalid reason', async function () { | 105 | it('Should fail with an invalid reason', async function () { |
114 | const path = basePath + servers[0].video.uuid + '/blacklist' | 106 | const path = basePath + servers[0].store.video.uuid + '/blacklist' |
115 | const fields = { reason: 'a'.repeat(305) } | 107 | const fields = { reason: 'a'.repeat(305) } |
116 | 108 | ||
117 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) | 109 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
@@ -126,12 +118,12 @@ describe('Test video blacklist API validators', function () { | |||
126 | path, | 118 | path, |
127 | token: servers[0].accessToken, | 119 | token: servers[0].accessToken, |
128 | fields, | 120 | fields, |
129 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | 121 | expectedStatus: HttpStatusCode.CONFLICT_409 |
130 | }) | 122 | }) |
131 | }) | 123 | }) |
132 | 124 | ||
133 | it('Should succeed with the correct params', async function () { | 125 | it('Should succeed with the correct params', async function () { |
134 | const path = basePath + servers[0].video.uuid + '/blacklist' | 126 | const path = basePath + servers[0].store.video.uuid + '/blacklist' |
135 | const fields = {} | 127 | const fields = {} |
136 | 128 | ||
137 | await makePostBodyRequest({ | 129 | await makePostBodyRequest({ |
@@ -139,7 +131,7 @@ describe('Test video blacklist API validators', function () { | |||
139 | path, | 131 | path, |
140 | token: servers[0].accessToken, | 132 | token: servers[0].accessToken, |
141 | fields, | 133 | fields, |
142 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | 134 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
143 | }) | 135 | }) |
144 | }) | 136 | }) |
145 | }) | 137 | }) |
@@ -161,37 +153,37 @@ describe('Test video blacklist API validators', function () { | |||
161 | path, | 153 | path, |
162 | token: servers[0].accessToken, | 154 | token: servers[0].accessToken, |
163 | fields, | 155 | fields, |
164 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | 156 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
165 | }) | 157 | }) |
166 | }) | 158 | }) |
167 | 159 | ||
168 | it('Should fail with a non authenticated user', async function () { | 160 | it('Should fail with a non authenticated user', async function () { |
169 | const path = basePath + servers[0].video + '/blacklist' | 161 | const path = basePath + servers[0].store.video + '/blacklist' |
170 | const fields = {} | 162 | const fields = {} |
171 | await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | 163 | await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
172 | }) | 164 | }) |
173 | 165 | ||
174 | it('Should fail with a non admin user', async function () { | 166 | it('Should fail with a non admin user', async function () { |
175 | const path = basePath + servers[0].video + '/blacklist' | 167 | const path = basePath + servers[0].store.video + '/blacklist' |
176 | const fields = {} | 168 | const fields = {} |
177 | await makePutBodyRequest({ | 169 | await makePutBodyRequest({ |
178 | url: servers[0].url, | 170 | url: servers[0].url, |
179 | path, | 171 | path, |
180 | token: userAccessToken2, | 172 | token: userAccessToken2, |
181 | fields, | 173 | fields, |
182 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | 174 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
183 | }) | 175 | }) |
184 | }) | 176 | }) |
185 | 177 | ||
186 | it('Should fail with an invalid reason', async function () { | 178 | it('Should fail with an invalid reason', async function () { |
187 | const path = basePath + servers[0].video.uuid + '/blacklist' | 179 | const path = basePath + servers[0].store.video.uuid + '/blacklist' |
188 | const fields = { reason: 'a'.repeat(305) } | 180 | const fields = { reason: 'a'.repeat(305) } |
189 | 181 | ||
190 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) | 182 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) |
191 | }) | 183 | }) |
192 | 184 | ||
193 | it('Should succeed with the correct params', async function () { | 185 | it('Should succeed with the correct params', async function () { |
194 | const path = basePath + servers[0].video.shortUUID + '/blacklist' | 186 | const path = basePath + servers[0].store.video.shortUUID + '/blacklist' |
195 | const fields = { reason: 'hello' } | 187 | const fields = { reason: 'hello' } |
196 | 188 | ||
197 | await makePutBodyRequest({ | 189 | await makePutBodyRequest({ |
@@ -199,7 +191,7 @@ describe('Test video blacklist API validators', function () { | |||
199 | path, | 191 | path, |
200 | token: servers[0].accessToken, | 192 | token: servers[0].accessToken, |
201 | fields, | 193 | fields, |
202 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | 194 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
203 | }) | 195 | }) |
204 | }) | 196 | }) |
205 | }) | 197 | }) |
@@ -207,52 +199,53 @@ describe('Test video blacklist API validators', function () { | |||
207 | describe('When getting blacklisted video', function () { | 199 | describe('When getting blacklisted video', function () { |
208 | 200 | ||
209 | it('Should fail with a non authenticated user', async function () { | 201 | it('Should fail with a non authenticated user', async function () { |
210 | await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) | 202 | await servers[0].videos.get({ id: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
211 | }) | 203 | }) |
212 | 204 | ||
213 | it('Should fail with another user', async function () { | 205 | it('Should fail with another user', async function () { |
214 | await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) | 206 | await servers[0].videos.getWithToken({ |
207 | token: userAccessToken2, | ||
208 | id: servers[0].store.video.uuid, | ||
209 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
210 | }) | ||
215 | }) | 211 | }) |
216 | 212 | ||
217 | it('Should succeed with the owner authenticated user', async function () { | 213 | it('Should succeed with the owner authenticated user', async function () { |
218 | const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) | 214 | const video = await servers[0].videos.getWithToken({ token: userAccessToken1, id: servers[0].store.video.uuid }) |
219 | const video: VideoDetails = res.body | ||
220 | |||
221 | expect(video.blacklisted).to.be.true | 215 | expect(video.blacklisted).to.be.true |
222 | }) | 216 | }) |
223 | 217 | ||
224 | it('Should succeed with an admin', async function () { | 218 | it('Should succeed with an admin', async function () { |
225 | const video = servers[0].video | 219 | const video = servers[0].store.video |
226 | 220 | ||
227 | for (const id of [ video.id, video.uuid, video.shortUUID ]) { | 221 | for (const id of [ video.id, video.uuid, video.shortUUID ]) { |
228 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200) | 222 | const video = await servers[0].videos.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 }) |
229 | const video: VideoDetails = res.body | ||
230 | |||
231 | expect(video.blacklisted).to.be.true | 223 | expect(video.blacklisted).to.be.true |
232 | } | 224 | } |
233 | }) | 225 | }) |
234 | }) | 226 | }) |
235 | 227 | ||
236 | describe('When removing a video in blacklist', function () { | 228 | describe('When removing a video in blacklist', function () { |
229 | |||
237 | it('Should fail with a non authenticated user', async function () { | 230 | it('Should fail with a non authenticated user', async function () { |
238 | await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) | 231 | await command.remove({ token: 'fake token', videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
239 | }) | 232 | }) |
240 | 233 | ||
241 | it('Should fail with a non admin user', async function () { | 234 | it('Should fail with a non admin user', async function () { |
242 | await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) | 235 | await command.remove({ token: userAccessToken2, videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
243 | }) | 236 | }) |
244 | 237 | ||
245 | it('Should fail with an incorrect id', async function () { | 238 | it('Should fail with an incorrect id', async function () { |
246 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) | 239 | await command.remove({ videoId: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
247 | }) | 240 | }) |
248 | 241 | ||
249 | it('Should fail with a not blacklisted video', async function () { | 242 | it('Should fail with a not blacklisted video', async function () { |
250 | // The video was not added to the blacklist so it should fail | 243 | // The video was not added to the blacklist so it should fail |
251 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404) | 244 | await command.remove({ videoId: notBlacklistedVideoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
252 | }) | 245 | }) |
253 | 246 | ||
254 | it('Should succeed with the correct params', async function () { | 247 | it('Should succeed with the correct params', async function () { |
255 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204) | 248 | await command.remove({ videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 }) |
256 | }) | 249 | }) |
257 | }) | 250 | }) |
258 | 251 | ||
@@ -260,11 +253,11 @@ describe('Test video blacklist API validators', function () { | |||
260 | const basePath = '/api/v1/videos/blacklist/' | 253 | const basePath = '/api/v1/videos/blacklist/' |
261 | 254 | ||
262 | it('Should fail with a non authenticated user', async function () { | 255 | it('Should fail with a non authenticated user', async function () { |
263 | await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 256 | await servers[0].blacklist.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
264 | }) | 257 | }) |
265 | 258 | ||
266 | it('Should fail with a non admin user', async function () { | 259 | it('Should fail with a non admin user', async function () { |
267 | await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 }) | 260 | await servers[0].blacklist.list({ token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
268 | }) | 261 | }) |
269 | 262 | ||
270 | it('Should fail with a bad start pagination', async function () { | 263 | it('Should fail with a bad start pagination', async function () { |
@@ -280,16 +273,11 @@ describe('Test video blacklist API validators', function () { | |||
280 | }) | 273 | }) |
281 | 274 | ||
282 | it('Should fail with an invalid type', async function () { | 275 | it('Should fail with an invalid type', async function () { |
283 | await getBlacklistedVideosList({ | 276 | await servers[0].blacklist.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
284 | url: servers[0].url, | ||
285 | token: servers[0].accessToken, | ||
286 | type: 0, | ||
287 | specialStatus: HttpStatusCode.BAD_REQUEST_400 | ||
288 | }) | ||
289 | }) | 277 | }) |
290 | 278 | ||
291 | it('Should succeed with the correct parameters', async function () { | 279 | it('Should succeed with the correct parameters', async function () { |
292 | await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL }) | 280 | await servers[0].blacklist.list({ type: VideoBlacklistType.MANUAL }) |
293 | }) | 281 | }) |
294 | }) | 282 | }) |
295 | 283 | ||