]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9b474844 | 2 | |
9b474844 | 3 | import 'mocha' |
2158ac90 RK |
4 | import * as chai from 'chai' |
5 | import { ServerConfig } from '@shared/models' | |
89cd1275 C |
6 | import { |
7 | addVideoCommentReply, | |
6691c522 | 8 | addVideoCommentThread, |
3cabf353 | 9 | createLive, |
a1587156 | 10 | doubleFollow, |
38267c0c | 11 | getAccountVideos, |
a1587156 | 12 | getConfig, |
a4d2ca07 | 13 | getMyVideos, |
6691c522 | 14 | getPluginTestPath, |
6691c522 | 15 | getVideo, |
38267c0c | 16 | getVideoChannelVideos, |
6691c522 | 17 | getVideoCommentThreads, |
a1587156 C |
18 | getVideosList, |
19 | getVideosListPagination, | |
6691c522 C |
20 | getVideoThreadComments, |
21 | getVideoWithToken, | |
a1587156 C |
22 | installPlugin, |
23 | registerUser, | |
24 | setAccessTokensToServers, | |
6691c522 | 25 | setDefaultVideoChannel, |
3cabf353 | 26 | updateCustomSubConfig, |
a1587156 C |
27 | updateVideo, |
28 | uploadVideo, | |
29 | waitJobs | |
89cd1275 | 30 | } from '../../../shared/extra-utils' |
2158ac90 | 31 | import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' |
b488ba1e | 32 | import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' |
2158ac90 | 33 | import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos' |
6691c522 | 34 | import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' |
f2eb23cd | 35 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
9b474844 C |
36 | |
37 | const expect = chai.expect | |
38 | ||
39 | describe('Test plugin filter hooks', function () { | |
89cd1275 C |
40 | let servers: ServerInfo[] |
41 | let videoUUID: string | |
42 | let threadId: number | |
9b474844 C |
43 | |
44 | before(async function () { | |
45 | this.timeout(30000) | |
9b474844 | 46 | |
89cd1275 C |
47 | servers = await flushAndRunMultipleServers(2) |
48 | await setAccessTokensToServers(servers) | |
6691c522 C |
49 | await setDefaultVideoChannel(servers) |
50 | await doubleFollow(servers[0], servers[1]) | |
89cd1275 C |
51 | |
52 | await installPlugin({ | |
53 | url: servers[0].url, | |
54 | accessToken: servers[0].accessToken, | |
55 | path: getPluginTestPath() | |
56 | }) | |
57 | ||
58 | await installPlugin({ | |
59 | url: servers[0].url, | |
60 | accessToken: servers[0].accessToken, | |
61 | path: getPluginTestPath('-two') | |
62 | }) | |
63 | ||
64 | for (let i = 0; i < 10; i++) { | |
65 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) | |
66 | } | |
67 | ||
68 | const res = await getVideosList(servers[0].url) | |
69 | videoUUID = res.body.data[0].uuid | |
3cabf353 C |
70 | |
71 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
72 | live: { enabled: true }, | |
73 | signup: { enabled: true }, | |
74 | import: { | |
75 | videos: { | |
76 | http: { enabled: true }, | |
77 | torrent: { enabled: true } | |
78 | } | |
79 | } | |
80 | }) | |
9b474844 C |
81 | }) |
82 | ||
6691c522 | 83 | it('Should run filter:api.videos.list.params', async function () { |
89cd1275 C |
84 | const res = await getVideosListPagination(servers[0].url, 0, 2) |
85 | ||
86 | // 2 plugins do +1 to the count parameter | |
87 | expect(res.body.data).to.have.lengthOf(4) | |
88 | }) | |
89 | ||
90 | it('Should run filter:api.videos.list.result', async function () { | |
91 | const res = await getVideosListPagination(servers[0].url, 0, 0) | |
92 | ||
93 | // Plugin do +1 to the total result | |
94 | expect(res.body.total).to.equal(11) | |
95 | }) | |
96 | ||
38267c0c C |
97 | it('Should run filter:api.accounts.videos.list.params', async function () { |
98 | const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) | |
99 | ||
100 | // 1 plugin do +1 to the count parameter | |
101 | expect(res.body.data).to.have.lengthOf(3) | |
102 | }) | |
103 | ||
104 | it('Should run filter:api.accounts.videos.list.result', async function () { | |
105 | const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) | |
106 | ||
107 | // Plugin do +2 to the total result | |
108 | expect(res.body.total).to.equal(12) | |
109 | }) | |
110 | ||
111 | it('Should run filter:api.video-channels.videos.list.params', async function () { | |
112 | const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) | |
113 | ||
114 | // 1 plugin do +3 to the count parameter | |
115 | expect(res.body.data).to.have.lengthOf(5) | |
116 | }) | |
117 | ||
118 | it('Should run filter:api.video-channels.videos.list.result', async function () { | |
c824e8a0 | 119 | const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) |
38267c0c C |
120 | |
121 | // Plugin do +3 to the total result | |
122 | expect(res.body.total).to.equal(13) | |
123 | }) | |
124 | ||
a4d2ca07 C |
125 | it('Should run filter:api.user.me.videos.list.params', async function () { |
126 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) | |
127 | ||
128 | // 1 plugin do +4 to the count parameter | |
129 | expect(res.body.data).to.have.lengthOf(6) | |
130 | }) | |
131 | ||
132 | it('Should run filter:api.user.me.videos.list.result', async function () { | |
133 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) | |
134 | ||
135 | // Plugin do +4 to the total result | |
136 | expect(res.body.total).to.equal(14) | |
137 | }) | |
138 | ||
89cd1275 C |
139 | it('Should run filter:api.video.get.result', async function () { |
140 | const res = await getVideo(servers[0].url, videoUUID) | |
141 | ||
142 | expect(res.body.name).to.contain('<3') | |
9b474844 C |
143 | }) |
144 | ||
6691c522 | 145 | it('Should run filter:api.video.upload.accept.result', async function () { |
f2eb23cd | 146 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) |
6691c522 C |
147 | }) |
148 | ||
3cabf353 C |
149 | it('Should run filter:api.live-video.create.accept.result', async function () { |
150 | const attributes = { | |
151 | name: 'video with bad word', | |
152 | privacy: VideoPrivacy.PUBLIC, | |
153 | channelId: servers[0].videoChannel.id | |
154 | } | |
155 | ||
f2eb23cd | 156 | await createLive(servers[0].url, servers[0].accessToken, attributes, HttpStatusCode.FORBIDDEN_403) |
3cabf353 C |
157 | }) |
158 | ||
2158ac90 RK |
159 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { |
160 | const baseAttributes = { | |
161 | name: 'normal title', | |
162 | privacy: VideoPrivacy.PUBLIC, | |
163 | channelId: servers[0].videoChannel.id, | |
b488ba1e | 164 | targetUrl: getGoodVideoUrl() + 'bad' |
2158ac90 | 165 | } |
f2eb23cd | 166 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) |
2158ac90 RK |
167 | }) |
168 | ||
169 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { | |
170 | const baseAttributes = { | |
171 | name: 'bad torrent', | |
172 | privacy: VideoPrivacy.PUBLIC, | |
173 | channelId: servers[0].videoChannel.id, | |
174 | torrentfile: 'video-720p.torrent' as any | |
175 | } | |
f2eb23cd | 176 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) |
2158ac90 RK |
177 | }) |
178 | ||
179 | it('Should run filter:api.video.post-import-url.accept.result', async function () { | |
180 | this.timeout(60000) | |
181 | ||
182 | let videoImportId: number | |
183 | ||
184 | { | |
185 | const baseAttributes = { | |
186 | name: 'title with bad word', | |
187 | privacy: VideoPrivacy.PUBLIC, | |
188 | channelId: servers[0].videoChannel.id, | |
b488ba1e | 189 | targetUrl: getGoodVideoUrl() |
2158ac90 RK |
190 | } |
191 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | |
192 | videoImportId = res.body.id | |
193 | } | |
194 | ||
195 | await waitJobs(servers) | |
196 | ||
197 | { | |
198 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | |
199 | const videoImports = res.body.data as VideoImport[] | |
200 | ||
201 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
202 | ||
203 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
204 | expect(videoImport.state.label).to.equal('Rejected') | |
205 | } | |
206 | }) | |
207 | ||
208 | it('Should run filter:api.video.post-import-torrent.accept.result', async function () { | |
209 | this.timeout(60000) | |
210 | ||
211 | let videoImportId: number | |
212 | ||
213 | { | |
214 | const baseAttributes = { | |
215 | name: 'title with bad word', | |
216 | privacy: VideoPrivacy.PUBLIC, | |
217 | channelId: servers[0].videoChannel.id, | |
218 | torrentfile: 'video-720p.torrent' as any | |
219 | } | |
220 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | |
221 | videoImportId = res.body.id | |
222 | } | |
223 | ||
224 | await waitJobs(servers) | |
225 | ||
226 | { | |
227 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | |
228 | const videoImports = res.body.data as VideoImport[] | |
229 | ||
230 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
231 | ||
232 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
233 | expect(videoImport.state.label).to.equal('Rejected') | |
234 | } | |
235 | }) | |
236 | ||
6691c522 | 237 | it('Should run filter:api.video-thread.create.accept.result', async function () { |
f2eb23cd | 238 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403) |
6691c522 C |
239 | }) |
240 | ||
241 | it('Should run filter:api.video-comment-reply.create.accept.result', async function () { | |
242 | const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') | |
243 | threadId = res.body.comment.id | |
244 | ||
f2eb23cd RK |
245 | await addVideoCommentReply( |
246 | servers[0].url, | |
247 | servers[0].accessToken, | |
248 | videoUUID, | |
249 | threadId, | |
250 | 'comment with bad word', | |
251 | HttpStatusCode.FORBIDDEN_403 | |
252 | ) | |
253 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200) | |
6691c522 C |
254 | }) |
255 | ||
256 | it('Should run filter:api.video-threads.list.params', async function () { | |
257 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
258 | ||
259 | // our plugin do +1 to the count parameter | |
260 | expect(res.body.data).to.have.lengthOf(1) | |
261 | }) | |
262 | ||
263 | it('Should run filter:api.video-threads.list.result', async function () { | |
264 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
265 | ||
266 | // Plugin do +1 to the total result | |
267 | expect(res.body.total).to.equal(2) | |
268 | }) | |
269 | ||
270 | it('Should run filter:api.video-thread-comments.list.params') | |
271 | ||
272 | it('Should run filter:api.video-thread-comments.list.result', async function () { | |
273 | const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) | |
274 | ||
275 | const thread = res.body as VideoCommentThreadTree | |
276 | expect(thread.comment.text.endsWith(' <3')).to.be.true | |
277 | }) | |
278 | ||
279 | describe('Should run filter:video.auto-blacklist.result', function () { | |
280 | ||
281 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | |
282 | const videoId = oldRes.body.video.uuid | |
283 | ||
284 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId) | |
285 | const video: VideoDetails = res.body | |
286 | expect(video.blacklisted).to.equal(value) | |
287 | } | |
288 | ||
289 | it('Should blacklist on upload', async function () { | |
a1587156 | 290 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) |
6691c522 C |
291 | await checkIsBlacklisted(res, true) |
292 | }) | |
293 | ||
294 | it('Should blacklist on import', async function () { | |
89566f77 C |
295 | this.timeout(15000) |
296 | ||
6691c522 C |
297 | const attributes = { |
298 | name: 'video please blacklist me', | |
b488ba1e | 299 | targetUrl: getGoodVideoUrl(), |
6691c522 C |
300 | channelId: servers[0].videoChannel.id |
301 | } | |
302 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
303 | await checkIsBlacklisted(res, true) | |
304 | }) | |
305 | ||
306 | it('Should blacklist on update', async function () { | |
a1587156 | 307 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) |
6691c522 C |
308 | const videoId = res.body.video.uuid |
309 | await checkIsBlacklisted(res, false) | |
310 | ||
a1587156 | 311 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) |
6691c522 C |
312 | await checkIsBlacklisted(res, true) |
313 | }) | |
314 | ||
315 | it('Should blacklist on remote upload', async function () { | |
316 | this.timeout(45000) | |
317 | ||
a1587156 | 318 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) |
6691c522 C |
319 | await waitJobs(servers) |
320 | ||
321 | await checkIsBlacklisted(res, true) | |
322 | }) | |
323 | ||
324 | it('Should blacklist on remote update', async function () { | |
325 | this.timeout(45000) | |
326 | ||
a1587156 | 327 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) |
6691c522 C |
328 | await waitJobs(servers) |
329 | ||
330 | const videoId = res.body.video.uuid | |
331 | await checkIsBlacklisted(res, false) | |
332 | ||
333 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | |
334 | await waitJobs(servers) | |
335 | ||
336 | await checkIsBlacklisted(res, true) | |
337 | }) | |
338 | }) | |
339 | ||
4ce7eb71 C |
340 | describe('Should run filter:api.user.signup.allowed.result', function () { |
341 | ||
342 | it('Should run on config endpoint', async function () { | |
343 | const res = await getConfig(servers[0].url) | |
344 | expect((res.body as ServerConfig).signup.allowed).to.be.true | |
345 | }) | |
346 | ||
347 | it('Should allow a signup', async function () { | |
348 | await registerUser(servers[0].url, 'john', 'password') | |
349 | }) | |
350 | ||
351 | it('Should not allow a signup', async function () { | |
f2eb23cd | 352 | const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403) |
4ce7eb71 C |
353 | |
354 | expect(res.body.error).to.equal('No jma') | |
355 | }) | |
356 | }) | |
357 | ||
9b474844 | 358 | after(async function () { |
89cd1275 | 359 | await cleanupTests(servers) |
9b474844 C |
360 | }) |
361 | }) |